This repository has been archived by the owner on May 12, 2020. It is now read-only.
/
choose.py
119 lines (89 loc) · 3.39 KB
/
choose.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import lampstand.reactions.base
from lampstand.tools import splitAt
import re
import time
import random
import sys
import logging
def __init__():
pass
class Reaction(lampstand.reactions.base.Reaction):
__name = 'Choose'
cooldown_number = 6
cooldown_time = 360
uses = []
def __init__(self, connection):
self.logger = logging.getLogger(self.__name)
self.channelMatch = re.compile(
'^%s. (choose|should I) (.* or .*)' %
connection.nickname,
re.IGNORECASE)
self.privateMatch = re.compile(
'(choose|should I) (.* or .*)\??$',
re.IGNORECASE)
def channelAction(self, connection, user, channel, message):
self.logger.info("[Choose] called")
if self.overUsed(self.uses, self.cooldown_number, self.cooldown_time):
connection.message(
channel,
"I'm not running your life for you, go away.")
return True
self.updateOveruse()
match = self.channelMatch.findall(message)
if random.randint(0, 100) == 69:
self.logger.info("Yes")
connection.message(channel, "%s: Yes" % user)
return True
if random.randint(0, 100) == 67:
self.logger.info("Edge")
connection.message(channel, "%s: edge" % user)
return True
self.logger.info(match)
reaction = self.choose(match[0][1])
if reaction.lower() == "death" and user.lower() != "aquarion":
connection.kick(channel, user, "Death.")
elif reaction.lower() == "boom" and user.lower():
connection.kick(channel, user, "BOOM")
else:
connection.message(channel, "%s: %s" % (user, reaction))
return True
def privateAction(self, connection, user, channel, message):
self.logger.info("[Choose] called")
if self.overUsed(self.uses, self.cooldown_number, self.cooldown_time):
connection.message(
user,
"I'm not running your life for you, go away.")
return
self.updateOveruse()
match = self.privateMatch.findall(message)
self.logger.info("Match: %s" % match)
reaction = self.choose(match[0][1])
connection.message(user, "%s: %s" % (user, reaction))
def choose(self, message):
if message[-1:] == "?":
message = message[:-1]
self.logger.info(message)
# new regex by ccooke - 2010-05-28
#regex = re.compile("(?:\s*(?:\s*(?:,|x?or)\s*)+\s*)+", re.IGNORECASE);
#regex = re.compile("(?:\s+(?:\s*(?:x?or)\s*)+\s*|,)+", re.IGNORECASE);
regex = re.compile(
"(?:\s+(?:\s*(?:x?or(?=\W))\s*)+\s*|,)+\s*",
re.IGNORECASE)
choose = regex.split(message)
#choose = []
#orsplit = message.split(" or ")
# for thing in orsplit:
# lst = thing.split(", ")
# for x in lst:
# choose.append(x)
# self.logger.info(choose)
self.logger.info(choose)
for thing in choose:
if thing.lower() == "glados":
self.logger.info("Chosen Glados")
return "GLaDOS. Obviously"
if thing.lower() == "hal":
self.logger.info("Removed a Hal")
choose.remove(thing)
self.logger.info(choose)
return random.choice(choose)