-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstart.py
313 lines (296 loc) · 14.8 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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
import telebot
import random
import json
from Utils.Helpers import Helpers
import sqlite3
# создаем бота
admin=[1156896214,5690225560]
#5690225560 - Lekma
#1156896214 - Я макс
bot = telebot.TeleBot('5772083305:AAHL49TU8zO2DDSRrJf9aKXSj1QoQUEs_1o')
# Функция для получения списка всех акций из файла offers.json
def get_offers():
# Читаем данные из файла offers.json
with open("Logic/offers.json", "r",encoding='utf-8') as f:
data = json.load(f)
# Генерируем текстовый список всех акци
offer_list = "Список акций:\n"
for offer_id, offer_data in data.items():
vault=offer_data['ShopType']
daily=offer_data['ShopDisplay']
current=""
types=""
if vault==1:current="Золото"
elif vault==0:current="Кристаллы"
if daily==1:types="Ежедневная"
elif daily==0:types="Обычная"
offer_list += f"\nАкция #{offer_id}\n"
offer_list += f"Название: {offer_data['OfferTitle']}\n"
offer_list += f"Тип: {types}\n"
offer_list += f"Боец: {offer_data['BrawlerID'][0]}\n"
offer_list += f"Скин: {offer_data['SkinID'][0]}\n"
offer_list += f"Валюта: {current}\n"
offer_list += f"Стоимость: {offer_data['Cost']}\n"
offer_list += f"Множитель: {offer_data['Multiplier'][0]}\n"
# Возвращаем текстовый список всех акций
return offer_list
# Обработчик команды /list
@bot.message_handler(commands=['list'])
def handle_list_offers(message):
# Получаем список всех акций из файла offers.json
offer_list = get_offers()
# Отправляем пользователю список всех акций
bot.send_message(chat_id=message.chat.id, text=offer_list)
@bot.message_handler(commands=['new_offer'])
def add_offer(message):
user_id = message.from_user.id
if user_id in admin:
if len(message.text.split()) < 2:
bot.reply_to(message, 'Используйте команду /new_offer с аргументами в формате: /new_offer <ID> <OfferTitle> <Cost> <Multiplier> <BrawlerID> <SkinID> <OfferBGR> <ShopType> <ShopDisplay>')
return
offer_data = message.text.split()
new_offer = {
'ID': [int(offer_data[1]), 0, 0],
'OfferTitle': offer_data[2],
'Cost': int(offer_data[3]),
'OldCost': 0,
'Multiplier': [int(offer_data[4]), 0, 0],
'BrawlerID': [int(offer_data[5]), 0, 0],
'SkinID': [int(offer_data[6]), 0, 0],
'WhoBuyed': [],
'Timer': 86400,
'OfferBGR': offer_data[7],
'ShopType': int(offer_data[8]),
'ShopDisplay': int(offer_data[9])
}
with open('Logic/offers.json', 'r',encoding='utf-8') as f:
offers = json.load(f)
offers[str(len(offers))] = new_offer
with open('Logic/offers.json', 'w',encoding='utf-8') as f:
json.dump(offers, f, indent=4)
bot.reply_to(message, 'Новая акция добавлена!')
else:
bot.reply_to(message, "Вы не являетесь администратором!")
@bot.message_handler(commands=['start'])
def send_welcome(message):
user_id = message.from_user.id
if user_id in admin:
bot.reply_to(message, "/list - Посмотреть список акций.\n/new_offer - создает новую акцию.\n/remove_offer - Удалить акцию.\n/theme - Изменить всем фон\n/new_code - Добавить новый код Автора.\n/del_code - Удалить код Автора.\n/code_list - Список кодов Автора.\n/auto_shop - Обновить ежедневынй магазин.\n/add_vip - Выдать вип статус.\n/del_vip - Забрать вип статус.\n/add_gems - Выдать гемов игроку.\n/ban - Выдать бан игроку")
else:
bot.reply_to(message, "Вы не являетесь администратором!")
@bot.message_handler(commands=['remove_offer'])
def remove_offer(message):
user_id = message.from_user.id
if user_id in admin:
if len(message.text.split()) != 2:
bot.reply_to(message, 'Используйте команду /remove_offer с аргументом в формате: /remove_offer <ID>')
return
offer_id = message.text.split()[1]
with open('Logic/offers.json', 'r', encoding='utf-8') as f:
offers = json.load(f)
if offer_id not in offers:
bot.reply_to(message, f'Акция с ID {offer_id} не найдена')
return
offers.pop(offer_id)
with open('Logic/offers.json', 'w', encoding='utf-8') as f:
json.dump(offers, f)
bot.reply_to(message, f'Акция с ID {offer_id} удалена')
else:
bot.reply_to(message, "Вы не являетесь администратором!")
# Определяем функцию-обработчик для команды /theme
@bot.message_handler(commands=['theme'])
def theme(message):
user_id = message.from_user.id
if user_id in admin:
if len(message.text.split()) < 2:
bot.reply_to(message, "Выбери ID темы\n0 - Обычная\n1 - Новый год (Снег)\n2 - Красный новый год\n3 - От клеш рояля\n5 - Желтые панды\n6 - Фиолетовый булл\n7 - Роботы Зелёный фон\n8 - Фиолетовый фон\n9 - Пиратский фон\n11 - Футбольный фон\nИспользовать команду /theme ID")
else:
user_id = message.from_user.id
theme_id = message.text.split()[1]
conn = sqlite3.connect("database/Player/plr.db")
c = conn.cursor()
c.execute(f"UPDATE plrs SET theme={theme_id}")
conn.commit()
c.execute("SELECT * FROM plrs")
conn.close()
bot.send_message(chat_id=message.chat.id, text=f"Айди всех записей был изменён на {theme_id}")
else:
bot.reply_to(message, "Вы не являетесь администратором!")
#коды автора
@bot.message_handler(commands=['new_code'])
def new_code(message):
user_id = message.from_user.id
if user_id in admin:
if len(message.text.split()) < 2:
bot.reply_to(message, "Правильное использование /new_code Название Кода(На англ)")
else:
code = message.text.split()[1]
with open("config.json", "r", encoding='utf-8') as f:
config = json.load(f)
if code not in config["CCC"]:
config["CCC"].append(code)
with open("config.json", "w", encoding='utf-8') as f:
json.dump(config, f, indent=4)
bot.send_message(chat_id=message.chat.id, text=f"Новый код {code}, Был добавлен!")
else:
bot.send_message(chat_id=message.chat.id, text=f"Код {code} уже существует!")
else:
bot.reply_to(message, "Вы не являетесь администратором!")
@bot.message_handler(commands=['code_list'])
def code_list(message):
with open('config.json', 'r') as f:
data = json.load(f)
code_list = '\n'.join(data["CCC"])
bot.send_message(chat_id=message.chat.id, text=f"Список кодов: \n{code_list}")
@bot.message_handler(commands=['del_code'])
def del_code(message):
user_id = message.from_user.id
if user_id in admin:
if len(message.text.split()) < 2:
bot.reply_to(message, "Правильное использование /del_code Название Кода")
else:
code = message.text.split()[1]
with open("config.json", "r", encoding='utf-8') as f:
config = json.load(f)
if code in config["CCC"]:
config["CCC"].remove(code)
with open("config.json", "w", encoding='utf-8') as f:
json.dump(config, f, indent=4)
bot.send_message(chat_id=message.chat.id, text=f"Код {code}, Был удалён!")
else:
bot.send_message(chat_id=message.chat.id, text=f"Код {code} не найден!")
else:
bot.reply_to(message, "Вы не являетесь администратором!")
#конец кодов
#Вип Старт
@bot.message_handler(commands=['add_vip'])
def add_vip(message):
user_id = message.from_user.id
if user_id in admin:
if len(message.text.split()) < 2:
bot.reply_to(message, "Правильное использование /add_vip ID(Можно узнать в профиле профиле при поставке цветного ника)")
else:
vip_id = int(message.text.split()[1])
with open("config.json", "r", encoding='utf-8') as f:
config = json.load(f)
if vip_id not in config["vips"]:
config["vips"].append(vip_id)
with open("config.json", "w", encoding='utf-8') as f:
json.dump(config, f, indent=4)
bot.send_message(chat_id=message.chat.id, text=f"Вип статус был выдан игроку с ID {vip_id}")
else:
bot.send_message(chat_id=message.chat.id, text=f"Вип статус уже есть у ID {vip_id}")
else:
bot.reply_to(message, "Вы не являетесь администратором!")
@bot.message_handler(commands=['del_vip'])
def del_vip(message):
user_id = message.from_user.id
if user_id in admin:
if len(message.text.split()) < 2:
bot.reply_to(message, "Правильное использование /del_vip ID(Можно узнать в профиле профиле при поставке цветного ника)")
else:
code = int(message.text.split()[1])
with open("config.json", "r", encoding='utf-8') as f:
config = json.load(f)
if code in config["vips"]:
config["vips"].remove(code)
with open("config.json", "w", encoding='utf-8') as f:
json.dump(config, f, indent=4)
bot.send_message(chat_id=message.chat.id, text=f"Вип статус был удален у игрока с ID {code}")
else:
bot.send_message(chat_id=message.chat.id, text=f"Вип статус не найден у игрока с ID {code}")
else:
bot.reply_to(message, "Вы не являетесь администратором!")
#Конец випов
@bot.message_handler(commands=['auto_shop'])
def auto_shop(message):
user_id = message.from_user.id
if user_id in admin:
with open('Logic/offers.json', 'r', encoding='utf-8') as f:
data = json.load(f)
for i in range(12): # изменяем первые 5 записей по ID
if i <= 5:
new_offer = {
'ID': [8, 0, 0],
'OfferTitle': "daily",
'Cost': random.randint(10, 228),
'OldCost': 0,
'Multiplier': [random.randint(1, 100), 0, 0],
'BrawlerID': [random.randint(1, 32), 0, 0],
'SkinID': [0, 0, 0],
'WhoBuyed': [],
'Timer': 86400,
'OfferBGR': "offer_gems",
'ShopType': 1,
'ShopDisplay': 1
}
data[i] = new_offer
elif i > 5:
with open('config.json', 'r', encoding='utf-8') as f:
settings = json.load(f)
skins = settings['Skins']
random_skin = random.choice(skins)
skins.remove(random_skin)
settings['Skins'] = skins
with open('config.json', 'w', encoding='utf-8') as f:
json.dump(settings, f, indent=4, ensure_ascii=False)
new_offer = {
'ID': [4, 0, 0],
'OfferTitle': "DAILY SKIN",
'Cost': random.randint(10, 228),
'OldCost': 0,
'Multiplier': [0, 0, 0],
'BrawlerID': [0, 0, 0],
'SkinID': [random_skin, 0, 0],
'WhoBuyed': [],
'Timer': 86400,
'OfferBGR': "offer_gems",
'ShopType': 0,
'ShopDisplay': 0
}
data[i] = new_offer
with open('Logic/offers.json', 'w', encoding='utf-8') as f:
json.dump(data, f, indent=4, ensure_ascii=False)
bot.reply_to(message, 'Акции успешно обновлены!')
else:
bot.reply_to(message, "Вы не являетесь администратором!")
# add_gems
@bot.message_handler(commands=['add_gems'])
def add_gems(message):
user_id = message.from_user.id
if user_id in admin:
if len(message.text.split()) < 2:
bot.reply_to(message, "Правильное использование /add_gems ID AMMOUNT")
else:
user_id = message.from_user.id
id = message.text.split()[1]
ammount = message.text.split()[2]
conn = sqlite3.connect("database/Player/plr.db")
cursor = conn.cursor()
cursor.execute("UPDATE plrs SET gems = ? WHERE lowID = ?", (ammount, id))
conn.commit()
conn.close()
bot.send_message(chat_id=message.chat.id, text=f"Игроку с айди {id} Выдали {ammount} Гемов")
else:
bot.reply_to(message, "Вы не являетесь администратором!")
@bot.message_handler(commands=['ban'])
def ban(message):
user_id = message.from_user.id
if user_id in admin:
if len(message.text.split()) < 2:
bot.reply_to(message, "Правильное использование /ban ID")
else:
vip_id = int(message.text.split()[1])
with open("config.json", "r", encoding='utf-8') as f:
config = json.load(f)
if vip_id not in config["vips"]:
config["vips"].append(vip_id)
with open("config.json", "w", encoding='utf-8') as f:
json.dump(config, f, indent=4)
bot.send_message(chat_id=message.chat.id, text=f"Бан был выдан игроку {vip_id}")
else:
bot.send_message(chat_id=message.chat.id, text=f"Бан уже есть у игрока {vip_id}")
else:
bot.reply_to(message, "Вы не являетесь администратором!")
# Запускаем бота
bot.polling()