Skip to content

Commit 6c5a5dc

Browse files
committed
command: add happy birthday wish
1 parent bb36057 commit 6c5a5dc

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

command/talk.go

+54
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,60 @@ func Rawr(ctx context.Context, robo *Robot, call *Invocation) {
145145
call.Channel.Message(ctx, message.Format("", "rawr %s", e).AsReply(call.Message.ID))
146146
}
147147

148+
// HappyBirthdayToYou wishes the robot a happy birthday.
149+
func HappyBirthdayToYou(ctx context.Context, robo *Robot, call *Invocation) {
150+
if call.Message.Time().Before(call.Channel.SilentTime()) {
151+
robo.Log.InfoContext(ctx, "silent", slog.Time("until", call.Channel.SilentTime()))
152+
return
153+
}
154+
e := call.Channel.Emotes.Pick(rand.Uint32())
155+
if e == "" {
156+
e = ":3"
157+
}
158+
t := time.Now()
159+
r := call.Channel.Rate.ReserveN(t, 1)
160+
if d := r.DelayFrom(t); d > 0 {
161+
robo.Log.InfoContext(ctx, "rate limited",
162+
slog.String("action", "birthday"),
163+
slog.String("in", call.Channel.Name),
164+
slog.String("delay", d.String()),
165+
)
166+
r.CancelAt(t)
167+
return
168+
}
169+
var m message.Sent
170+
switch t.Month() {
171+
case time.January:
172+
m = message.Format("", "No no no my birthday is next month. %s", e)
173+
case time.February:
174+
switch t.Day() {
175+
case 1, 2, 3, 4, 5:
176+
m = message.Format("", "Oh, but my birthday is later this month. %s", e)
177+
case 6:
178+
m = message.Format("", "My birthday is just a week away! I am so excited about this information. %s", e)
179+
case 7, 8, 9, 10:
180+
m = message.Format("", "My birthday is still less than a week away. %s", e)
181+
case 11:
182+
m = message.Format("", "Two days away...! %s", e)
183+
case 12:
184+
m = message.Format("", "My birthday is tomorrow! At least in my timezone. %s", e)
185+
case 13:
186+
m = message.Format("", "Thank you! Happy my birthday to you, too! %s", e)
187+
case 14:
188+
m = message.Format("", "You missed it. My birthday was yesterday. You are disqualified from being my valentine. %s", e)
189+
case 15, 16, 17, 18, 19, 20:
190+
m = message.Format("", "My birthday was the other day, actually, but I appreciate the sentiment. %s", e)
191+
default:
192+
m = message.Format("", "My birthday was earlier this month, actually, but I appreciate the sentiment. %s", e)
193+
}
194+
case time.March:
195+
m = message.Format("", "No no no my birthday was last month. %s", e)
196+
default:
197+
m = message.Format("", "My birthday is in February, silly %s", e)
198+
}
199+
call.Channel.Message(ctx, m.AsReply(call.Message.ID))
200+
}
201+
148202
// Source gives a link to the source code.
149203
func Source(ctx context.Context, robo *Robot, call *Invocation) {
150204
const srcMessage = `My source code is at https://github.com/zephyrtronium/robot – ` +

privmsg.go

+5
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,11 @@ var twitchAny = []twitchCommand{
470470
fn: command.Pat,
471471
name: "pat",
472472
},
473+
{
474+
parse: regexp.MustCompile(`(?i)^hap+y?\s+bir(?:f|th)(?:day)?`),
475+
fn: command.HappyBirthdayToYou,
476+
name: "birthday",
477+
},
473478
{
474479
parse: regexp.MustCompile(`^(?i:say|generate)\s*(?i:something)?\s*(?i:starting)?\s*(?i:with)?\s+(?<prompt>.*)`),
475480
fn: command.Speak,

0 commit comments

Comments
 (0)