/
main.py
330 lines (268 loc) · 19.7 KB
/
main.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# -*- coding: utf-8 -*-
## V 3.0
"""
ChangeLog
- V3.0 -
Rewrote main.py to work with the new chatbot.py
Cleaned the code
"""
## Description
"""
A chatbot mainly for the ChemistryStackExchange chatroom
"""
# Imports and initialization
from chatbot import Chatbot, log # chatbot.py, the chatbot framework
import random # chose a random element from a table
import upsidedown # flips strings - non PIP library
import shutil # file manipulation (creating images from bytes)
from PIL import Image # check if images are valid / images format conversion
from imgurpython import ImgurClient # upload images to imgur
import time # sleeping
client_id = 'fb1b922cb86bb0f' # Imgur module setup
client_secret = 'cffaf5da440289a8923f9be60c22b26e25675d3d'
clientImg = ImgurClient(client_id, client_secret)
## Initialization
# Create chatbot
chatbot=Chatbot()
# Login to SE
chatbot.login()
# useful vars
coolTables = {
"tablesList": ["(╯°□°)╯︵ ┻━┻", "(ノಠ益ಠ)ノ彡┻━┻", "ʕノ•ᴥ•ʔノ ︵ ┻━┻", "(/¯◡ ‿ ◡)/¯ ~ ┻━┻", "(ノ-_-)ノ ~┻━┻", "(ノ;;)ノ~┻━┻",
"(ノ-_-)ノ ~┻━┻ ☆`", "(ノ-_-)ノ・・・~~┻━┻", "(ノ-_-)ノ~┻━┻", "ノ ̄□ ̄)ノ ~┻━┻", "(ノꐦ ⊙曲ఠ)ノ彡┻━┻", "(ノ`□´)ノ⌒┻━┻",
"(ノꐦ ๑´Д`๑)ノ彡┻━┻", "┻━┻ミ\(≧ロ≦\)", "(ノ ̄□ ̄)ノ ~┻━┻", "(ノ♯`△´)ノ~’┻━┻", "(ノT_T)ノ ^┻━┻", "(┛ಠДಠ)┛彡┻━┻",
"(ノ°▽°)ノ︵┻━┻", "(ノ*’ω’*)ノ彡┻━┻", "(ノಥ益ಥ)ノ ┻━┻", "(╯’□’)╯︵ ┻━┻", "(ノಥДಥ)ノ︵┻━┻・/", "(._.) ~ ︵ ┻━┻",
"┗[© ♒ ©]┛ ︵ ┻━┻", "┻━┻ ︵ ლ(⌒-⌒ლ)", "(ノ^◡^)ノ︵ ┻━┻", "༼ ᕤ ºل͟º ༽ᕤ ︵┻━┻", "ヽ༼ ツ ༽ノ ︵┻━┻",
"༼ ͠ຈ ͟ل͜ ͠ຈ༽ง︵┻━┻", "ヽ༼ຈل͜ຈ༽ノ︵┻━┻", "(╯ຈل͜ຈ) ╯︵ ┻━┻", "༼ノಠل͟ಠ༽ノ ︵ ┻━┻", "༼ノຈل͜ຈ༽ノ︵┻━┻",
"(╯ ͝° ͜ʖ͡°)╯︵ ┻━┻", "(つ☢益☢)つ︵┻━┻", "ヽ༼ຈل͜ຈ༽ノ︵ ┻━┻", "(┛◉Д◉)┛彡┻━┻", "(ノ≧∇≦)ノ ミ ┸━┸", "┻━┻ミ\(≧ロ≦\)",
"(ノ`´)ノ ~┻━┻ ~", "ʕ ⊃・ ◡ ・ ʔ⊃︵┻━┻", "(ノ▼д▼)ノ ~┻━┻ ☆`", "(┛❍ᴥ❍)┛彡┻━┻", "(ʘ∇ʘ)ク 彡 ┻━┻",
"┻━┻ ︵ ლ(ಠ益ಠლ)", "(╯ಠ_ರೃ)╯︵ ┻━┻", "/(ò.ó)┛彡┻━┻", "(╯=▃=)╯︵┻━┻", "(ノ`ー´)ノ・・・~~┻━┻", "(ノ`◇´)ノ~┻━┻",
"┻━┻ ヘ╰( •̀ε•́ ╰)", "(ノ`Д´)ノ~┻━┻", "(ノ`△´)ノ~┻━┻", "(⑅ノ-_-)ノ~┻━┻ ", "(╯ ・ ᗜ ・ )╯︵ ┻━┻ ",
"(ノ ゚Д゚)ノ ==== ┻━━┻", "!!!!|┛*`Д´|┛・・~~┻━┻ ┳━┳", "(/#-_-)/~┻┻〃", "(/ToT)/ ~┻┻", "(ノ-_-)ノ・・・~┻┻ ",
"(ノ*’‐’)ノ ミ ┸┸", "(ノ#-_-)ノ ミ ┴┴", "(ノ`_´)ノ~~┴┴", "(ノ`´)ノミ┻┻", "ノToT)ノ ~┻┻", "(ノ`Д)ノ:・’∵:.┻┻",
"(ノToT)ノ ミ ┸┸", "(メ–)ノノ。。。┻┻", "(ノ≧∇≦)ノ ミ ┸┸", "(ノToT)ノ ~┻┻", "┳┳ヾ(T(エ)Tヽ)",
"(ノTwT)ノ ┫:・’.::・┻┻:・’.::・", "(ノ͡° ͜ʖ ͡°)ノ︵┻┻ ", "(ノ-_-)ノ・・・~~~┻┻", "(ノ;o;)ノ ┫:・’.::・┻┻:・’.::・",
"(ノ;ω;)ノ ┫:・’.::・┻┻:・’.::・", "(ノToT)ノ ┫:・’.::・┻┻:・’.::・", "(ノTДT)ノ ┫:・’.::・┻┻:・’.::・",
"(ノToT)ノ ┫:・’.::・┻┻:・’.::・", "(ノ`Д´)ノ-----┻┻ -3-3", "(ノ ̄^ ̄)ノ ┳┳ ┣ ┻┻ ┫ ┳┳",
"(ノ´□`)ノ ┫:・’∵:.┻┻:・’.:┣∵・:. ┳┳", "(ノ`0)ノ ⌒┫:・’.::・┻┻:・’.::・", "(ノ`⌒´)ノ ┫:・’.::・┻┻:・’.::・",
"(ノ`⌒´)ノ ┫:・’.::・┻┻:・’.::・", "( `o)ノノ ┫", "( ノo|o)ノ ┫。゚:.:", "(;--)ノノ ┫:・゜’", "(/-o-)/ ⌒ ┤",
"(/`ο´)/ ⌒ ┫:’゚:。・,. 。゜", "(/ToT)/_┫・..", "(ノ-_-)ノ ┫〝〟∵", "(ノ-0-)ノ ┫∵:.", "(ノ-o-)ノ ~┫:・’.::・",
"(ノ-o-)ノ⌒┳ ┫┻┣", "(ノ ̄_ ̄)ノ ┫〝〟∵", "(丿>ロ<)丿 ┤∵:.", "(ノ ̄ー ̄)ノ ┫:・’.::", "(ノ ̄ー ̄)ノ ┫〝〟∵",
"(ノ=゚ロ゚)ノ ⌒┫:・’.::", "(ノ>o<)ノ ┫:・’.::", "(ノ≧∇≦)ノ ┫ ゜・∵。", "(ノ≧ο≦)ノ ┫ ゜・∵。", "(ノ○Д○)ノ===┠",
"(ノー”ー)ノ ┫ ゜・∵。", "(ノToT)ノ ┫:・’.::・", "((((ノ`皿´)ノ ⌒┫:・┫┻┠’.", "(ノ*`▽´*)ノ ⌒┫ ┻ ┣ ┳", "(ノ ̄皿 ̄)ノ ⌒=== ┫",
"・.:゚。┣\(’ロ´\)", "(ノ#▼o▼)ノ ┫:・’.::・", "┣¨┣¨┣¨ヾ(゜Д゜ )ノ┣¨┣¨┣", "┣¨ ୧(๑ ⁼̴̀ᐜ⁼̴́๑)૭",
"((|||||┝\(`д´)/┥|||||))", "┝\( ‘∇^*)^☆/┥ ", "(ノ゚∀゚)ノ ┫:。・:*:・゚’★,。・:*:♪・゚’☆━━━!!!!",
"┻━┻ ︵ ¯\\\ (ツ)/¯ ︵ ┻━┻", "┻━┻ ︵ヽ(`Д´)ノ︵ ┻━┻", "┻━┻ ︵ヽ(`Д´)ノ︵ ┻━┻", "┻━┻ ︵ ¯\\\(ツ)/¯ ︵ ┻━┻",
"┫┻┠⌒ヾ(-_-ヾ 三 ノ-_-)ノ⌒┫:・┫┻", "(/>□<)/亠亠", "(ノ ̄_ ̄)ノ\。:・゛。", "(ノÒ益Ó)ノ彡▔▔▏", "_|___|_ ╰(º o º╰) ",
"(ノ ̄ ̄∇ ̄ ̄)ノ~~~~~⌒━━┻━━┻━━", "⊂(ノ ̄ ̄ ̄(工) ̄ ̄ ̄)⊃ノ~~~~~━━━┻━━┻━━━", "(ノ-o-)ノ┸┸)`3゜)・;’.",
"(ノ-。-)ノ┻━┻☆( ^)", "(ノ-_-)ノ ~┻━┻ (/o\)", "(ノ#-◇-)ノ ~~~~┻━┻☆(x _ x)ノ", "(ノ`0)ノ ⌒┫ ┻ ┣ ┳☆(x x)",
"(ノ`m´)ノ ~┻━┻ (/o\)", "(ノ`Д´)ノ.:・┻┻)`з゜)・:゙; ", "(ノ ̄▽ ̄)ノ┻━┻☆)* ̄□)ノ))", "(ノ ̄◇ ̄)ノ~┻━┻/(×。×)",
"(ノToT)ノ ┫:・’.::・\┻┻(・_\)", "(╯°□°)╯︵ ┻━┻ ︵ ╯(°□° ╯)", "(ノ^_^)ノ┻━┻ ┬─┬ ノ( ^_^ノ)", "ミ┻┻(ノ>。<)ノ",
".::・┻┻☆()゚O゚)", "(ノ`A”)ノ ⌒┫ ┻ ┣ ┳☆(x x)", "(ノ`m´)ノ ~┻━┻ (/o\)", "⌒┫ ┻ ┣ ⌒┻☆)゚⊿゚)ノ",
"(ノ≧∇≦)ノ ミ ┸┸)`ν゚)・;’.", "(ノToT)ノ ┫:・’.::・\┻┻(・_\)", "(ノ-o-)ノ ”″┻━┻☆(>○<)",
"ミ(ノ ̄^ ̄)ノ!≡≡≡≡≡━┳━☆() ̄□ ̄)/", "(メ`д´)┫~┻┻ ~┣~┳┳ (。@ヘ@。川", "ミ(ノ ̄^ ̄)ノ≡≡≡≡≡━┳━☆() ̄□ ̄)/",
"(╯°Д°)╯︵/(.□ . )", "(ノಠ ∩ಠ)ノ彡( o°o)", "/( .□.) ︵╰(゜益゜)╯︵ /(.□. /)",
"≡/( .-.)\\\ ︵╰(«○»益«○»)╯︵ /(.□. /)̨", "(/ .□.)\\\ ︵╰(゜Д゜)╯︵ /(.□. \\\)", "(╯°□°)╯︵( .o.)",
"(╯°□°)╯︵ (\\\ . 0 .)(/ ̄(エ) ̄)/ ⌒ ○┼<", "(╯°□°)╯︵ /( ‿⌓‿ )ノ┬─┬ノ ︵ ( o°o)", "┬─┬ ︵ /(.□. \\\)",
"┬──┬╯︵ /(.□. \\\)", "┬──┬ ︵(╯。□。)╯", "ヘ(´° □°)ヘ┳━┳", "(╯°□°)╯︵ ʞooqǝɔɐℲ", "(╯°□°)╯︵ ɹǝʇʇıʍ⊥",
"(∿°○°)∿ ︵ ǝʌol", "(╯°□°)╯︵ ɯsıɥdɹoɯouǝʞs", "(╯°□°)╯︵ sɯɐxǝ", "(╯°□°)╯︵ ƃuıʎpnʇs", "(╯°□°)╯︵ ʞɹoʍ",
"(੭ ◕㉨◕)੭ =͟͟͞͞=͟͟͞͞三❆)’дº);,’:=͟͟͞͞", "(ノꐦ ◎曲◎)ノ=͟͟͞͞ ⌨", "(っ ºДº)っ ︵ ⌨", "(╯^□^)╯︵ ❄☃❄",
"(╯ `Д ́)╯︵ (฿)", "♡╰(*゚x゚*)╯♡", "˭̡̞(◞⁎˃ᆺ˂)◞₎₎=͟͟͞͞✉", "(۶ૈ ۜ ᵒ̌▱๋ᵒ̌ )۶ૈ=͟͟͞͞ ⌨`ワ°)・;’.",
"╰( ^o^)╮-=ニ=一=三", "(ノ>_<)ノ ≡●", "●~*⌒ ヽ(´ー` )", "!!(⊃ Д)⊃≡゚ ゚", "(╬☉д⊙)=◯)๏д๏))・;’.",
"(ര̀⍨ര́)و ̑̑༉ լਕ ̏੭ჯ ૅੁ~ɭ ɿ❢❢", "˭̡̞(◞⁎˃ᆺ˂)◞₎₎=͟͟͞͞˳˚॰°ₒ৹๐", "૮(ꂧ᷆⺫ꂧ᷇)ა=͟͟͞͞ꊞ",
"ヽ[・∀・]ノ(((((((((●~*", "ヘ|・∀・|ノ*~●", "(*ノ゚▽゚)ノ ⌒((((●", "(╯°□°)╯︵ ส็็็็็็็ส", "⌨ █▬▬◟(`ﮧ´ ◟ )",
"○三 \( ̄^ ̄\)", ",,,,,,,,((* ̄(エ) ̄)ノ ⌒☆ o*_(x)_)", "(۶ૈ‡▼益▼)۶ૈ=͟͟͞͞ ⌨", "(ノω・)ノ⌒゛◆",
"(۶ૈ ۜ ᵒ̌▱๋ᵒ̌ )۶ૈ=͟͟͞͞ ⌨", "(۶ૈ ᵒ̌ Дᵒ̌)۶ૈ=͟͟͞͞ ⌨", "☆(ノ^o^)ノ‥‥‥…━━━━〇(^~^)",
"( つ•̀ω•́)つ・・*:・:・゜:==≡≡Σ=͟͟͞͞(✡)`Д´)"],
"flipsList": ["( つ•̀ω•́)つ","(∿°○°)∿","(۶ૈ‡▼益▼)۶", "◟(`ﮧ´ ◟ )","(╯°ਊ°)╯︵", "(づಥਊಥ)づ︵", "(づ๑ʖ๑)┛︵"],
"doubleflipsList": ["╰(*゚x゚*)╯","\(`д´)/","︵╰(゜益゜)╯︵ ","╰(«○»益«○»)╯","︵╰(゜Д゜)╯︵"],
"untablesList": ["┬─┬ ノ( ^_^ノ)", "┬──┬◡ノ(° -°ノ)", "┬━┬ ノ( ゜¸゜ノ)", "┬━┬ ノ( ゜-゜ノ)", "┳━┳ ヽ༼ಠل͜ಠ༽ノ",
"┬──┬ ¯\\\_(ツ)",
"┬──┬ ノ( ゜-゜ノ)", "(ヘ・_・)ヘ┳━┳", "┻o(T_T )ミ( ;_;)o┯", "┣ヘ(≧∇≦ヘ)… (≧∇≦)/┳━┳",
"┣ヘ(^▽^ヘ)Ξ(゚▽゚*)ノ┳━┳",
],
"iceCreamList": [
"http://www.daytonaradio.com/wkro/wp-content/uploads/sites/4/2015/07/ice-cream.jpg"],
"sushiList": [
"http://www.shopbelmontmarket.com/wp-content/uploads/page_img_sushi_01.jpg",
"http://www.jim.fr/e-docs/00/02/66/5C/carac_photo_1.jpg",
"https://u.tfstatic.com/restaurant_photos/503/250503/169/612/sushi-company-suggestie-van-de-chef-5fc05.jpg"],
"gunsList": ["(҂‾ ▵‾)︻デ═一 (˚▽˚’!)/",
"̿’ ̿’\\\̵͇̿̿\\\з=(ಥДಥ)=ε/̵͇̿̿/’̿’̿",
"( う-´)づ︻╦̵̵̿╤── \\\(˚☐˚”)/",
"(⌐■_■)–︻╦╤─",
"̿̿ ̿̿ ̿’̿’̵͇̿̿з=༼ ▀̿̿Ĺ̯̿̿▀̿ ̿ ༽ ",
"━╤デ╦︻(▀̿̿Ĺ̯̿̿▀̿ ̿)",
"╾━╤デ╦︻ ▄︻̷̿┻̿═━一", "︻╦̵̵͇̿̿̿̿══╤─",
"༼ ಠل͟ಠ༽ ̿ ̿ ̿ ̿’̿’̵з=༼ຈل͜ຈ༽ノ",
"̿’ ̿’\\\̵͇̿̿\\\з=(ಡل͟ಡ)=ε/̵͇̿̿/’̿’̿",
"¬o( ̄- ̄メ)", "(҂`з´).っ︻デ═一",
"ᕕ╏ ͡ᵔ ‸ ͡ᵔ ╏و︻̷┻̿═━一", "⌐╦╦═─",
"(゚皿゚)r┏┳---*",
"・-/(。□。;/)—-┳┓y(-_・ )", "(メ▼▼)┏)゚o゚)",
"[ノಠೃಠ]︻̷┻̿═━一", "……┳┓o(▼▼キ)",
"(キ▼▼)o┏┳……", "(メ▼皿▼)┳*–",
"̿̿’̿’\\\̵͇̿̿\\\=(•̪●)=/̵͇̿̿/’̿̿ ̿ ̿ ̿",
"】゚Д゚)┳—-゚~:;’:;ω*:;’;—-",
"ξ(✿ ❛‿❛)ξ▄︻┻┳═一 ",
"⁞ つ: •̀ ⌂ •́ : ⁞-︻╦̵̵͇̿̿̿̿══╤─",
"╾━╤デ╦︻ԅ། ・ิ _ʖ ・ิ །ง",
"……┳┓o(-`Д´-メ )",
"┌( ͝° ͜ʖ͡°)=ε/̵͇̿̿/’̿’̿ ̿ └། ๑ _ ๑ །┘",
"(‥)←¬~(▼▼#)~~",
"(ง⌐□ل͜□)︻̷┻̿═━一",
"‘̿’\\\̵͇̿̿\\\=( `◟ 、)=/̵͇̿̿/’̿̿ ̿",
"༼ ºل͟º ༽ ̿ ̿ ̿ ̿’̿’̵з=༼ ▀̿Ĺ̯▀̿ ̿ ༽",
"(キ▼▼)_┏┳……",
"( ͝ಠ ʖ ಠ)=ε/̵͇̿̿/’̿’̿ ̿",
"ლ(~•̀︿•́~)つ︻̷┻̿═━一",
"(ง ͠° / ^ \\\ °)-/̵͇̿̿/’̿’̿ ̿",
"(‘ºل͟º)ノ⌒. ̿̿ ̿̿ ̿’̿’̵͇̿̿з=༼ ▀̿̿Ĺ̯̿̿▀̿ ̿ ༽",
"(▀̿̿Ĺ̯̿̿▀̿ ̿)•︻̷̿┻̿┻═━━ヽ༼ຈ益ຈ༽ノ",
"ー═┻┳︻▄ξ(✿ ❛‿❛)ξ▄︻┻┳═一",
"ヘ(ToTヘ))) ・ — ε¬(▼▼メ)凸",
"( メ▼Д▼)┏☆====(((_◇_)======⊃",
"!! ( メ▼Д▼)┏☆====(((_◇_)======⊃",
"!!(★▼▼)o┳*—————–●));´ロ`))",
"!! ヘ(ToTヘ))) ・ — ε¬(▼▼メ)凸",
"ヽ༼ຈ益ຈ༽_•︻̷̿┻̿═━一|<——— ҉ Ĺ̯̿̿▀̿ ̿)",
"ヽ༼xل͜x༽ノ <===== ̿’ ̿’\\\̵͇̿̿\\\з༼ຈل͜ຈ༽ ε/̵͇̿̿/’̿’̿ =====> ヽ༼xل͜x༽ノ",
"ლ[☉︿)७)७︻̷┻̿═━一︻̷┻̿═━一",
"( φ_<)r┬ ━━━━━━…=>"],
"owners": ["113953", "135450", "24986","117922"]
}
def handleEvents(room, event):
if 'user_id' in event and event['user_id']==chatbot.bot_chat_id: return # don't consider events from the bot*
if event['event_type']==1: # event: new message
handleMessage(room, event)
if event['event_type']==3: # event: user entered the room
pass
if event['event_type']==6: # event: change in the stars on a message
pass
if event['event_type']==10: # event: message deleted
pass
commands={} #format :: {init : {cmd_msg : [func, sep]}, ...}
def addCommand(func, cmd_msg, init='!!', sep='/'):
# adds commands following the following pattern
# func(a,b,c) for message "!!cmd_msg/a/b/c"
if not init in commands:
commands[init]={}
commands[init][cmd_msg]=[func, sep]
def initCommands():
def exit(room, event, *args):
if event['user_id']==117922: # Hippalectryon
room.leave()
def exit_all(room, event, *args):
if event['user_id']==117922: # Hippalectryon
chatbot.leaveAllRooms()
def repeat(room, event, *args): # nope
return
s=args[0]
room.sendMessage(s)
def wiki(room, event, *args):
article = args[0]
room.sendMessage("https://en.wikipedia.org/wiki/{}".format(article))
def flip(room, event, *args):
if len(args)==0: # no args
room.sendMessage(random.choice(coolTables["tablesList"]))
else:
msg=args[0]
room.sendMessage(random.choice(coolTables["flipsList"])+upsidedown.transform(msg)[::-1])
def molec_img(room, event, *args):
def removeUselessSpace(name):
image = Image.open(name)
image.load()
imageBox = image.getbbox()
cropped = image.crop(imageBox)
cropped.save(name)
molec=args[0]
id = room.sendMessage("Hold tight, I'm processing your request ... {}".format(random.choice(coolTables["tablesList"])))
reqUrl = "http://cactus.nci.nih.gov/chemical/structure/{}/image".format(molec)
molecImg = chatbot.session.get(reqUrl, stream=True)
with open('{}/mol.gif'.format(room.temp_path), 'wb') as out_file:
shutil.copyfileobj(molecImg.raw, out_file)
try:
Image.open('{}/mol.gif'.format(room.temp_path)).save('{}/mol.png'.format(room.temp_path))
except Exception as e:
room.editMessage("<An error occured : {}. Check your molecule's name>".format(e), id)
return
del molecImg
removeUselessSpace('{}/mol.png'.format(room.temp_path))
ans = ""
try:
ans = clientImg.upload_from_path('{}/mol.png'.format(room.temp_path))
except Exception as e:
room.editMessage("<An error occured : {}. Check your molecule's name>".format(e), id)
return
url = ans['link']
room.editMessage(url, id)
def doubleflip(room, event, *args):
if len(args)==0: # no args
room.sendMessage(random.choice(coolTables["tablesList"]))
else:
msg=args[0]
sss=upsidedown.transform(msg)
room.sendMessage("{}{}{}".format(sss,random.choice(coolTables["doubleflipsList"]),sss[::-1]))
def untable(room, event, *args):
room.sendMessage(random.choice(coolTables["untablesList"]))
def gun(room, event, *args):
room.sendMessage(random.choice(coolTables["gunsList"]))
def beer(room, event, *args):
room.sendMessage("http://www.mandevillebeergarden.com/wp-content/uploads/2015/02/Beer-Slide-Background.jpg")
def tea(room, event, *args):
room.sendMessage("https://www.drinkpreneur.com/wp-content/uploads/2017/02/drinkpreneur_health-benefits-of-rose-tea.jpg")
def spam(room, event, *args):
room.sendMessage("https://upload.wikimedia.org/wikipedia/commons/0/09/Spam_can.png")
def coffee(room, event, *args):
room.sendMessage("http://res.freestockphotos.biz/pictures/10/10641-a-cup-of-coffee-on-a-bean-background-pv.jpg")
def sushi(room, event, *args):
room.sendMessage(random.choice(coolTables["sushiList"]))
def ice_cream(room, event, *args):
room.sendMessage(random.choice(coolTables["iceCreamList"]))
def test(room, event, *args):
id=room.sendMessage("a test")
time.sleep(1)
room.editMessage("test - success !", id)
def help(room, event, *args):
helpString = """Hi! I'm the almighty bot of ChemistrySE's main chatroom. /!\ If you find me annoying, you can ignore me by clicking on my profile image and chosing "ignore this user" /!\ You can find my documentation [here](http://meta.chemistry.stackexchange.com/a/3198/5591)."""
room.sendMessage(helpString)
addCommand(exit, 'exit')
addCommand(exit_all, 'exit!')
addCommand(beer, 'beer')
addCommand(tea, 'tea')
addCommand(spam, 'spam')
addCommand(coffee, 'coffee')
addCommand(sushi, 'sushi')
addCommand(ice_cream, 'ice cream')
addCommand(repeat, 'repeat')
addCommand(wiki, 'wiki')
addCommand(flip, 'flip')
addCommand(molec_img, 'img')
addCommand(doubleflip, 'doubleflip')
addCommand(untable, 'untable')
addCommand(gun, 'gun')
addCommand(test, 'test')
addCommand(help, 'help')
initCommands()
def handleMessage(room, event):
content = event["content"]
user_name = event['user_name']
user_id = event['user_id']
chat_room_name = event['room_name']
chat_room_id = event['room_id']
log('[{} - {}] Got message "{}" from user {}, id={}'.format(chat_room_name, chat_room_id, content, user_name, user_id))
for init in commands:
if content.find(init)==0: # find if the init is registered
content_=content[len(init):]
for cmd_msg in commands[init]:
if content_.find(cmd_msg)==0: # find if the command is registered
func, sep=commands[init][cmd_msg]
content_=content_[len(cmd_msg)+len(sep):]
args=content_.split(sep)
if args==['']: args=[]
try:
func(room, event, *args)
except Exception as e:
log("An error occured while launching function {} with args {} : {}".format(cmd_msg, args, e))
chatbot.joinRoom(1,handleEvents) # Sandbox
chatbot.joinRoom(3229,handleEvents) # The Periodic Table