Mastodon support
This commit is contained in:
29
mastodon/mastodon.go
Normal file
29
mastodon/mastodon.go
Normal file
@ -0,0 +1,29 @@
|
||||
package mastodon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"github.com/mattn/go-mastodon"
|
||||
)
|
||||
|
||||
type Mastodon struct {
|
||||
client *mastodon.Client
|
||||
}
|
||||
|
||||
func NewMastodon(server string, clientID string, clientSecret string, username string, password string) *Mastodon {
|
||||
m := &Mastodon{}
|
||||
|
||||
m.client = mastodon.NewClient(&mastodon.Config{
|
||||
Server: server,
|
||||
ClientID: clientID,
|
||||
ClientSecret: clientSecret,
|
||||
})
|
||||
err := m.client.Authenticate(context.Background(), username, password)
|
||||
if err != nil {
|
||||
log.Print("Failed to configure Mastodon: ", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
14
mastodon/toot.go
Normal file
14
mastodon/toot.go
Normal file
@ -0,0 +1,14 @@
|
||||
package mastodon
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mattn/go-mastodon"
|
||||
)
|
||||
|
||||
func (m *Mastodon) Toot(message string) error {
|
||||
_, err := m.client.PostStatus(context.Background(), &mastodon.Toot{
|
||||
Status: message,
|
||||
})
|
||||
return err
|
||||
}
|
Reference in New Issue
Block a user