-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (42 loc) · 1 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
package main
import (
"fmt"
"github.com/turnage/graw"
"github.com/turnage/graw/reddit"
"log"
"os"
)
type subscriberBot struct {
bot reddit.Bot
}
func (s *subscriberBot) Mention(mention *reddit.Message) error {
fmt.Println("Detected a mention!")
return nil
}
func main() {
app := reddit.App{
ID: os.Getenv("REDDIT_BOT_ID"),
Secret: os.Getenv("REDDIT_BOT_SECRET"),
Username: os.Getenv("REDDIT_BOT_USERNAME"),
Password: os.Getenv("REDDIT_BOT_PASSWORD"),
}
agentString := os.Getenv("AGENT_STRING_PLATFORM") + ":" +
os.Getenv("AGENT_STRING_APP_ID") + ":" +
os.Getenv("AGENT_STRING_VERSION")
botConfig := reddit.BotConfig{
App: app,
Agent: agentString,
}
bot, err := reddit.NewBot(botConfig)
if err != nil {
log.Fatal(err)
return
}
cfg := graw.Config{Mentions: true}
handler := &subscriberBot{bot: bot}
if _, wait, err := graw.Run(handler, bot, cfg); err != nil {
fmt.Println("Failed to start graw run: ", err)
} else {
fmt.Println("graw run failed: ", wait())
}
}