-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.py
61 lines (47 loc) · 2.42 KB
/
bot.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
import logging
from telegram.ext import Updater, CommandHandler, MessageHandler, RegexHandler, ConversationHandler, Filters
from telegram.ext import messagequeue as mq
from handlers import *
import settings
logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s',
level=logging.INFO,
filename='bot.log'
)
subscribers = set()
def main():
mybot = Updater(settings.API_KEY, request_kwargs=settings.PROXY)
mybot.bot._msg_queue = mq.MessageQueue()
mybot.bot._is_messages_queued_default = True
logging.info('Бот запускается')
dp = mybot.dispatcher
mybot.job_queue.run_repeating(send_updates, 5)
anketa = ConversationHandler(
entry_points=[RegexHandler('^(Заполнить анкету)$', anketa_start, pass_user_data=True)],
states={
"name": [MessageHandler(Filters.text, anketa_get_name, pass_user_data=True)],
"rating": [RegexHandler('^(1|2|3|4|5)$', anketa_rating, pass_user_data=True)],
"comment": [MessageHandler(Filters.text, anketa_comment, pass_user_data=True),
CommandHandler('skip', anketa_skip_comment, pass_user_data=True)],
},
fallbacks=[MessageHandler(
Filters.text | Filters.video | Filters.photo | Filters.document,
dontknow,
pass_user_data=True
)]
)
dp.add_handler(CommandHandler('start', greet_user, pass_user_data=True))
dp.add_handler(anketa)
dp.add_handler(CommandHandler('cat', send_cat_picture, pass_user_data=True))
dp.add_handler(RegexHandler('^(Прислать котика)$', send_cat_picture, pass_user_data=True))
dp.add_handler(RegexHandler('^(Сменить аватарку)$', change_avatar, pass_user_data=True))
dp.add_handler(MessageHandler(Filters.contact, get_contact, pass_user_data=True))
dp.add_handler(MessageHandler(Filters.location, get_location, pass_user_data=True))
dp.add_handler(CommandHandler('subscribe', subscribe))
dp.add_handler(CommandHandler('unsubscribe', unsubscribe))
dp.add_handler(CommandHandler('alarm', set_alarm, pass_args=True, pass_job_queue=True))
dp.add_handler(MessageHandler(Filters.photo, check_user_photo, pass_user_data=True))
dp.add_handler(MessageHandler(Filters.text, talk_to_me, pass_user_data=True))
mybot.start_polling()
mybot.idle()
if __name__ == "__main__":
main()