- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbot.py
More file actions
Latest commit
97 lines (81 loc) · 3.45 KB
/
Copy pathbot.py
File metadata and controls
97 lines (81 loc) · 3.45 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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
fromdatetimeimporttime
importlogging
importpytz
fromtelegram.botimportBot
fromtelegram.extimport (Updater, CommandHandler, MessageHandler, Filters, ConversationHandler,
CallbackQueryHandler)
fromtelegram.extimportmessagequeueasmq
fromtelegram.ext.jobqueueimportDays
fromtelegram.utils.requestimportRequest
fromanketaimport (anketa_start, anketa_name, anketa_rating, anketa_skip, anketa_comment,
anketa_dontknow)
fromhandlersimport (greet_user, guess_number, send_cat_picture, user_coordinates,
talk_to_me, check_user_photo, subscribe, unsubscribe, set_alarm,
cat_picture_rating)
fromjobsimportsend_updates
importsettings
logging.basicConfig(filename="bot.log", level=logging.INFO)
PROXY= {'proxy_url': settings.PROXY_URL,
'urllib3_proxy_kwargs': {'username': settings.PROXY_USERNAME, 'password': settings.PROXY_PASSWORD}}
classMQBot(Bot):
def__init__(self, *args, is_queued_def=True, msg_queue=None, **kwargs):
super().__init__(*args, **kwargs)
self._is_messages_queued_default=is_queued_def
self._msg_queue=msg_queueormq.MessageQueue()
def__del__(self):
try:
self._msg_queue.stop()
except:
pass
@mq.queuedmessage
defsend_message(self, *args, **kwargs):
returnsuper().send_message(*args, **kwargs)
defmain():
request=Request(
con_pool_size=8,
proxy_url=PROXY['proxy_url'],
urllib3_proxy_kwargs=PROXY['urllib3_proxy_kwargs']
)
bot=MQBot(settings.API_KEY, request=request)
mybot=Updater(bot=bot, use_context=True)
jq=mybot.job_queue
target_time=time(12, 0, tzinfo=pytz.timezone('Europe/Moscow'))
target_days= (Days.MON, Days.WED, Days.FRI)
jq.run_daily(send_updates, target_time, target_days)
dp=mybot.dispatcher
anketa=ConversationHandler(
entry_points=[
MessageHandler(Filters.regex('^(Заполнить анкету)$'), anketa_start)
],
states={
"name": [MessageHandler(Filters.text, anketa_name)],
"rating": [MessageHandler(Filters.regex('^(1|2|3|4|5)$'), anketa_rating)],
"comment": [
CommandHandler("skip", anketa_skip),
MessageHandler(Filters.text, anketa_comment)
]
},
fallbacks=[
MessageHandler(
Filters.text|Filters.photo|Filters.video|Filters.document|Filters.location,
anketa_dontknow
)
]
)
dp.add_handler(anketa)
dp.add_handler(CommandHandler("start", greet_user))
dp.add_handler(CommandHandler("guess", guess_number))
dp.add_handler(CommandHandler("cat", send_cat_picture))
dp.add_handler(CommandHandler('subscribe', subscribe))
dp.add_handler(CommandHandler('unsubscribe', unsubscribe))
dp.add_handler(CommandHandler('alarm', set_alarm))
dp.add_handler(CallbackQueryHandler(cat_picture_rating, pattern="^(rating|)"))
dp.add_handler(MessageHandler(Filters.regex('^(Прислать котика)$'), send_cat_picture))
dp.add_handler(MessageHandler(Filters.photo, check_user_photo))
dp.add_handler(MessageHandler(Filters.location, user_coordinates))
dp.add_handler(MessageHandler(Filters.text, talk_to_me))
logging.info("Бот стартовал")
mybot.start_polling()
mybot.idle()
if__name__=="__main__":
main()