-
Notifications
You must be signed in to change notification settings - Fork 2
/
start.py
179 lines (152 loc) · 5.66 KB
/
start.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import logging
from random import randint
import re
updater = Updater('TOKEN')
dispatcher = updater.dispatcher
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
# English
def help_en(bot, update):
message = update.message
answer = "Send me a message and I'll give you advice."
bot.send_message(message.chat_id, answer)
print(message.from_user.full_name + ': ' + message.text + ' | ' + 'Bot: ' + answer);
def echo_en(bot, update):
message = update.message
chat_id = message.chat_id
answer = ''
if re.search(r'\b((e+r+i+(c+|k+|c+k+|c+h+|q+u+e+))|(э+р+и+к+\w*))\b', message.text.lower()) != None:
answer = 'He who must not be named...'
else:
value = randint(0, 19)
if value == 0:
answer = 'It is certain'
elif value == 1:
answer = 'It is decidedly so'
elif value == 2:
answer = 'Without a doubt'
elif value == 3:
answer = 'Yes — definitely'
elif value == 4:
answer = 'You may rely on it'
elif value == 5:
answer = 'As I see it, yes'
elif value == 6:
answer = 'Most likely'
elif value == 7:
answer = 'Outlook good'
elif value == 8:
answer = 'Signs point to yes'
elif value == 9:
answer = 'Yes'
elif value == 10:
answer = 'Reply hazy, try again'
elif value == 11:
answer = 'Ask again later'
elif value == 12:
answer = 'Better not tell you now'
elif value == 13:
answer = 'Cannot predict now'
elif value == 14:
answer = 'Concentrate and ask again'
elif value == 15:
answer = 'Don’t count on it'
elif value == 16:
answer = 'My reply is no'
elif value == 17:
answer = 'My sources say no'
elif value == 18:
answer = 'Outlook not so good'
else:
answer = 'Very doubtful'
bot.send_message(chat_id, answer)
print(message.from_user.full_name + ': ' + message.text + ' | ' + 'Bot: ' + answer);
def unknown_en(bot, update):
message = update.message
answer = "Sorry, I didn't understand that command."
bot.send_message(message.chat_id, answer)
print(message.from_user.full_name + ': ' + message.text + ' | ' + 'Bot: ' + answer);
start_en_handler = CommandHandler('start', help_en, filters = ~ Filters.language('ru'))
dispatcher.add_handler(start_en_handler)
help_en_handler = CommandHandler('help', help_en, filters = ~ Filters.language('ru'))
dispatcher.add_handler(help_en_handler)
echo_en_handler = MessageHandler(Filters.text & (~ Filters.language('ru')), echo_en)
dispatcher.add_handler(echo_en_handler)
unknown_en_handler = MessageHandler(Filters.command & (~ Filters.language('ru')), unknown_en)
dispatcher.add_handler(unknown_en_handler)
# Russian
def help_ru(bot, update):
message = update.message
answer = 'Отправь мне сообщение, и я дам тебе совет.'
bot.send_message(message.chat_id, answer)
print(message.from_user.full_name + ': ' + message.text + ' | ' + 'Bot: ' + answer);
def echo_ru(bot, update):
message = update.message
chat_id = message.chat_id
answer = ''
if re.search(r'\b((н+е+)* *(у+в+е+р+е+н+))\b', message.text.lower()) != None:
value = randint(0, 1)
if value == 0:
answer = 'Я уверен в этом.'
else:
answer = 'Я не уверен в этом.'
elif re.search(r'\b((e+r+i+(c+|k+|c+k+|c+h+|q+u+e+))|(э+р+и+к+\w*))\b', message.text.lower()) != None:
answer = 'Это тот, чьё имя нельзя называть...'
else:
value = randint(0, 19)
if value == 0:
answer = 'Бесспорно'
elif value == 1:
answer = 'Предрешено'
elif value == 2:
answer = 'Никаких сомнений'
elif value == 3:
answer = 'Определённо да'
elif value == 4:
answer = 'Можешь быть уверен в этом'
elif value == 5:
answer = 'Мне кажется — «да»'
elif value == 6:
answer = 'Вероятнее всего'
elif value == 7:
answer = 'Хорошие перспективы'
elif value == 8:
answer = 'Знаки говорят — «да»'
elif value == 9:
answer = 'Да'
elif value == 10:
answer = 'Пока не ясно, попробуй снова'
elif value == 11:
answer = 'Спроси позже'
elif value == 12:
answer = 'Лучше не рассказывать'
elif value == 13:
answer = 'Сейчас нельзя предсказать'
elif value == 14:
answer = 'Сконцентрируйся и спроси опять'
elif value == 15:
answer = 'Даже не думай'
elif value == 16:
answer = 'Мой ответ — «нет»'
elif value == 17:
answer = 'По моим данным — «нет»'
elif value == 18:
answer = 'Перспективы не очень хорошие'
else:
answer = 'Весьма сомнительно'
bot.send_message(chat_id, answer)
print(message.from_user.full_name + ': ' + message.text + ' | ' + 'Bot: ' + answer);
def unknown_ru(bot, update):
message = update.message
answer = 'Извините, я не понял эту команду.'
bot.send_message(message.chat_id, answer)
print(message.from_user.full_name + ': ' + message.text + ' | ' + 'Bot: ' + answer);
start_ru_handler = CommandHandler('start', help_ru, filters = Filters.language('ru'))
dispatcher.add_handler(start_ru_handler)
help_ru_handler = CommandHandler('help', help_ru, filters = Filters.language('ru'))
dispatcher.add_handler(help_ru_handler)
echo_ru_handler = MessageHandler(Filters.text & Filters.language('ru'), echo_ru)
dispatcher.add_handler(echo_ru_handler)
unknown_ru_handler = MessageHandler(Filters.command & Filters.language('ru'), unknown_ru)
dispatcher.add_handler(unknown_ru_handler)
updater.start_polling()