Skip to content

Commit 3a98521

Browse files
committed
make sure heralds don't spam after a netsplit.
1 parent 63052bb commit 3a98521

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

plugins/herald.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
1+
import re
2+
import time
23
from cloudbot import hook
34
from cloudbot.event import EventType
45
from plugins import grab
56

67
import random
78

89
db_ready = []
9-
10+
opt_out = []
11+
delay = 10
12+
floodcheck = {}
1013

1114
def db_init(db, conn_name):
1215
"""Check to see if the DB has the herald table. Connection name is for caching the result per connection.
@@ -66,24 +69,42 @@ def welcome(nick, action, message, chan, event, db, conn):
6669
# freenode uncomment then next line
6770
# chan = event.irc_raw.split('JOIN ')[1].lower()
6871
# snoonet
72+
decoy = re.compile('[o○O0öøóóȯôőŏᴏōο](<|>|<)')
73+
colors_re = re.compile("\x02|\x03(?:\d{1,2}(?:,\d{1,2})?)?", re.UNICODE)
74+
bino_re = re.compile('b+i+n+o+', re.IGNORECASE)
75+
offensive_re = re.compile('卐')
76+
6977
try:
7078
chan = event.irc_raw.split(':')[2].lower()
7179
except:
7280
return
81+
if chan in opt_out:
82+
return
83+
84+
if chan in floodcheck:
85+
if time.time() - floodcheck[chan] <= delay:
86+
return
87+
else:
88+
floodcheck[chan] = time.time()
89+
7390
welcome = db.execute("select quote from herald where name = :name and chan = :chan", {
7491
'name': nick.lower(), 'chan': chan.lower()}).fetchone()
7592
if welcome:
7693
greet = welcome[0]
94+
greet = re.sub(bino_re, 'flenny', greet)
95+
greet = re.sub(offensive_re, ' freespeech oppression ', greet)
7796
if greet.lower().split(' ')[0] == ".grabrandom":
7897
text = ""
7998
if len(greet.split(' ')) >= 2:
8099
candidates = greet.lower().split(' ')[1:]
81100
text = random.choice(candidates)
82101
out = grab.grabrandom(text, chan, message)
83102
message(out, chan)
103+
elif decoy.search(colors_re.sub("", greet.replace('\u200b', '').replace(' ', '').replace('\u202f','').replace('\x02', ''))):
104+
message("DECOY DUCK --> {}".format(greet), chan)
84105
else:
85-
message(welcome[0], chan)
86-
106+
message("\u200b {}".format(greet), chan)
107+
floodcheck[chan] = time.time()
87108
# Saying something whenever someone joins can get really spammy
88109
# else:
89110
# action("welcomes {} to {}".format(nick, chan), chan)

0 commit comments

Comments
 (0)