Skip to content

Commit f854f9e

Browse files
committed
Adiciona funcao antiflood para evitar erro 429
1 parent d708e3e commit f854f9e

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

bot.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ def concurso_query(query, page=0):
175175
button
176176
)
177177
else:
178-
materia_msg = bot.send_message(
178+
materia_msg = telebot.util.antiflood(
179+
bot.send_message,
179180
query.from_user.id,
180181
message_text,
181182
reply_markup=button
@@ -231,7 +232,8 @@ def bancas_query(query):
231232
button
232233
)
233234
else:
234-
concurso_msg = bot.send_message(
235+
concurso_msg = telebot.util.antiflood(
236+
bot.send_message,
235237
query.from_user.id,
236238
message_text,
237239
reply_markup=button
@@ -274,7 +276,9 @@ def send_rules(message):
274276
if message.chat.id < 0:
275277
return
276278
else:
277-
bot.send_photo(message.chat.id,
279+
telebot.util.antiflood(
280+
bot.send_photo,
281+
message.chat.id,
278282
'AgACAgEAAxkBAAIODmW7suEuE8g5IEts5iuXVaHBJeqJAAKjrTEbfhvgRZLf' +
279283
'-IIi8YBqAQADAgADcwADNAQ',
280284
caption='Envie um pix para a chave <code>[email protected]</code>',
@@ -290,7 +294,8 @@ def informacoes(message):
290294
'https://github.com/GabrielRF/QuestoesDeConcursoBot\n\n' +
291295
'🆘 Entre em contato:\nhttps://chat.grf.xyz/QuestoesDeConcursoBot'
292296
)
293-
bot.send_message(
297+
telebot.util.antiflood(
298+
bot.send_message,
294299
message.from_user.id,
295300
info_message,
296301
parse_mode='HTML',
@@ -332,7 +337,8 @@ def definir_banca(message):
332337
f'A qualquer momento use o <code>Menu</code> para ver as opções do bot\n'
333338
f'Para iniciar uma atividade, selecione uma banca abaixo:'
334339
)
335-
msg = bot.send_message(
340+
msg = telebot.util.antiflood(
341+
bot.send_message,
336342
message.from_user.id,
337343
start_message,
338344
reply_markup=button,
@@ -372,15 +378,18 @@ def send_results(user_id):
372378
message_effect_id=random.choice(effects)
373379
)
374380
except:
375-
bot.send_message(
381+
telebot.util.antiflood(
382+
bot.send_message,
376383
user_id,
377384
end_message,
378385
parse_mode='HTML',
379386
message_effect_id=random.choice(effects)
380387
)
381388

382389
def send_poll(user_id, query_data=None):
383-
bot.send_chat_action(user_id, 'typing')
390+
telebot.util.antiflood(
391+
bot.send_chat_action,user_id, 'typing'
392+
)
384393
try:
385394
banca, concurso, materia, i = query_data.split('#')
386395
except ValueError:
@@ -417,7 +426,8 @@ def send_poll(user_id, query_data=None):
417426
opcoes, correta = poll_options(questoes)
418427

419428
try:
420-
msg = bot.send_message(
429+
msg = telebot.util.antiflood(
430+
bot.send_message,
421431
user_id,
422432
enunciado,
423433
parse_mode='Markdown'
@@ -429,14 +439,15 @@ def send_poll(user_id, query_data=None):
429439
break_every = 5
430440
for palavra in range(0, len(enunciado_split)-1, break_every):
431441
s = '\n'
432-
msg = bot.send_message(
442+
msg = telebot.util.antiflood(
443+
bot.send_message,
433444
user_id,
434445
s.join(enunciado_split[palavra:palavra+break_every]),
435446
parse_mode='Markdown',
436447
reply_to_message_id=msg_id
437448
)
438449
msg_id = msg.id
439-
bot.send_chat_action(user_id, 'typing')
450+
telebot.util.antiflood(bot.send_chat_action, user_id, 'typing')
440451

441452
button = telebot.types.InlineKeyboardMarkup()
442453
button.row(
@@ -448,7 +459,8 @@ def send_poll(user_id, query_data=None):
448459
redis_set(user_id, f'{banca}#{concurso}#{materia}#{i+1}')
449460

450461
try:
451-
poll_msg = bot.send_poll(
462+
poll_msg = telebot.util.antiflood(
463+
bot.send_poll,
452464
user_id,
453465
f'Resposta [{i+1}/{tamanho}]:',
454466
opcoes,
@@ -474,7 +486,8 @@ def send_poll(user_id, query_data=None):
474486
alternativas,
475487
parse_mode='Markdown'
476488
)
477-
poll_msg = bot.send_poll(
489+
poll_msg = telebot.util.antiflood(
490+
bot.send_poll,
478491
user_id,
479492
f'Resposta [{i+1}/{tamanho}]:',
480493
novas_opcoes,

0 commit comments

Comments
 (0)