1
0
Fork 0

Just use AccessToken to connect to Mastodon after correctly getting it
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Daniele Tricoli 2022-03-01 01:41:32 +01:00
parent bc9b090023
commit bda25e2c20
1 changed files with 4 additions and 15 deletions

View File

@ -1,7 +1,3 @@
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
@ -19,8 +15,6 @@ const (
DEBUG = "DEBUG"
TELEGRAM_BOT_TOKEN = "TELEGRAM_BOT_TOKEN"
MASTODON_SERVER_ADDRESS = "MASTODON_SERVER_ADDRESS"
MASTODON_CLIENT_ID = "MASTODON_CLIENT_ID"
MASTODON_SECRET = "MASTODON_SECRET"
MASTODON_ACCESS_TOKEN = "MASTODON_ACCESS_TOKEN"
)
@ -36,16 +30,10 @@ the specified Mastodon account.`,
mastodon_instance := os.Getenv(MASTODON_SERVER_ADDRESS)
c := mastodon.NewClient(&mastodon.Config{
Server: mastodon_instance,
ClientID: os.Getenv(MASTODON_CLIENT_ID),
ClientSecret: os.Getenv(MASTODON_SECRET),
AccessToken: os.Getenv(MASTODON_ACCESS_TOKEN),
})
log.Println("Crating a new client for mastondon istance:", mastodon_instance)
err := c.AuthenticateToken(context.Background(), os.Getenv(MASTODON_ACCESS_TOKEN), os.Getenv(MASTODON_REDIRECT_URI))
if err != nil {
log.Fatal(err)
}
bot, err := tgbotapi.NewBotAPI(os.Getenv(TELEGRAM_BOT_TOKEN))
if err != nil {
log.Panic(err)
@ -65,6 +53,7 @@ the specified Mastodon account.`,
status, err := c.PostStatus(context.Background(), &mastodon.Toot{
Status: update.Message.Text,
// TODO: make users able to set visibility
Visibility: "unlisted",
})