Created
November 13, 2018 15:19
-
-
Save Semior001/4486299d844309a8c1186a428a285afd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import telebot | |
import datetime | |
import time | |
import random | |
from isoweek import Week | |
import config | |
counter = -1 | |
tb = telebot.TeleBot(config.token) | |
file = open("phrases.txt", "r") | |
phrases = file.readlines() | |
file.close() | |
random.shuffle(phrases) | |
lastTime = 0.0 | |
print('=============================') | |
print(':: Перемешиваю фразочки: ::') | |
for i in phrases: | |
print(i.replace('\\n','\n')) | |
print(':: Фразочки перемешаны ::') | |
print('=============================') | |
@tb.message_handler(commands=['week']) | |
def handle_week(message): | |
global phrases | |
global lastTime | |
# currTime = time.time() | |
# if currTime - lastTime < 600: | |
# print('запрос поставлен на hold, разница: ', currTime - lastTime) | |
# return | |
# lastTime = currTime | |
startweek = 33 | |
global counter | |
counter+=1 | |
print(counter) | |
if counter%10 == 0 and counter != 0: | |
tb.send_message(message.chat.id, '''Достигнут очередной десяток вопросов о текущей неделе! Поздравляю, память у вас ни к черту''') | |
i = int(counter%len(phrases)) | |
print("Хм, " + str(i)) | |
tb.send_message(message.chat.id, phrases[i].replace('\\n', '\n').format(str(Week.thisweek().week - startweek))) | |
if counter%len(phrases) == 0 and counter != 0: | |
counter = -1 | |
random.shuffle(phrases) | |
print('=============================') | |
print(':: Перемешиваю фразочки: ::') | |
for i in phrases: | |
print(i.replace('\\n','\n')) | |
print(':: Фразочки перемешаны ::') | |
print('=============================') | |
@tb.message_handler(commands=['update']) | |
def handle_update(message): | |
global phrases | |
print('Загружаю фразочки...') | |
file = open("phrases.txt", "r") | |
phrases = file.readlines() | |
file.close() | |
print('Всего {} фразочек'.format(str(len(phrases)))) | |
global counter | |
random.shuffle(phrases) | |
counter = -1 | |
print('=============================') | |
print(':: Перемешиваю фразочки: ::') | |
for i in phrases: | |
print(i.replace('\\n','\n')) | |
print(':: Фразочки перемешаны ::') | |
print('=============================') | |
tb.send_message(message.chat.id, '''База прикольных фразочек обновлена!''') | |
crashCount = -1 | |
while crashCount < 10: | |
crashCount += 1 | |
try: | |
tb.polling() | |
except Exception as e: | |
print("crash") | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment