-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
45 lines (31 loc) · 1.15 KB
/
main.py
File metadata and controls
45 lines (31 loc) · 1.15 KB
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
#!/usr/bin/env python3
from telegram.ext import Updater, CommandHandler
import logging
from funks import Funks
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
def main(api_key):
"""Start the bot."""
updater = Updater(api_key, use_context=True)
# Get the dispatcher to register handlers
dp = updater.dispatcher
# on different commands - answer in Telegram
functions = Funks()
methods = [getattr(functions, m) for m in dir(functions) if not m.startswith('__')]
names = [x for x in dir(Funks) if not x.startswith('__')]
for i in range(len(methods)):
dp.add_handler(CommandHandler(names[i], methods[i]))
# log all errors
dp.add_error_handler(error)
# Start the Bot
updater.start_polling()
updater.idle()
def error(update, context):
"""Log Errors caused by Updates."""
logger.warning('Update "%s" caused error "%s"', update, context.error)
if __name__ == '__main__':
print("i am running!")
with open("auth2.yaml", 'r') as f:
api_key = f.readline()
main(api_key)