-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathold_bot.py
198 lines (158 loc) · 7.38 KB
/
old_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
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
#!/usr/bin/env python
# reast in peace, lastkatka in python
import json
import os
import sys
import time
import config # config.py in the bot's directory
import telepot
from telepot.loop import MessageLoop
token = config.token
lastkatka = config.lastkatka
lastvegan = config.lastvegan
tourgroup = config.tourgroup
allowed_chats = [lastkatka, lastvegan, tourgroup]
admins = config.admins
# for tournament
tournamentEnabled = False
link = ""
tournamentChannel = config.tournamentChannel
tournamentPassword = config.tournamentPassword
members = []
members_ids = []
# for vegan
veganStartCommands = config.veganStartCommands
joined = []
joinAllowed = False
def reply(chat_id, msg):
if 'reply_to_message' not in msg:
bot.sendMessage(chat_id, "Этой командой нужно ответить на сообщение!", reply_to_message_id=msg['message_id'])
return False
else:
return True
def proccessTournament(chat_id, msg, txt): # managing tournament
global tournamentEnabled
global members
global members_ids
if "/summon" == txt[:7]:
pinglist = []
for i in members:
pinglist.append("@" + i)
bot.sendMessage(lastvegan, ", ".join(
pinglist) + ", напишите мне в лс команду /tournament для получения ссылки на группу с турниром")
elif "/tournament" == txt[:11]:
if msg['chat']['type'] == "private":
if msg['from']['username'] in members:
members_ids.append(msg['from']['id']) # collect user's ids (will be used in /kickmembers command)
bot.sendMessage(chat_id, "Заходи сюда -> " + link)
else:
bot.sendMessage(chat_id, "Вас пока еще не звали")
else:
bot.sendMessage(chat_id, "Команда работает только у бота в лс", reply_to_message_id=msg['message_id'])
elif "/kickmembers" == txt[:12] and msg['from']['id'] in admins:
bot.sendMessage(tourgroup, "Раунд завершен, пока!")
bot.sendMessage(lastvegan,
"<b>Раунд завершен. Болельщики, посетите " + tournamentChannel + ", чтобы узнать результат!</b>",
parse_mode="HTML")
for user_id in members_ids:
bot.kickChatMember(tourgroup, user_id)
bot.unbanChatMember(tourgroup, user_id)
resetTournament()
elif "/rt" == txt[:3] and msg['from']['id'] in admins:
bot.sendMessage(lastvegan, "<b>Турнир отменен из-за непредвиденных обстоятельств!</b>", parse_mode="HTML")
def proccessVegan(msg, txt): # counting players
global joined
global joinAllowed
if txt in veganStartCommands:
if not joinAllowed:
joinAllowed = True
joined.clear()
if joinAllowed:
if "/join@veganwarsbot" == txt[:18]:
if msg['from']['username'] not in joined:
joined.append(msg['from']['username'])
bot.sendMessage(lastvegan, "Джойнулось " + str(len(joined)) + " игроков")
elif "/fight@veganwarsbot" == txt[:19]:
if len(joined) > 1:
resetVegan()
else:
bot.sendMessage(lastvegan, "Веганы, джоин, мясоеды наступают!!!")
elif "/flee@veganwarsbot" == txt[:18]:
if msg['from']['username'] in joined:
joined.remove(msg['from']['username'])
bot.sendMessage(lastvegan, "Осталось " + str(len(joined)) + " игроков")
elif "/reset" == txt[:6]:
bot.sendMessage(lastvegan, "Счетчик обнулен!")
resetVegan()
def resetVegan():
global joinAllowed
joinAllowed = False
joined.clear()
def resetTournament():
members.clear()
members_ids.clear()
tournamentEnabled = False
def handle(msg):
global tournamentEnabled
global members
global link
content_type, chat_type, chat_id = telepot.glance(msg)
if chat_type != "private" and chat_id not in allowed_chats: # leave from foreign groups
bot.sendMessage(chat_id, "Какая то левая конфа, ну ее нафиг")
bot.leaveChat(chat_id)
txt = ""
if 'text' in msg:
txt = txt + msg['text']
if txt != "" and chat_type != "channel":
print("Msg: " + msg['from']['first_name'] + ": " + txt)
if "/pinthis" == txt[:8]:
if reply(chat_id, msg):
bot.pinChatMessage(chat_id, msg['reply_to_message']['message_id'], disable_notification=True)
bot.deleteMessage(telepot.message_identifier(msg))
elif "/unpin" == txt[:6]:
bot.unpinChatMessage(chat_id)
bot.deleteMessage(telepot.message_identifier(msg))
elif "/nahuy" == txt[:6] and chat_type != "private":
if reply(chat_id, msg):
reply_id = msg['reply_to_message']['message_id']
if msg['reply_to_message']['from']['username'] == "Senderman":
bot.sendMessage(chat_id, "Юльку нахуй слать низзя!", reply_to_message_id=msg['message_id'])
elif msg['reply_to_message']['from']['username'] == "gtfo_uvao_bot":
bot.sendMessage(chat_id, "Бота нахуй слать низзя!", reply_to_message_id=msg['message_id'])
else:
bot.sendMessage(chat_id, "Вы были посланы нахуй юзером " + msg['from']['first_name'],
reply_to_message_id=reply_id)
bot.deleteMessage(telepot.message_identifier(msg))
elif "/thx" == txt[:4] and chat_type != "private":
if reply(chat_id, msg):
reply_id = msg['reply_to_message']['message_id']
bot.sendMessage(chat_id, "Вы были поглажены по голове юзером " + msg['from']['first_name'],
reply_to_message_id=reply_id)
bot.deleteMessage(telepot.message_identifier(msg))
elif "/setup" == txt[:6]:
params = txt.strip().replace("@", "").split(" ")[1:]
if len(params) != 4:
bot.sendMessage(chat_id, "Неверное количество аргументов!", reply_to_message_id=msg['message_id'])
elif params[3] != tournamentPassword:
bot.sendMessage(chat_id, "Неверный пароль!")
else:
members = params[0:2]
link = params[2]
tournamentEnabled = True
resetVegan()
bot.sendMessage(lastvegan, "<b>Турнир активирован!</b>\n\n<b>Участники:</b> " + ", ".join(
members) + "\nОтправьте /summon чтобы позвать участников на турнир!", parse_mode="HTML")
elif tournamentEnabled:
proccessTournament(chat_id, msg, txt)
elif chat_id == lastvegan:
proccessVegan(msg, txt)
bot = telepot.Bot(token)
# skip old messages
updates = bot.getUpdates()
if updates:
last_update_id = updates[-1]['update_id']
bot.getUpdates(offset=last_update_id+1)
MessageLoop(bot, handle).run_as_thread()
print('Listening ...')
while 1:
time.sleep(10)