-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrazy.py
62 lines (53 loc) · 1.96 KB
/
crazy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import re
import lurklib
class Crazy:
def __init__(self, irc):
self.irc = irc
self.max_lvl = 11
self.min_lvl = -self.max_lvl
def usage(self, chan, from_):
self.irc.privmsg(chan, from_[
0] + ": the crazyness level must be an int from %d to %d" % (self.min_lvl, self.max_lvl))
def on_chanmsg(self, from_, chan, msg):
parts = msg.split()
if len(parts) != 2:
self.usage(chan, from_)
return
level_str = parts[1]
topic = self.irc.topic(chan)[0]
topic = self.irc.topic(chan)[0]
#topic = self.irc.topic(chan)[0]
try:
current_level = len(re.findall("\[(=*)-*\]", topic)[0])
except IndexError:
current_level = 0
not_found = True
if level_str == "++":
if current_level < self.max_lvl:
level = current_level + 1
else:
level = current_level
elif level_str == "--":
if current_level > self.min_lvl:
level = current_level - 1
else:
level = current_level
else:
try:
level = int(level_str)
if level < self.min_lvl or level > self.max_lvl:
self.usage(chan, from_)
return
except ValueError:
self.usage(chan, from_)
return
the_char = "=" if level > 0 else "_"
level = abs(level)
crazy_str = "[" + the_char * level + "-" * (self.max_lvl - level) + "]"
new_topic = re.sub("(\[[=_]+-+\]|\[[=_]+\]|\[-+\])", crazy_str, topic)
#self.irc.privmsg(chan, "New topic would be " + new_topic)
try:
self.irc.topic(chan, new_topic)
except lurklib.exceptions._Exceptions.ChanOPrivsNeeded as e:
self.irc.privmsg(
chan, "I require OP, OP, OP -> /mode #dorsal-fun +o DorsalFunBot")