@@ -145,6 +145,60 @@ func Rawr(ctx context.Context, robo *Robot, call *Invocation) {
145
145
call .Channel .Message (ctx , message .Format ("" , "rawr %s" , e ).AsReply (call .Message .ID ))
146
146
}
147
147
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
+
148
202
// Source gives a link to the source code.
149
203
func Source (ctx context.Context , robo * Robot , call * Invocation ) {
150
204
const srcMessage = `My source code is at https://github.com/zephyrtronium/robot – ` +
0 commit comments