-
Notifications
You must be signed in to change notification settings - Fork 0
/
vaska_bot.py
126 lines (107 loc) · 3.22 KB
/
vaska_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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# -*- coding: utf-8 -*-
from handlers import *
from my_filter import Filter
from mailru_im_async_bot.bot import Bot
from mailru_im_async_bot.handler import StartCommandHandler, MessageHandler, CommandHandler, DefaultHandler, BotButtonCommandHandler, NewChatMembersHandler, LeftChatMembersHandler
from logging.config import fileConfig
from pid import PidFile
import wolframalpha
import asyncio
import logging
import sys
import os
configs_path = os.path.realpath(os.path.dirname(sys.argv[0])) + "/"
# Get config path from args
if len(sys.argv) > 1:
configs_path = sys.argv[1]
if not os.path.isfile(os.path.join(configs_path, "logging.ini")):
raise FileExistsError(f"File logging.ini not found in path {configs_path}")
logging.config.fileConfig(os.path.join(configs_path, "logging.ini"), disable_existing_loggers=False)
log = logging.getLogger(__name__)
loop = asyncio.get_event_loop()
NAME = "vaska"
TOKEN = "***.**********.**********:*********"
APP_ID = "******-********"
client = wolframalpha.Client(APP_ID)
bot = Bot(token=TOKEN, name=NAME)
# Register your handlers here
# ---------------------------------------------------------------------
bot.dispatcher.add_handler(StartCommandHandler(
callback=new_start_bot
)
)
bot.dispatcher.add_handler(MessageHandler(
callback=sticker,
filters=Filter.sticker
)
)
bot.dispatcher.add_handler(MessageHandler(
callback=media,
filters=Filter.media
)
)
bot.dispatcher.add_handler(MessageHandler(
callback=ask,
filters=Filter.regexp('(?i)получить(.*?)отве(т)|найти(.*?)решени(е|я)|(реш(и|ить)|помоги)(.*?)(приме(р|ы)|зада|мате|физ|хим|дома)')
)
)
bot.dispatcher.add_handler(MessageHandler(
callback=help_mi,
filters=Filter.chaotic_args(['что', 'ты', ['умеешь', 'умешь', 'умеешь?', 'умешь?']])
)
)
bot.dispatcher.add_handler(MessageHandler(
callback=write_text,
filters=Filter.chaotic_args([['сделай', 'напиши'], ['конспект', 'сочинение']])
)
)
bot.dispatcher.add_handler(CommandHandler(
callback=add_phrases,
command='addPhrases'
)
)
bot.dispatcher.add_handler(CommandHandler(
callback=add_answer,
command='addAnswer'
)
)
bot.dispatcher.add_handler(MessageHandler(
callback=rand_answer,
filters=Filter.regexp(r'(?i).+\?$(?<!что мне задали\?)(?<!что ты умеешь\?)(?<!что ты умешь\?)')
)
)
bot.dispatcher.add_handler(DefaultHandler(
callback=def_phrases
)
)
bot.dispatcher.add_handler(BotButtonCommandHandler(
callback=button_1,
filters=Filter.callback_data('call_back_id_1')
)
)
bot.dispatcher.add_handler(BotButtonCommandHandler(
callback=button_2,
filters=Filter.callback_data('call_back_id_2')
)
)
bot.dispatcher.add_handler(BotButtonCommandHandler(
callback=button_3,
filters=Filter.callback_data('call_back_id_3')
)
)
bot.dispatcher.add_handler(BotButtonCommandHandler(
callback=button_4,
filters=Filter.callback_data('call_back_id_4')
)
)
bot.dispatcher.add_handler(BotButtonCommandHandler(
callback=def_phrases,
filters=Filter.callback_data('call_back_id_5')
)
)
with PidFile(NAME):
try:
loop.create_task(bot.start_polling())
loop.run_forever()
finally:
loop.close()