-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
51 lines (42 loc) · 1.97 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
import logging
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, ConversationHandler
from anketa import (anketa_start, anketa_name, anketa_rating, anketa_skip, anketa_comment,
anketa_dontknow)
from handlers import (greet_user, guess_number, send_cat_picture, user_coordinates,
talk_to_me, check_user_photo)
import settings
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}}
def main():
mybot = Updater(settings.API_KEY, use_context=True, request_kwargs=PROXY)
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(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()