|
1 | | - |
| 1 | +import re |
| 2 | +import time |
2 | 3 | from cloudbot import hook |
3 | 4 | from cloudbot.event import EventType |
4 | 5 | from plugins import grab |
5 | 6 |
|
6 | 7 | import random |
7 | 8 |
|
8 | 9 | db_ready = [] |
9 | | - |
| 10 | +opt_out = [] |
| 11 | +delay = 10 |
| 12 | +floodcheck = {} |
10 | 13 |
|
11 | 14 | def db_init(db, conn_name): |
12 | 15 | """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): |
66 | 69 | # freenode uncomment then next line |
67 | 70 | # chan = event.irc_raw.split('JOIN ')[1].lower() |
68 | 71 | # 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 | + |
69 | 77 | try: |
70 | 78 | chan = event.irc_raw.split(':')[2].lower() |
71 | 79 | except: |
72 | 80 | 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 | + |
73 | 90 | welcome = db.execute("select quote from herald where name = :name and chan = :chan", { |
74 | 91 | 'name': nick.lower(), 'chan': chan.lower()}).fetchone() |
75 | 92 | if welcome: |
76 | 93 | greet = welcome[0] |
| 94 | + greet = re.sub(bino_re, 'flenny', greet) |
| 95 | + greet = re.sub(offensive_re, ' freespeech oppression ', greet) |
77 | 96 | if greet.lower().split(' ')[0] == ".grabrandom": |
78 | 97 | text = "" |
79 | 98 | if len(greet.split(' ')) >= 2: |
80 | 99 | candidates = greet.lower().split(' ')[1:] |
81 | 100 | text = random.choice(candidates) |
82 | 101 | out = grab.grabrandom(text, chan, message) |
83 | 102 | 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) |
84 | 105 | else: |
85 | | - message(welcome[0], chan) |
86 | | - |
| 106 | + message("\u200b {}".format(greet), chan) |
| 107 | + floodcheck[chan] = time.time() |
87 | 108 | # Saying something whenever someone joins can get really spammy |
88 | 109 | # else: |
89 | 110 | # action("welcomes {} to {}".format(nick, chan), chan) |
0 commit comments