@@ -262,27 +262,35 @@ func (robo *Robot) InitTwitchUsers(ctx context.Context, owner *Privilege, global
262
262
return nil
263
263
}
264
264
265
+ func mergere (global , ch string ) (* regexp.Regexp , error ) {
266
+ var re string
267
+ switch {
268
+ case global != "" && ch != "" :
269
+ re = "(" + global + ")|(" + ch + ")"
270
+ case global != "" :
271
+ re = global
272
+ case ch != "" :
273
+ re = ch
274
+ default :
275
+ re = "$^"
276
+ }
277
+ return regexp .Compile (re )
278
+ }
279
+
265
280
// SetTwitchChannels initializes Twitch channel configuration.
266
281
// It must be called after SetTMI.
267
282
func (robo * Robot ) SetTwitchChannels (ctx context.Context , global Global , channels map [string ]* ChannelCfg ) error {
268
283
// TODO(zeph): we can convert this to a SetChannels, where it just adds the
269
284
// channels for any given service
270
285
for nm , ch := range channels {
271
- var re string
272
- switch {
273
- case global .Block != "" && ch .Block != "" :
274
- re = "(" + global .Block + ")|(" + ch .Block + ")"
275
- case global .Block != "" :
276
- re = global .Block
277
- case ch .Block != "" :
278
- re = ch .Block
279
- default :
280
- re = "$^"
281
- }
282
- blk , err := regexp .Compile (re )
286
+ blk , err := mergere (global .Block , ch .Block )
283
287
if err != nil {
284
288
return fmt .Errorf ("bad global or channel block expression for twitch.%s: %w" , nm , err )
285
289
}
290
+ meme , err := mergere (global .Meme , ch .Meme )
291
+ if err != nil {
292
+ return fmt .Errorf ("bad global or channel meme expression for twitch.%s: %w" , nm , err )
293
+ }
286
294
emotes := pick .New (pick .FromMap (mergemaps (global .Emotes , ch .Emotes )))
287
295
effects := pick .New (pick .FromMap (mergemaps (global .Effects , ch .Effects )))
288
296
ign , mod := make (map [string ]bool ), make (map [string ]bool )
@@ -308,6 +316,7 @@ func (robo *Robot) SetTwitchChannels(ctx context.Context, global Global, channel
308
316
Learn : ch .Learn ,
309
317
Send : ch .Send ,
310
318
Block : blk ,
319
+ Meme : meme ,
311
320
Responses : ch .Responses ,
312
321
Rate : rate .NewLimiter (rate .Every (fseconds (ch .Rate .Every )), ch .Rate .Num ),
313
322
Ignore : ign ,
@@ -493,6 +502,9 @@ type ChannelCfg struct {
493
502
Rate Rate `toml:"rate"`
494
503
// Copypasta is the configuration for copypasta.
495
504
Copypasta Copypasta `toml:"copypasta"`
505
+ // Meme is a regular expression of messages to allow to be copypasta even
506
+ // if matched by this channel's or the global Block.
507
+ Meme string `toml:"meme"`
496
508
// Emotes is the emotes and their weights for the channel.
497
509
Emotes map [string ]int `toml:"emotes"`
498
510
// Effects is the effects and their weights for the channel.
@@ -505,6 +517,9 @@ type ChannelCfg struct {
505
517
type Global struct {
506
518
// Block is a regular expression of messages to ignore everywhere.
507
519
Block string `toml:"block"`
520
+ // Meme is a regular expression of messages to allow to be copypasta even
521
+ // if matched by Block.
522
+ Meme string `toml:"meme"`
508
523
// Emotes is the emotes and their weights to use everywhere.
509
524
Emotes map [string ]int `toml:"emotes"`
510
525
// Effects is the effects and their weights to use everywhere.
0 commit comments