-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
218 lines (166 loc) · 6.93 KB
/
main.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import telebot
import time
from threading import Timer
import argparse
import random
import json
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--token', help='telegram bot token', dest='token', required=True)
args = parser.parse_args()
bot = telebot.TeleBot(args.token)
# Мапа чатов
chats = {}
# Класс состояний чата
class ChatState:
def __init__(self):
self.already_counting = False
self.timer = None
self.end_time = None
self.told_jokes = []
# массив состояний бота в разных чатах
alreadyCounting = {}
# массив таймеров по id чата
timers = {}
# массивы слов
went_array = ['пашол', 'пошел', 'пошёл', 'пашел', 'пошол', "пшел"]
hello_array = ['привет', 'здарова']
stop_array = ['стопэ', 'остановись']
how_many_array = ['скока', 'скоро']
name_array = [
'падла',
'дурак кожаный',
'псина',
'гандон',
'говнюк',
'дерьмо',
'жополиз',
'мудило',
'мудозвон',
'хрен',
'хуеплёт',
'хуй',
'питух',
'шаромыжка',
'бычара',
'пёс',
"уебан",
"пиздаглазое мудоебище",
"распиздяй колхозный",
"сиська журавля",
"перхоть подзалупная",
"сосунок",
"капитан потные яички",
"писька бублика",
"шлепок майонезный",
"тп",
"уебок лесной",
"ебанат ты натрия",
"мозгоклюй",
"шлюхотанк"
]
joke_array = ['анекдот', 'пошути', "аник", "анек"]
sticker_array = [
'CAACAgIAAxkBAAEC7whhSGL2N-Xr2p9pZ_j_ztCFvvh8qwACUAADi_RmLF1_8lSVNSnvIAQ', # крыса
'CAACAgIAAxkBAAEEEwxiJcpQ4nCP23spg02TgnOaILBWNQAC-gADVp29Ckfe-pdxdHEBIwQ', # уточка
'CAACAgQAAxkBAAEEExBiJcrad8N0a1PuwZc8sjDcl1WU6QACNQADrzysLbM4d2Ggm3jVIwQ', # gta
'CAACAgQAAxkBAAEEExJiJcsCoMRrRUZ6S1sblBH8nRLNNAACtAEAAqixsRzCa-P1-tA_aiME',
'CAACAgIAAxkBAAEEExZiJctgE1PAP480QJ3d74vdrGsz_wACsQAD6iroJNrZmizM_Z3rIwQ' # ну го
]
# массив анекдотов
with open('anecdotes.json') as jokes_file:
jokes = json.load(jokes_file)
# случайное обращение
def name():
return random.choice(name_array)
# случайный стикер
def sticker():
return random.choice(sticker_array)
# обратный отсчет
def count_back(chat_id):
chats[chat_id].timer = None
for i in reversed(range(10)):
bot.send_message(chat_id, i + 1)
time.sleep(1)
chats[chat_id].already_counting = False
bot.send_message(chat_id, 'ПОПИЗДОВАЛИ')
bot.send_sticker(chat_id, sticker())
# рассказать анекдот
def tell_a_joke(chat_id):
joke_idx = random.randint(0, len(jokes))
while joke_idx in chats[chat_id].told_jokes:
joke_idx += 1
if joke_idx >= len(jokes):
bot.send_message(chat_id, f"Не доёбывай меня, {name()}, пойдём лучше покурим.")
bot.send_sticker(chat_id, sticker())
return
bot.send_message(chat_id, jokes[joke_idx])
chats[chat_id].told_jokes.append(joke_idx)
# остановка таймера
def stop_counting(chat_id):
chats[chat_id].timer.cancel()
chats[chat_id].timer = None
chats[chat_id].already_counting = False
bot.send_message(chat_id, 'Стою, стою...')
# обработка команды создания таймера
def count_time(message):
chat_id = message.chat.id
if chats[chat_id].already_counting:
bot.send_message(chat_id, f'Не мешай, {name()}, я уже считаю, я один блядь')
return
if not message.text[:-1].isdigit():
bot.send_message(chat_id, f'Бота мне не клади, {name()}')
return
minutes = int(message.text[:-1])
if minutes < 1:
bot.send_message(chat_id, f'Меньше курить надо, {name()}, побольше время введи')
return
if minutes > 120:
bot.send_message(chat_id, f'Молодец, {name()}, ты покуришь через {round(minutes / 60, 1)} ч. примерно')
return
chats[chat_id].already_counting = True
bot.send_message(chat_id, f'Засёк {minutes} мин')
chats[chat_id].end_time = time.time() + (minutes * 60)
chats[chat_id].timer = Timer(minutes * 60, count_back, args=(chat_id,))
chats[chat_id].timer.start()
# обработка команды /start
@bot.message_handler(commands=['start'])
def start(message):
bot.send_message(message.chat.id, 'Здарова, заебал)\n\n'
'Я Саньтьяго, приехал с Кубы, чтобы дымить здесь.\n\n'
'Скажи мне через сколько курим\n'
'(10! - означает что курим через 10 минут)\n\n'
'Если чё не понял - тебе туда /help')
# обработка команды /help
@bot.message_handler(commands=['help'])
def start(message):
bot.send_message(message.chat.id, 'Бля, ну ты тупой или прикидываешься?\n'
'Я же сказал 10! - через 10 минут курим\n'
'Включи тыкву: 5! - это 5 минут\n'
'А я уже посчитаю, и напомню тебе)')
# обработка текстовых сообщений
@bot.message_handler(content_types=['text'])
def get_text_messages(message):
text = message.text.lower()
chat_id = message.chat.id
if chat_id not in chats:
chats[chat_id] = ChatState()
if text in hello_array:
bot.send_message(chat_id, f'Ну здарова, {name()}')
if text in went_array:
bot.send_message(chat_id, f'нахуй)0), {name()}')
if text in stop_array:
if chats[chat_id].already_counting and chats[chat_id].timer:
stop_counting(chat_id)
return
if chats[chat_id].already_counting and chats[chat_id].timer is None:
bot.send_message(chat_id, f'Чуть чуть потерпи, {name()}, заебал')
return
bot.send_message(chat_id, f'Ты ниче не засек, {name()}')
if text in how_many_array:
time_text = time.strftime('%M:%S', time.gmtime(chats[chat_id].end_time - time.time()))
bot.send_message(chat_id, f'Осталось {time_text}')
if text.endswith('!'):
count_time(message)
if text in joke_array:
tell_a_joke(chat_id)
bot.polling(none_stop=True, interval=0)