-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
102 lines (81 loc) · 1.74 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"fmt"
"log"
"regexp"
"context"
"github.com/mattn/go-mastodon"
)
const regex = `<.*?>`
func main() {
Init()
c := mastodon.NewClient(&mastodon.Config{
Server: Server,
ClientID: C_key,
ClientSecret: C_secret,
})
err := c.Authenticate(context.Background(), User, Pass)
if err != nil {
log.Fatal(err)
}
/* Get Timeline
timeline, err := c.GetTimelineHome(context.Background(), nil)
if err != nil {
log.Fatal(err)
}
for i := len(timeline) - 1; i >= 0; i-- {
fmt.Println(timeline[i])
}
*/
notes, err := c.GetNotifications(context.Background(), nil)
if err != nil {
log.Fatal(err)
}
for _, msg := range notes {
fmt.Printf("Account: %s\nStatus: %s\n", msg.Account.URL, stripHtmlRegex(msg.Status.Content))
if stripHtmlRegex(msg.Status.Content) == BotName + " stop" && msg.Account.URL == Admin {
fmt.Println("Stopping")
//os.Exit(0)
}
}
/* Clear Notifications
err = c.ClearNotifications(context.Background())
if err != nil {
log.Fatal(err)
}
*/
ReadFile()
}
/*
// Post Status
_, err := c.PostStatus(context.Background(), &mastodon.Toot{
Status: msg,
//Visibility: "direct",
})
if err != nil {
log.Fatal(err)
}
*/
func stripHtmlRegex(s string) string {
r := regexp.MustCompile(regex)
return r.ReplaceAllString(s, "")
}
func Toot(msg string) {
c := mastodon.NewClient(&mastodon.Config{
Server: Server,
ClientID: C_key,
ClientSecret: C_secret,
})
err := c.Authenticate(context.Background(), User, Pass)
if err != nil {
log.Fatal(err)
}
// Post Status
_, errr := c.PostStatus(context.Background(), &mastodon.Toot{
Status: msg,
//Visibility: "direct",
})
if errr != nil {
log.Fatal(err)
}
}