-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
78 lines (52 loc) · 1.68 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'ipetrash'
import os
import time
# pip install python-telegram-bot
from telegram import Update
from telegram.ext import Updater, MessageHandler, CommandHandler, Filters, CallbackContext, Defaults
from config import TOKEN
from common import get_logger, log_func, reply_error
from third_party import zalgo
log = get_logger(__file__)
@log_func(log)
def on_start(update: Update, context: CallbackContext):
update.effective_message.reply_text(
'Enter something and the bot will return it as Z̗̱̥̝̔̑ͯͬ̈̍̊Ḁ̪̬̟̾L̗̺̞̎̑͑̑̄̓G͎̰̞̯O̹̹ text'
)
@log_func(log)
def on_request(update: Update, context: CallbackContext):
message = update.effective_message
message.reply_text(
zalgo.he_comes(message.text),
quote=True
)
def on_error(update: Update, context: CallbackContext):
reply_error(log, update, context)
def main():
cpu_count = os.cpu_count()
workers = cpu_count
log.debug(f'System: CPU_COUNT={cpu_count}, WORKERS={workers}')
log.debug('Start')
updater = Updater(
TOKEN,
workers=workers,
defaults=Defaults(run_async=True),
)
dp = updater.dispatcher
dp.add_handler(CommandHandler('start', on_start))
dp.add_handler(MessageHandler(Filters.text, on_request))
dp.add_error_handler(on_error)
updater.start_polling()
updater.idle()
log.debug('Finish')
if __name__ == '__main__':
while True:
try:
main()
except:
log.exception('')
timeout = 15
log.info(f'Restarting the bot after {timeout} seconds')
time.sleep(timeout)