forked from Omodi/GoToBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
botFunctions.py
234 lines (208 loc) · 7.41 KB
/
botFunctions.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import partyparrot.partyparrot as pp
import partyparrot.alphabet as al
import pony as p
import poll
import quote
import images
import catFacts
from gotobot import GoTo
# import wave
# import pyaudio
def colorCode(bot, msg):
print("color")
name = msg["text"][1 + msg["text"].find(" "):]
if(name == msg["text"]):
message = "invalid arguments"
bot.sendMessage(msg["channel"], message)
return
# tmp="#"
# for ch in name[:3]:
# tmp += hex(ord(ch))[2:]
if(name.lower() == "jon"):
h = "#39FF14"
elif(name.lower() == "verbose"):
h = "#b00bee"
else:
h = "#" + hex(abs(hash(name)))[2:8]
# print (h)
bot.sendMessage(msg["channel"], h)
def randominterns(bot, msg):
bot.sendMessage(msg["channel"], "Alex")
def randomIntern(bot, msg):
ranIntern = random.choice(bot.interns)
if ranIntern == "Steven G":
ranIntern = ":tubieg: :steveng: :partyg: :zoomieg:"
bot.sendMessage(msg["channel"], ranIntern)
def luna(bot, msg):
bot.sendMessage(msg["channel"], "luna shutdown")
def partyParrotMsg(bot, msg):
txt = msg['text'].lower()
txt = txt[12: len(txt)].strip()
txt = ''.join(ch for ch in txt if ch in al.ALPHABET)
print(txt)
print(pp.convert_str_to_emoji(txt))
bot.sendMessage(msg["channel"], pp.convert_str_to_emoji(txt, space=" "))
def send87(bot, msg):
bot.sendMessage(msg["channel"], "87")
def test(bot, msg):
testing = "blackboxwhitebox" * random.randrange(5, 20)
bot.sendMessage(msg["channel"], testing)
def pony(bot, msg):
bot.sendMessage(msg["channel"], "```" + p.Pony.getPony() + "```")
# def playGong(bot, msg):
# CHUNK = 1024
# wf = wave.open("gong.wav", "rb")
# p = pyaudio.PyAudio()
# stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
# channels=wf.getnchannels(),
# rate=wf.getframerate(),
# output=True)
# data = wf.readframes(CHUNK)
# while data != "":
# stream.write(data)
# data = wf.readframes(CHUNK)
# stream.stop_stream()
# stream.close()
# p.terminate()
def formatHelpMsg(cmd, msg):
justifyLength = 24
cmdLen = len(cmd)
msgLen = len(msg)
if cmdLen < justifyLength: # within formatting bounds
return cmd.ljust(justifyLength, ' ') + msg
if justifyLength < cmdLen: # overflow to next line for message
return cmd + '\n'.ljust(justifyLength + 1, ' ') + msg
"""
dictionary for routing function calls read from incoming messages over the slack rtm api
text - regex string matching for individual commands
callback - function called when text string is matched
help - string printed when help command is called,
show users which functions are enabled for use (blank they do not know it exists)
"""
router = [
{
"text": ["~colorname", "~color name"],
"callback":colorCode,
"type": "text",
"help": formatHelpMsg("`~colorname (string)`",
"- Returns hex color code derived from input")
}, {
"text": ["~randomintern"],
"callback":randomIntern,
"type": "text",
"help": formatHelpMsg("`~randomintern`",
"- select a random intern to give a task to")
}, {
"text": ["~help"],
"callback":GoTo.help,
"type": "text",
"help": formatHelpMsg("`~help`", "- display this message")
}, {
"text": ["~catfacts", "~cat facts"],
"callback":catFacts.catFacts,
"type": "text",
"help": formatHelpMsg("`~catfacts`", "- Returns a random catfact")
}, {
"text": ["~quote"],
"callback":quote,
"type": "text",
"help": ""
}, {
"text": ["~startpoll", "~poll", "~createpoll", "~start poll", "~poll", "~create poll"],
"callback":poll.startPoll,
"type": "text",
"help": formatHelpMsg("`~startpoll,(nameOfPoll),(option1),(option2),...(optionX)`",
"- Creates a poll that can be voted on, closed or have an option added to the poll")
}, {
"text": ["~stoppoll", "~removepoll", "~stop poll", "~remove poll"],
"callback":poll.stopPoll,
"type": "text",
"help": formatHelpMsg("`~stoppoll,(pollName)`", "- Ends the poll and displays results")
}, {
"text": ["~vote", "~votepoll", "~vote poll"],
"callback":poll.vote,
"type": "text",
"help": formatHelpMsg("`~vote,(pollName),(option)`",
"- Votes for (option). If you have aready voted it removes your old vote")
}, {
"text": ["~addoption"],
"callback":poll.addOption,
"type": "text",
"help": formatHelpMsg("`~addoption,(pollName),(newOption)`",
"- Creates a new option for a poll")
}, {
"text": ["ship it", ":shipit:", "shipit"],
"callback":images.shipIt,
"type": "text",
"help": formatHelpMsg("`ship it`", "- Returns ship it squirrel image")
}, {
"text": ["~deleteall"],
"callback":GoTo.deleteAll,
"type": "text",
"help": formatHelpMsg("`~deleteall`",
"- Deletes all messages from bot in whitelisted channels, and reacts when done.")
}, {
"text": ["~nye"],
"callback":images.nye,
"type": "text",
"help": formatHelpMsg("`~nye`", "- Returns a bill nye gif")
}, {
"text": ["~meme"],
"callback":images.getMeme,
"type": "text",
"help": formatHelpMsg("`~meme,(keyword)`",
"- Gets a meme for given keyword. Returns 'nope.jpg' if no meme found")
}, {
"text": ["~gif"],
"callback":images.getGiphy,
"type": "text",
"help": formatHelpMsg("`~gif,(keyword)`", "- Returns a gif with the given keyword")
}, {
"text": ["~insanity"],
"callback":images.getMeme,
"type": "text",
"help": formatHelpMsg("`~insanity`", "- Returns an insanity wolf meme")
}, {
"text": ["~dm"],
"callback":GoTo.sendDM,
"type": "text",
"help": ""
}, {
"text": ["~random intern", "~ randomintern"],
"callback": randominterns,
"type": "text",
"help": ""
}, {
"text": ["~partyparrot"],
"callback": partyParrotMsg,
"type": "text",
"help": formatHelpMsg("`~partyparrot (string)`", "- Converts text to party parrots")
}, {
"text": ["~send87"],
"callback": send87,
"type": "text",
"help": formatHelpMsg("`~send87`", "- Test function that sends 87")
}
# , {
# "text": ["zach", "zachisan", "<3", ":heart:",":heart_decoration:", "zack",
# ":heart_eyes:",":heartbeat:",":heartpulse:",":hearts:"],
# "callback": playGong,
# "type": "text",
# "help": ""
# }, {
# "text": ["~delete"],
# "callback":GoTo.delete,
# "type": "text",
# "help": "`~delete` - Deletes the last message sent by bot in the specified channel."
# }, {
# "text": ["test"],
# "callback":test,
# "type": "text",
# "help": "`test` `testing` - any appearance of the string `test` there will be a response posted"
# }, {
# "text": ["~pony"],
# "callback": pony,
# "type": "text",
# "help": "sends ascii art"
# }
]