forked from gabekanegae/botdokanebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
450 lines (338 loc) · 15.3 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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
from telegram.ext import Updater, CommandHandler
from sys import argv
import requests
import logging
import praw
import random as rd
from time import time, strftime, gmtime
import auth # Telegram Bot Token
from utils import *
def start(update, context):
logMessageReceived(update, context, logger)
s = "ta rodando ja ue"
update.message.reply_text(s, parse_mode="Markdown")
logMessageSent(update, context, logger, "TXT", s)
def help(update, context):
logMessageReceived(update, context, logger)
h = [
"pra ver os comando digita / no chat e ve qq aparece ali\n",
"\n",
"vamo ajuda a faze o bot kkkkk\n",
"https://github.com/tiagotriques/notbotdokanebot/\n"
]
s = "".join(h)
update.message.reply_text(s, parse_mode="Markdown")
logMessageSent(update, context, logger, "TXT", s)
def _getRandomFromFile(update, context, file):
logMessageReceived(update, context, logger)
now = int(time())
s = None
tries = 0
while ((not s) or (s in memory and now-memory[s] < MEMORY_TIMEOUT)) and (tries < MAX_TRIES):
tries += 1
s = rd.choice(file)
memory[s] = now
update.message.reply_text(s, parse_mode="Markdown")
logMessageSent(update, context, logger, "TXT", s)
logger.info(" --> {} tries | Mem size: {}".format(tries, len(memory)))
def bcc(update, context): _getRandomFromFile(update, context, bccList)
def bbc(update, context): _getRandomFromFile(update, context, bbcList)
def icmc(update, context): _getRandomFromFile(update, context, icmcList)
def usp(update, context): _getRandomFromFile(update, context, uspList)
def becd(update, context): _getRandomFromFile(update, context, becdList)
def bsi(update, context): _getRandomFromFile(update, context, bsiList)
def filme(update, context):
logMessageReceived(update, context, logger)
now = int(time())
s = None
tries = 0
while ((s is None) or (s in memory and now-memory[s] < MEMORY_TIMEOUT)) and (tries < MAX_TRIES):
tries += 1
rPalavras = rd.randint(0, len(palavrasM) + len(palavrasF) - 1)
pick = rd.choice(filmeList)
if rPalavras < len(palavrasM):
s = parseGender(pick, "male").format(word=palavrasM[rPalavras])
else:
rPalavras -= len(palavrasM)
s = parseGender(pick, "female").format(word=palavrasF[rPalavras])
memory[s] = now
update.message.reply_text(s, parse_mode="Markdown")
logMessageSent(update, context, logger, "TXT", s)
logger.info(" --> {} tries | Mem size: {}".format(tries, len(memory)))
def fwd(update, context):
logMessageReceived(update, context, logger)
now = int(time())
tries = 0
while True:
messageID = rd.randint(0, MAX_FWD_ID)
try:
tries += 1
s = "fwd#" + str(messageID)
if s not in memory or now-memory[s] >= MEMORY_TIMEOUT or tries >= MAX_TRIES:
context.bot.forwardMessage(
update.effective_chat.id, "@ofwdnovo", messageID)
memory[s] = now
break
except Exception:
pass
logMessageSent(update, context, logger, "FWD", str(
messageID), origID=messageID, origChannel="@ofwdnovo")
logger.info(" --> {} tries | Mem size: {}".format(tries, len(memory)))
def cu(update, context):
logMessageReceived(update, context, logger)
now = int(time())
tries = 0
while True:
messageID = rd.randint(0, MAX_FWD_CU_ID)
try:
tries += 1
s = "fwd#" + str(messageID)
if s not in memory or now-memory[s] >= MEMORY_TIMEOUT or tries >= MAX_TRIES:
context.bot.forwardMessage(
update.effective_chat.id, "@fwdcu", messageID)
memory[s] = now
break
except Exception:
pass
logMessageSent(update, context, logger, "FWD", str(
messageID), origID=messageID, origChannel="@fwdcu")
logger.info(" --> {} tries | Mem size: {}".format(tries, len(memory)))
def joegs(update, context):
logMessageReceived(update, context, logger)
origMsg = update.message.reply_to_message
queryText = None
if origMsg and origMsg.text:
queryText = origMsg.text
else:
s = "manda o comando respondendo a alguma msg pfvr"
if queryText:
body = {"text": queryText, "model": "pos"}
try:
r = requests.post(url=JOEGS_URL, data=body).json()
if r["result"] == "REAL":
s = "hmmm acho q eh vdd"
else:
s = "sei nao hein, se pa eh fake"
except Exception:
s = "caraio o joegs fudeu o role, alguem chama ele"
update.message.reply_text(s, parse_mode="Markdown")
logMessageSent(update, context, logger, "TXT", s)
def zapzap(update, context):
logMessageReceived(update, context, logger)
origMsg = update.message.reply_to_message
queryText = None
if origMsg and origMsg.text:
queryText = origMsg.text
else:
s = "manda o comando respondendo a alguma msg pfvr\n\nopções: angry/happy/sad/sassy/sick"
if queryText:
mood = "happy"
if len(context.args) != 0:
userMood = context.args[0].lower()
if userMood in moodAngry:
mood = "angry"
elif userMood in moodHappy:
mood = "happy"
elif userMood in moodSad:
mood = "sad"
elif userMood in moodSassy:
mood = "sassy"
elif userMood in moodSick:
mood = "sick"
origMsgWords = len(origMsg.text.split())
if origMsgWords <= 5:
rate = "1.0"
elif origMsgWords <= 15:
rate = "0.8"
else:
rate = "0.6"
body = {"zap": queryText, "mood": mood,
"strength": "3", "rate": rate, "tweet": "false"}
try:
r = requests.post(url=FLIPPER_URL, data=body).json()
if r["zap"]:
s = r["zap"]
except Exception:
s = "puta merda chama o flipper que deu ruim aqui"
update.message.reply_text(s, parse_mode="Markdown")
logMessageSent(update, context, logger, "TXT", s)
def _getRandomFromReddit(update, context, subreddit, user=None):
logMessageReceived(update, context, logger)
now = int(time())
tries = 0
while True:
try:
tries += 1
imgDesc, imgUrl = getRandomImageReddit(reddit, subreddit, user)
s = subreddit + "#" + imgUrl
if imgUrl and (s not in memory or now-memory[s] >= MEMORY_TIMEOUT or tries >= MAX_TRIES):
memory[s] = now
break
except Exception:
pass
context.bot.send_photo(chat_id=update.effective_chat.id,
photo=imgUrl, caption=imgDesc)
logMessageSent(update, context, logger, "IMG", imgDesc, url=imgUrl)
logger.info(" --> {} tries | Mem size: {}".format(tries, len(memory)))
def foodporn(update, context): _getRandomFromReddit(
update, context, "foodporn")
def shittyfoodporn(update, context): _getRandomFromReddit(
update, context, "shittyfoodporn")
def superaww(update, context): _getRandomFromReddit(
update, context, "superaww", "316nuts")
def programmerhumor(update, context): _getRandomFromReddit(
update, context, "programmerhumor")
def bandeco(update, context):
logMessageReceived(update, context, logger)
combos = [(301, 302), (326, 327), (843, 844)]
pick = rd.choice(combos)
context.bot.forwardMessage(update.effective_chat.id, "@ofwdnovo", pick[0])
logMessageSent(update, context, logger, "FWD", str(
pick[0]), origID=pick[0], origChannel="@ofwdnovo")
context.bot.forwardMessage(update.effective_chat.id, "@ofwdnovo", pick[1])
logMessageSent(update, context, logger, "FWD", str(
pick[1]), origID=pick[1], origChannel="@ofwdnovo")
def toschi(update, context):
logMessageReceived(update, context, logger)
m = int(strftime("%m", gmtime(time()-3*60*60)))
if m <= 6:
s = "po ta cedo ainda deixa os bixo vir kdkd"
update.message.reply_text(s, parse_mode="Markdown")
logMessageSent(update, context, logger, "TXT", s)
return
context.bot.forwardMessage(update.effective_chat.id, "@ofwdnovo", 362)
logMessageSent(update, context, logger, "FWD", "362",
origID=362, origChannel="@ofwdnovo")
context.bot.forwardMessage(update.effective_chat.id, "@ofwdnovo", 363)
logMessageSent(update, context, logger, "FWD", "363",
origID=363, origChannel="@ofwdnovo")
def proximo(update, context, option=None):
logMessageReceived(update, context, logger)
m, d, A, H = strftime("%m %d %A %H", gmtime(time()-3*60*60)).split()
H = int(H)
weekdays = {"Monday": "Segunda", "Tuesday": "Terça",
"Wednesday": "Quarta", "Thursday": "Quinta",
"Friday": "Sexta", "Saturday": "Sábado",
"Sunday": "Domingo"}
if not option:
if H <= 13:
mealTime = "☀ Almoço"
elif H >= 19:
mealTime = "☀ Almoço"
m, d, A, H = strftime("%m %d %A %H", gmtime(
time()-3*60*60+5*60*60)).split()
H = int(H)
else:
mealTime = "🌙 Jantar"
elif option == "almoco":
mealTime = "☀ Almoço"
else:
mealTime = "🌙 Jantar"
weekday = weekdays[A]
day = d + "/" + m
if weekday == "Domingo" or (weekday == "Sábado" and mealTime == "🌙 Jantar"):
s = "*🏫 São Carlos, Área 1 🍽\n{} de {} ({}):*\nFechado"
s = s.format(mealTime, weekday, day)
update.message.reply_text(s, parse_mode="Markdown")
return
mealKey = "cardapio#" + day + mealTime[2]
if mealKey in memory:
s = memory[mealKey]
update.message.reply_text(s, parse_mode="Markdown")
return
calories = rd.randint(550, 1350)
s, c = cardapio.index("SALADAS")+1, cardapio.index("CARNES")+1
v, m = cardapio.index("VEGS")+1, cardapio.index("MISTURAS")+1
d, f = cardapio.index("DOCES")+1, cardapio.index("FRUTAS")+1
p, b = cardapio.index("PAES")+1, cardapio.index("BEBIDAS")+1
salada = rd.choice(cardapio[s:c-2])
carne = rd.choice(cardapio[c:v-2])
veg = rd.choice(cardapio[v:m-2])
mistura = rd.choice(cardapio[m:d-2])
doce = rd.choice(cardapio[d:f-2])
fruta = rd.choice(cardapio[f:p-2])
pao = rd.choice(cardapio[p:b-2])
bebida = rd.choice(cardapio[b:])
s = "*🏫 São Carlos, Área 1 🍽\n{} de {} ({}):*\n"
s += "Arroz/Feijão/Arroz Integral/\n{}/\n{}\n"
s += "Opção Vegetariana: {}/\n{}/\nSobremesa: {}\n{}/\n"
s += "{}\n{}\n\n_Valor energético médio: ⚡ {}Kcal_"
s = s.format(mealTime, weekday, day, salada, carne, veg,
mistura, doce, fruta, pao, bebida, calories)
memory[mealKey] = s
update.message.reply_text(s, parse_mode="Markdown")
logMessageSent(update, context, logger, "TXT", s)
def almoco(update, context): proximo(update, context, "almoco")
def jantar(update, context): proximo(update, context, "jantar")
def _sendSimpleText(update, context, text):
logMessageReceived(update, context, logger)
update.message.reply_text(text, parse_mode="Markdown")
logMessageSent(update, context, logger, "TXT", text)
def matricula(update, context):
_sendSimpleText(update, context, "mais um semestre nao pfv n aguento mais")
def main():
updater = Updater(token=TOKEN, use_context=True)
dp = updater.dispatcher
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("help", help))
dp.add_handler(CommandHandler("filme", filme))
dp.add_handler(CommandHandler("bcc", bcc))
dp.add_handler(CommandHandler("bbc", bbc))
dp.add_handler(CommandHandler("becd", becd))
dp.add_handler(CommandHandler("bsi", bsi))
dp.add_handler(CommandHandler("icmc", icmc))
dp.add_handler(CommandHandler("usp", usp))
dp.add_handler(CommandHandler("fwd", fwd))
dp.add_handler(CommandHandler("cu", cu))
dp.add_handler(CommandHandler("joegs", joegs))
dp.add_handler(CommandHandler("zapzap", zapzap))
dp.add_handler(CommandHandler("comtompero", foodporn))
dp.add_handler(CommandHandler("semtompero", shittyfoodporn))
dp.add_handler(CommandHandler("itimalia", superaww))
dp.add_handler(CommandHandler("computaria", programmerhumor))
dp.add_handler(CommandHandler("almoco", almoco))
dp.add_handler(CommandHandler("jantar", jantar))
dp.add_handler(CommandHandler("proximo", proximo))
dp.add_handler(CommandHandler("bandeco", bandeco))
dp.add_handler(CommandHandler("toschi", toschi))
dp.add_handler(CommandHandler("matricula", matricula))
updater.start_polling()
logging.info("=== Bot running! ===")
updater.idle()
if __name__ == "__main__":
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s",
handlers=[logging.FileHandler("bot.log", "a", "UTF-8"), logging.StreamHandler()])
JOEGS_URL = "http://nilc-fakenews.herokuapp.com/ajax/check/"
FLIPPER_URL = "http://zapzap/api/v1.0/zap/" # Docker compose
bccList = loadFile("bcc.txt")
bbcList = loadFile("bbc.txt")
icmcList = loadFile("icmc.txt")
uspList = loadFile("usp.txt")
becdList = loadFile("becd.txt")
bsiList = loadFile("bsi.txt")
filmeList = loadFile("filme.txt")
palavrasM = ["cu", "pinto", "caralho"]
palavrasF = ["bunda"]
cardapio = loadFile("cardapio.txt")
emojiAngry = "😡😠🤬😤😣"
emojiHappy = "😀😃😄😁😆😅🤣😂🙂🙃😊😇🥰😍🤩☺😋😛😜🤪😝🤑🤗🤭🤔😬😌😪🤤😴🤠🥳😎🤓🧐"
emojiSad = "🤐🤫🤨😐😑😶😒🙄😔🤥😕😟🙁☹😮😯😲😳🥺😦😧😨😰😥😢😭😱😖😞😓😩😫"
emojiSassy = "😏😚😙😉😘😗😈👿"
emojiSick = "😷🤒🤕🤢🤮🤧🥵🥶🥴😵🤯"
moodAngry = set(["angry", "bravo", "brabo", "puto"] + list(emojiAngry))
moodHappy = set(["happy", "feliz"] + list(emojiHappy))
moodSad = set(["sad", "triste"] + list(emojiSad))
moodSassy = set(["sassy", "tarado", "safado"] + list(emojiSassy))
moodSick = set(["sick", "doente"] + list(emojiSick))
MEMORY_TIMEOUT = 5*60 # Doesn't repeat messages shown within the last X seconds
MAX_FWD_ID = 1500 # FWD channel has less than X messages
MAX_FWD_CU_ID = 50 # FWD channel has less than X messages
MAX_TRIES = 100 # Will try showing an unique message X times before giving up
reddit = praw.Reddit(client_id=auth.REDDIT_CID,
client_secret=auth.REDDIT_CSECRET,
user_agent=auth.REDDIT_UA)
memory = {}
TOKEN = auth.TEST_TOKEN if "test" in argv else auth.PROD_TOKEN
main()
logging.info("=== Bot shutting down! ===")