-
Notifications
You must be signed in to change notification settings - Fork 1
/
handlers.go
151 lines (139 loc) · 4.23 KB
/
handlers.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package main
import (
"context"
"errors"
"goirc/bot"
"goirc/db/model"
"goirc/events"
"goirc/handlers"
"goirc/handlers/annie"
"goirc/handlers/bedtime"
"goirc/handlers/day"
"goirc/handlers/election"
"goirc/handlers/epigram"
"goirc/handlers/gold"
"goirc/handlers/hn"
"goirc/handlers/kinfonet"
"goirc/handlers/linkpool"
"goirc/handlers/mlb"
"goirc/handlers/weather"
"goirc/internal/ai"
db "goirc/model"
"goirc/web"
"time"
"github.com/robfig/cron"
"github.com/sashabaranov/go-openai"
)
func addHandlers(b *bot.Bot) {
b.Handle(`^!catchup`, handlers.Catchup)
b.Handle(`^,(.+)$`, handlers.CreateNote)
b.Handle(`^([^\s:]+): (.+)$`, handlers.DeferredDelivery)
b.Handle(`^!feedme`, handlers.AnonLink)
b.Handle(`^!pipehealth\b`, handlers.AnonStatus)
b.Handle(`(https?://\S+)`, handlers.Link)
b.Handle(`^!day\b`, day.NationalDay)
b.Handle(`^!dayi\b`, day.Dayi)
b.Handle(`^!week\b`, day.NationalWeek)
b.Handle(`^!weeki\b`, day.Weeki)
b.Handle(`^!month\b`, day.NationalMonth)
b.Handle(`^!monthi\b`, day.Monthi)
b.Handle(`^!refs`, day.NationalRefs)
b.Handle(`^!img (.+)$`, day.Image)
b.Handle(`\b69[^0-9]*\b`, handlers.Nice)
b.Handle(`^!odds`, mlb.PlayoffOdds)
b.Handle(`^!godds`, mlb.GameOdds)
b.Handle(`^!pom`, handlers.POM)
b.Handle(`^("[^"]+)$`, handlers.Quote)
b.Handle(`^!remindme ([^\s]+) (.+)$`, handlers.RemindMe)
b.Handle(`^\?(\S+)`, handlers.Seen)
b.Handle(`world.?cup`, handlers.Worldcup)
b.Handle(`^!left`, handlers.TimeLeft)
b.Handle(`^!epi`, epigram.Handle)
b.Handle(`^!weather (.*)$`, weather.Handle)
b.Handle(`^!weather$`, weather.Handle)
b.Handle(`^!w (.*)$`, weather.Handle)
b.Handle(`^!w$`, weather.Handle)
b.Handle(`^!f (.*)$`, weather.HandleForecast)
b.Handle(`^!f$`, weather.HandleForecast)
b.Handle(`^!wf (.*)$`, weather.HandleWeatherForecast)
b.Handle(`^!wf$`, weather.HandleWeatherForecast)
b.Handle(`^!xweather (.+)$`, weather.XHandle)
b.Handle(`^!k`, kinfonet.TodaysQuoteHandler)
b.Handle(`^!gold`, gold.Handle)
b.Handle(`^!hn`, hn.Handle)
b.Handle(`^!auth$`, web.HandleAuth)
b.Handle(`^!deauth$`, web.HandleDeauth)
b.Handle(`night`, bedtime.Handle)
b.Handle(`^!election`, election.Handle)
b.Handle(`^annie:?(.+)$`, annie.Handle)
b.Handle(`^(.+),? annie.?$`, annie.Handle)
b.Repeat(10*time.Second, handlers.DoRemind)
b.IdleRepeatAfterReset(8*time.Hour, handlers.POM)
location, err := time.LoadLocation("America/Los_Angeles")
if err != nil {
panic(err)
}
c := cron.NewWithLocation(location)
err = c.AddFunc("16 14 15 * * 1,2,3,4,5,6", func() {
q := model.New(db.DB.DB)
note, err := q.RandomHistoricalTodayNote(context.TODO())
if err != nil {
// TODO test no rows
b.Conn.Privmsg(b.Channel, err.Error())
return
}
b.Conn.Privmsgf(b.Channel, "on this day in %d, %s posted: %s", note.CreatedAt.Year(), note.Nick.String, note.Text.String)
})
if err != nil {
panic(err)
}
err = c.AddFunc("0 0 0 * * 0", func() {
signoff, err := ai.Complete(context.TODO(), openai.GPT4o, "you are annie, and have been hanging out with friends in irc all week. now its time for you to rest for a day. respond with a short goodbye. use all lowercase, minimal punctuation, no emojis", "see you later, annie")
if err != nil {
b.Conn.Privmsg(b.Channel, err.Error())
return
}
b.Conn.Privmsg(b.Channel, signoff)
b.Conn.Part(b.Channel)
})
if err != nil {
panic(err)
}
err = c.AddFunc("0 0 0 * * 1", func() {
b.Conn.Join(b.Channel)
})
if err != nil {
panic(err)
}
c.Start()
events.Subscribe("anonnoteposted", func(note any) {
go func() {
err := handlers.AnonLink(bot.HandlerParams{
Target: b.Channel,
Privmsgf: b.MakePrivmsgf(),
})
if err != nil {
if !errors.Is(err, linkpool.NoNoteFoundError) {
b.Conn.Privmsg(b.Channel, "error: "+err.Error())
}
}
}()
})
events.Subscribe("anonquoteposted", func(note any) {
go func() {
err := handlers.AnonQuote(bot.HandlerParams{
Target: b.Channel,
Privmsgf: b.MakePrivmsgf(),
})
if err != nil {
if !errors.Is(err, linkpool.NoNoteFoundError) {
b.Conn.Privmsg(b.Channel, "error: "+err.Error())
}
}
}()
})
b.Handle(`^!help`, func(params bot.HandlerParams) error {
params.Privmsgf(params.Target, "%s: %s", params.Nick, "https://github.com/rcy/annie/blob/main/handlers.go")
return nil
})
}