mirror of
https://github.com/idanoo/go-mastodon-stats
synced 2025-07-02 22:32:19 +00:00
Use as client
This commit is contained in:
parent
5c1da4a904
commit
97caf4bc37
1 changed files with 6 additions and 28 deletions
|
@ -8,41 +8,19 @@ import (
|
|||
"github.com/mattn/go-mastodon"
|
||||
)
|
||||
|
||||
func registerApp() (string, string, error) {
|
||||
app, err := mastodon.RegisterApp(context.Background(), &mastodon.AppConfig{
|
||||
Server: fmt.Sprintf("https://%s", MASTODON_INSTANCE_URL),
|
||||
ClientName: MASTODON_CLIENT_NAME,
|
||||
Scopes: "read write follow",
|
||||
Website: "https://github.com/mattn/go-mastodon",
|
||||
})
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
fmt.Printf("client-id : %s\n", app.ClientID)
|
||||
fmt.Printf("client-secret: %s\n", app.ClientSecret)
|
||||
|
||||
return app.ClientID, app.ClientSecret, nil
|
||||
}
|
||||
|
||||
func postToMastodon(metrics []metric) {
|
||||
if MASTODON_INSTANCE_URL == "" {
|
||||
log.Printf("Skipping posting to mastodon. Missing configuration")
|
||||
return
|
||||
}
|
||||
|
||||
clientId, clientSecret, err := registerApp()
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return
|
||||
}
|
||||
|
||||
c := mastodon.NewClient(&mastodon.Config{
|
||||
Server: fmt.Sprintf("https://%s", MASTODON_INSTANCE_URL),
|
||||
ClientID: clientId,
|
||||
ClientSecret: clientSecret,
|
||||
ClientID: MASTODON_CLIENT_NAME,
|
||||
ClientSecret: "random-secret-that-doesnt-really-matter-lol",
|
||||
})
|
||||
err = c.Authenticate(context.Background(), MASTODON_USERNAME, MASTODON_PASSWORD)
|
||||
|
||||
err := c.Authenticate(context.Background(), MASTODON_USERNAME, MASTODON_PASSWORD)
|
||||
if err != nil {
|
||||
log.Println("Invalid mastodon credentials?")
|
||||
log.Print(err)
|
||||
|
@ -57,11 +35,11 @@ func postToMastodon(metrics []metric) {
|
|||
}
|
||||
msg = msg + "\n\n" + "#Stats"
|
||||
|
||||
toot := mastodon.Toot{
|
||||
toot := &mastodon.Toot{
|
||||
Status: msg,
|
||||
}
|
||||
|
||||
_, err = c.PostStatus(context.Background(), &toot)
|
||||
_, err = c.PostStatus(context.Background(), toot)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue