This repository was archived by the owner on Aug 16, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
942 lines (917 loc) · 45.6 KB
/
Copy pathmain.py
File metadata and controls
942 lines (917 loc) · 45.6 KB
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
# Очередная попытка переписать Спайка на питон :)
# 25.09.2021 12:10
from pyrogram import Client, filters, types
from pyrogram.types import ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineKeyboardMarkup, InlineKeyboardButton, Message
import sqlite3
import random
import time
# Антифлуд
antiflood_list1 = []
antiflood_list2 = []
antiflood_list3 = []
def antiflood(msg, limit):
inlistb = 0
inlist = 0
i = 0
while i < len(antiflood_list1):
if (antiflood_list1[i] == msg.chat.id):
inlist = i
inlistb = 1
i += 1
#print("inlistb: " + str(inlistb))
#print("inlist: " + str(inlist))
#print("time: " + str(time.time()))
#print("rtime: " + str(round(time.time())))
if (inlistb == 0):
antiflood_list1.append(msg.chat.id)
antiflood_list2.append(100)
antiflood_list3.append(0)
if ((time.time() - antiflood_list2[inlist]) > limit):
antiflood_list2.pop(inlist)
antiflood_list2.insert(inlist, round(time.time()))
antiflood_list3.pop(inlist)
antiflood_list3.insert(inlist, 0)
return(1)
else:
antiflood_list2.pop(inlist)
antiflood_list2.insert(inlist, round(time.time()))
a = antiflood_list3[inlist]
antiflood_list3.pop(inlist)
antiflood_list3.insert(inlist, a + 1)
if (a == 10):
bot.send_message(msg.chat.id, "Хватит, пожалуйста, я устал...")
return(0)
# Логика #
class game:
def play_cmd(msg):
database.execute("SELECT registration FROM users WHERE tg_id = ?", (str(msg.chat.id),))
result = database.fetchall()
if (result[0][0] == None):
bot.send_message(msg.chat.id, "Выбери событие:", reply_markup=ReplyKeyboardMarkup([["Захват кристаллов",], ["В меню",],], resize_keyboard=True))
else:
bot.send_message(msg.chat.id, "Выбери событие:", reply_markup=ReplyKeyboardMarkup([["Захват кристаллов",], ["Онлайн захват кристаллов",], ["Столкновение",], ["В меню",], ], resize_keyboard=True))
def menu_cmd(msg):
game.update_tokens(msg)
database.execute("SELECT nickname, selected_brawler, trophies, gems, coins, tokens, brawlpass_lvl, rtokens FROM users WHERE tg_id = ?", (str(msg.chat.id),))
result = database.fetchall()
database.execute("SELECT name FROM brawlers WHERE id = ?", (str(result[0][1]),))
selected_brawler = database.fetchall()
bot.send_message(msg.chat.id, f"<b>Спайк - Игровой Бот (Beta)</b>\nНикнейм: {result[0][0]}\nБравлер: {selected_brawler[0][0]}\nТрофеи: {result[0][2]}\nМонеты: {result[0][4]}\nКристаллы: {result[0][3]}\nБравл пасс: {result[0][6]} уровень\nТокены: {result[0][5]}\nОсталось токенов: {result[0][7]}", reply_markup=ReplyKeyboardMarkup([["Играть", "Бравлеры"], ["Бравл пасс"]], resize_keyboard=True))
def playgame_cmd(msg, game):
if (game == 1): # GemGrab
database.execute("UPDATE users SET now_action = 1 WHERE tg_id = ?", (str(msg.chat.id),))
db_connect.commit()
bot.send_photo(msg.chat.id, "AgACAgIAAxkBAAIBBWFQKH_mxYk9-BPQrJChifGy_vlcAAJ3szEbiBOASjQIatWJQZjaaXsurS4AAwEAAwIAA3kAAx6VAAIeBA", "Бой в захвате кристаллов!")
database.execute("SELECT selected_brawler FROM users WHERE tg_id = ?", (str(msg.chat.id),))
result = database.fetchall()
database.execute("SELECT chance FROM brawlers WHERE id = ?", (str(result[0][0]),))
result = database.fetchall()
database.execute("SELECT registration FROM users WHERE tg_id = ?", (str(msg.chat.id),))
result3 = database.fetchall()
a = random.randint(1, 100)
database.execute("SELECT trophies, tokens, rtokens FROM users WHERE tg_id = ?", (str(msg.chat.id),))
result2 = database.fetchall()
if (result3[0][0] == None):
bot.send_message(msg.chat.id, "Победа! +8 трофеев.", reply_markup=ReplyKeyboardMarkup([["Играть снова",]], resize_keyboard=True))
database.execute("UPDATE users SET trophies = ? WHERE tg_id = ?", (result2[0][0] + 8, str(msg.chat.id),))
bot.send_message(msg.chat.id, "Хороший бой, не правда ли? Нажми на <b>Играть снова</b>, что бы сыграть еще!")
database.execute("UPDATE users SET registration = 1 WHERE tg_id = ?", (str(msg.chat.id),))
db_connect.commit()
elif (result3[0][0] == 1):
bot.send_message(msg.chat.id, "Поражение! -3 трофея.", reply_markup=ReplyKeyboardMarkup([["В меню",]], resize_keyboard=True))
database.execute("UPDATE users SET trophies = ? WHERE tg_id = ?", (result2[0][0] - 3, str(msg.chat.id),))
#bot.send_message(msg.chat.id, "Хороший бой, не правда ли? Нажми на <b>Играть снова</b>, что бы сыграть еще!")
database.execute("UPDATE users SET registration = 8 WHERE tg_id = ?", (str(msg.chat.id),))
db_connect.commit()
else:
if (a <= result[0][0]):
bot.send_message(msg.chat.id, "Победа! +8 трофеев.", reply_markup=ReplyKeyboardMarkup([["Играть снова", "В меню"],], resize_keyboard=True))
database.execute("UPDATE users SET trophies = ? WHERE tg_id = ?", (result2[0][0] + 8, str(msg.chat.id),))
if (result2[0][2] >= 20):
database.execute("UPDATE users SET tokens = ? WHERE tg_id = ?", (result2[0][1] + 20, str(msg.chat.id),))
database.execute("UPDATE users SET rtokens = ? WHERE tg_id = ?", (result2[0][2] - 20, str(msg.chat.id),))
else:
database.execute("UPDATE users SET tokens = ? WHERE tg_id = ?", (result2[0][1] + result2[0][2], str(msg.chat.id),))
database.execute("UPDATE users SET rtokens = 0 WHERE tg_id = ?", (str(msg.chat.id),))
db_connect.commit()
else:
if (result2[0][0] - 3 < 0):
bot.send_message(msg.chat.id, "Поражение! 0 трофеев.", reply_markup=ReplyKeyboardMarkup([["Играть снова", "В меню"],], resize_keyboard=True))
else:
bot.send_message(msg.chat.id, "Поражение! -3 трофея.", reply_markup=ReplyKeyboardMarkup([["Играть снова", "В меню"],], resize_keyboard=True))
database.execute("UPDATE users SET trophies = ? WHERE tg_id = ?", (result2[0][0] -3, str(msg.chat.id),))
if (result2[0][2] >= 10):
database.execute("UPDATE users SET tokens = ? WHERE tg_id = ?", (result2[0][1] + 10, str(msg.chat.id),))
database.execute("UPDATE users SET rtokens = ? WHERE tg_id = ?", (result2[0][2] - 10, str(msg.chat.id),))
else:
database.execute("UPDATE users SET tokens = ? WHERE tg_id = ?", (result2[0][1] + result2[0][2], str(msg.chat.id),))
database.execute("UPDATE users SET rtokens = 0 WHERE tg_id = ?", (str(msg.chat.id),))
db_connect.commit()
if (game == 3): # GemGrab Online
database.execute("UPDATE users SET now_action = 3 WHERE tg_id = ?", (str(msg.chat.id),))
db_connect.commit()
database.execute("SELECT * FROM online")
online_stat = database.fetchall()
if (online_stat == []): # Лобби
database.execute("SELECT selected_brawler, nickname FROM users WHERE tg_id = ?", (str(msg.chat.id),))
brawler = database.fetchall()
database.execute("INSERT INTO online (tg_id, name, brawler_id) VALUES (?, ?, ?)", (str(msg.chat.id), str(brawler[0][1]), str(brawler[0][0]),))
db_connect.commit();
bot.send_message(msg.chat.id, "Поиск игроков...", reply_markup=ReplyKeyboardMarkup([["В меню"],], resize_keyboard=True))
else:
bot.send_message(msg.chat.id, "Поиск игроков...")
database.execute("SELECT nickname, trophies, selected_brawler FROM users WHERE tg_id = ?", (str(msg.chat.id),))
fplayer_profile = database.fetchall()
database.execute("SELECT name FROM brawlers WHERE id = ?", (str(fplayer_profile[0][2]),))
brawler = database.fetchall()
bot.send_message(online_stat[0][0], "Игрок найден!\nНикнейм: " + fplayer_profile[0][0] + "\nБравлер: " + brawler[0][0] + "\nТрофеи: " + str(fplayer_profile[0][1]))
database.execute("SELECT nickname, trophies, selected_brawler FROM users WHERE tg_id = ?", (online_stat[0][0],))
splayer_profile = database.fetchall()
database.execute("SELECT name FROM brawlers WHERE id = ?", (str(splayer_profile[0][2]),))
brawler = database.fetchall()
bot.send_message(msg.chat.id, "Игрок найден!\nНикнейм: " + splayer_profile[0][0] + "\nБравлер: " + brawler[0][0] + "\nТрофеи: " + str(splayer_profile[0][1]))
splayer_id = online_stat[0][0]
bot.send_photo(msg.chat.id, "AgACAgIAAxkBAAIBBWFQKH_mxYk9-BPQrJChifGy_vlcAAJ3szEbiBOASjQIatWJQZjaaXsurS4AAwEAAwIAA3kAAx6VAAIeBA", "Онлайн бой в захвате кристаллов!")
bot.send_photo(splayer_id, "AgACAgIAAxkBAAIBBWFQKH_mxYk9-BPQrJChifGy_vlcAAJ3szEbiBOASjQIatWJQZjaaXsurS4AAwEAAwIAA3kAAx6VAAIeBA", "Онлайн бой в захвате кристаллов!")
database.execute("SELECT selected_brawler FROM users WHERE tg_id = ?", (str(msg.chat.id),))
fplayer_chance = database.fetchall()
database.execute("SELECT chance FROM brawlers WHERE id = ?", (str(fplayer_chance[0][0]),))
fplayer_chance = database.fetchall()
database.execute("SELECT selected_brawler FROM users WHERE tg_id = ?", (str(msg.chat.id),))
splayer_chance = database.fetchall()
database.execute("SELECT chance FROM brawlers WHERE id = ?", (str(splayer_chance[0][0]),))
splayer_chance = database.fetchall()
all_chance = (50 - (fplayer_chance[0][0] - splayer_chance[0][0]))
a = random.randint(1, 100)
if (a <= all_chance):
database.execute("SELECT trophies, tokens, rtokens FROM users WHERE tg_id = ?", (str(msg.chat.id),))
result2 = database.fetchall()
bot.send_message(msg.chat.id, "Победа! +8 трофеев.", reply_markup=ReplyKeyboardMarkup([["Играть снова", "В меню"],], resize_keyboard=True))
database.execute("UPDATE users SET trophies = ? WHERE tg_id = ?", (result2[0][0] + 8, str(msg.chat.id),))
if (result2[0][2] >= 20):
database.execute("UPDATE users SET tokens = ? WHERE tg_id = ?", (result2[0][1] + 20, str(msg.chat.id),))
database.execute("UPDATE users SET rtokens = ? WHERE tg_id = ?", (result2[0][2] - 20, str(msg.chat.id),))
else:
database.execute("UPDATE users SET tokens = ? WHERE tg_id = ?", (result2[0][1] + result2[0][2], str(msg.chat.id),))
database.execute("UPDATE users SET rtokens = 0 WHERE tg_id = ?", (str(msg.chat.id),))
db_connect.commit()
# second
database.execute("SELECT trophies, tokens, rtokens FROM users WHERE tg_id = ?", (splayer_id,))
result2 = database.fetchall()
if (result2[0][0] - 3 < 0):
bot.send_message(splayer_id, "Поражение! 0 трофеев.", reply_markup=ReplyKeyboardMarkup([["Играть снова", "В меню"],], resize_keyboard=True))
else:
bot.send_message(splayer_id, "Поражение! -3 трофея.", reply_markup=ReplyKeyboardMarkup([["Играть снова", "В меню"],], resize_keyboard=True))
database.execute("UPDATE users SET trophies = ? WHERE tg_id = ?", (result2[0][0] -3, splayer_id,))
if (result2[0][2] >= 10):
database.execute("UPDATE users SET tokens = ? WHERE tg_id = ?", (result2[0][1] + 10, str(splayer_id),))
database.execute("UPDATE users SET rtokens = ? WHERE tg_id = ?", (result2[0][2] - 10, str(splayer_id),))
else:
database.execute("UPDATE users SET tokens = ? WHERE tg_id = ?", (result2[0][1] + result2[0][2], str(splayer_id),))
database.execute("UPDATE users SET rtokens = 0 WHERE tg_id = ?", (str(splayer_id),))
db_connect.commit()
else:
database.execute("SELECT trophies, tokens, rtokens FROM users WHERE tg_id = ?", (str(msg.chat.id),))
result2 = database.fetchall()
if (result2[0][0] - 3 < 0):
bot.send_message(msg.chat.id, "Поражение! 0 трофеев.", reply_markup=ReplyKeyboardMarkup([["Играть снова", "В меню"],], resize_keyboard=True))
else:
bot.send_message(msg.chat.id, "Поражение! -3 трофея.", reply_markup=ReplyKeyboardMarkup([["Играть снова", "В меню"],], resize_keyboard=True))
database.execute("UPDATE users SET trophies = ? WHERE tg_id = ?", (result2[0][0] -3, str(msg.chat.id),))
if (result2[0][2] >= 10):
database.execute("UPDATE users SET tokens = ? WHERE tg_id = ?", (result2[0][1] + 10, str(msg.chat.id),))
database.execute("UPDATE users SET rtokens = ? WHERE tg_id = ?", (result2[0][2] - 10, str(msg.chat.id),))
else:
database.execute("UPDATE users SET tokens = ? WHERE tg_id = ?", (result2[0][1] + result2[0][2], str(msg.chat.id),))
database.execute("UPDATE users SET rtokens = 0 WHERE tg_id = ?", (str(msg.chat.id),))
db_connect.commit()
# second
database.execute("SELECT trophies, tokens, rtokens FROM users WHERE tg_id = ?", (splayer_id,))
result2 = database.fetchall()
bot.send_message(splayer_id, "Победа! +8 трофеев.", reply_markup=ReplyKeyboardMarkup([["Играть снова", "В меню"],], resize_keyboard=True))
database.execute("UPDATE users SET trophies = ? WHERE tg_id = ?", (result2[0][0] + 8, splayer_id,))
if (result2[0][2] >= 20):
database.execute("UPDATE users SET tokens = ? WHERE tg_id = ?", (result2[0][1] + 20, str(splayer_id),))
database.execute("UPDATE users SET rtokens = ? WHERE tg_id = ?", (result2[0][2] - 20, str(splayer_id),))
else:
database.execute("UPDATE users SET tokens = ? WHERE tg_id = ?", (result2[0][1] + result2[0][2], str(splayer_id),))
database.execute("UPDATE users SET rtokens = 0 WHERE tg_id = ?", (str(splayer_id),))
db_connect.commit()
database.execute("DELETE FROM online")
db_connect.commit()
elif (game == 2): # Showdown
database.execute("UPDATE users SET now_action = 2 WHERE tg_id = ?", (str(msg.chat.id),))
db_connect.commit()
bot.send_photo(msg.chat.id, "AgACAgIAAxkBAAIBCWFQKNaF0AABBJPVTo0iNp0_aNA2NgACebMxG4gTgEpAtRlSXUYC3PVb0KkuAAMBAAMCAAN5AAMKmAQAAR4E", "Бой в столкновении!")
shd = ["1 место! +10 трофеев.", "2 место! +8 трофеев.", "3 место! +6 трофеев.", "4 место! +5 трофеев.", "5 место! +3 трофея.", "6 место! +1 трофей.", "7 место! 0 трофеев.", "8 место! -1 трофей.", "9 место! -2 трофея.", "10 место! -3 трофей."]
shdt = [10, 8, 6, 5, 3, 1, 0, -1, -2, -3]
shdtk = [34, 28, 22, 16, 10, 8, 6, 4, 2, 0]
shdch = [4, 9, 15, 22, 30, 39, 49, 60, 72, 85]
a = random.randint(0, 9)
#if (a > shdch)
database.execute("SELECT trophies, tokens, rtokens FROM users WHERE tg_id = ?", (str(msg.chat.id),))
result2 = database.fetchall()
bot.send_message(msg.chat.id, shd[a], reply_markup=ReplyKeyboardMarkup([["Играть снова", "В меню"],], resize_keyboard=True))
database.execute("UPDATE users SET trophies = ? WHERE tg_id = ?", (result2[0][0] + shdt[a], str(msg.chat.id),))
if (result2[0][2] >= shdtk[a]):
database.execute("UPDATE users SET tokens = ? WHERE tg_id = ?", (result2[0][1] + shdtk[a], str(msg.chat.id),))
database.execute("UPDATE users SET rtokens = ? WHERE tg_id = ?", (result2[0][2] - shdtk[a], str(msg.chat.id),))
else:
database.execute("UPDATE users SET tokens = ? WHERE tg_id = ?", (result2[0][1] + result2[0][2], str(msg.chat.id),))
database.execute("UPDATE users SET rtokens = 0 WHERE tg_id = ?", (str(msg.chat.id),))
db_connect.commit()
# Бравлеры #
def brawlers_cmd(msg, b):
if (b == 0):
bot.send_message(msg.chat.id, "Выбери редкость:", reply_markup=ReplyKeyboardMarkup([["Обычные", "Редкие"], ["Сверхредкие", "Эпические"], ["Мифические", "Легендарные"], ["Хроматические", "В меню"],], resize_keyboard=True))
else:
database.execute("SELECT name, id FROM brawlers WHERE rare_id = ?", (str(b),))
result = database.fetchall()
keys = []
keys2 = []
k = 1
i = 0
database.execute("SELECT brawler_id FROM have_brawlers WHERE tg_id = ? AND rare_id = ?", (str(msg.chat.id), str(b),))
hb = database.fetchall()
while i < len(result):
if ((int(result[i][1]) == 1) and b == 1):
haveb = 1
else:
haveb = 0
a = 0
while a < len(hb):
if (int(result[i][1]) == int(hb[a][0])):
haveb = 1
a += 1
if (haveb == 1):
keys2.append(result[i][0])
else:
keys2.append("🔒 " + result[i][0])
if (k == 2):
keys.append(keys2)
keys2 = []
k = 1
else:
k = 2
i += 1
if (k == 2):
keys2.append("В меню")
keys.append(keys2)
keys2 = []
else:
keys.append(["В меню"])
bot.send_message(msg.chat.id, "Выбери бравлера:", reply_markup=ReplyKeyboardMarkup(keys, resize_keyboard=True))
def select_brawler_cmd(msg, b):
if (b == 1):
haveb = 1
else:
database.execute("SELECT brawler_id FROM have_brawlers WHERE brawler_id = ? AND tg_id = ?", (str(b), str(msg.chat.id),))
hb = database.fetchall()
haveb = 0
a = 0
while a < len(hb):
if (int(hb[a][0]) == int(b)):
haveb = 1
a += 1
if (haveb == 1):
database.execute("UPDATE users SET selected_brawler = ? WHERE tg_id = ?", (str(b), str(msg.chat.id),))
db_connect.commit()
bot.send_message(msg.chat.id, "Бравлер " + msg.text + " выбран!")
game.menu_cmd(msg)
else:
bname = msg.text.replace("🔒 ", "")
bot.send_message(msg.chat.id, "У тебя еще нет бравлера " + bname + "!")
# Боксы #
def box_logic(tg_id):
database.execute("SELECT chance_rare, chance_superrare, chance_epic, chance_mythic, chance_legendary FROM users WHERE tg_id = ?", (tg_id,))
#chances = [[2.7662, 1.2470, 0.5641, 0.2573, 0.1138]]
temp = database.fetchall()[0]
chances = []
i = 0
while (i < len(temp)):
chances.append(float(temp[i]))
i += 1
rand = random.randint(0, 999999) / 10000
coins = 0
gems = 0
doublers = 0
items = []
# редкий
if (rand <= chances[0]):
hn_brawlers = game.get_havent_brawlers(tg_id, 2)
if (hn_brawlers != []):
newb = hn_brawlers[random.randint(0, len(hn_brawlers)-1)]
database.execute("SELECT name, rare_id FROM brawlers WHERE id = ?", (newb,))
newb_stat = database.fetchall()[0]
newb_name = newb_stat[0]
items.append("Новый бравлер: " + newb_name)
database.execute("INSERT INTO have_brawlers (brawler_id, rare_id, tg_id) VALUES (?, ?, ?)", (newb, newb_stat[1], tg_id,))
db_connect.commit()
else:
coins += random.randint(2, 4)
# сверхредкий
elif (rand <= (chances[0] + chances[1])):
hn_brawlers = game.get_havent_brawlers(tg_id, 3)
if (hn_brawlers != []):
newb = hn_brawlers[random.randint(0, len(hn_brawlers)-1)]
database.execute("SELECT name, rare_id FROM brawlers WHERE id = ?", (newb,))
newb_stat = database.fetchall()[0]
newb_name = newb_stat[0]
items.append("Новый бравлер: " + newb_name)
database.execute("INSERT INTO have_brawlers (brawler_id, rare_id, tg_id) VALUES (?, ?, ?)", (newb, newb_stat[1], tg_id,))
db_connect.commit()
else:
coins += random.randint(4, 6)
# эпический
elif (rand <= (chances[0] + chances[1] + chances[2])):
hn_brawlers = game.get_havent_brawlers(tg_id, 4)
have_hromatics = game.get_havent_brawlers(tg_id, 7)
database.execute("SELECT id FROM brawlers WHERE rare_id = 7 ORDER BY id")
allh = database.fetchall()
i = 0
while (i < len(allh)-2):
if (allh[i][0] in have_hromatics):
hn_brawlers.append(allh[i][0])
i += 1
if (hn_brawlers != []):
newb = hn_brawlers[random.randint(0, len(hn_brawlers)-1)]
database.execute("SELECT name, rare_id FROM brawlers WHERE id = ?", (newb,))
newb_stat = database.fetchall()[0]
newb_name = newb_stat[0]
items.append("Новый бравлер: " + newb_name)
database.execute("INSERT INTO have_brawlers (brawler_id, rare_id, tg_id) VALUES (?, ?, ?)", (newb, newb_stat[1], tg_id,))
db_connect.commit()
else:
coins += random.randint(6, 8)
# мифический
elif (rand <= (chances[0] + chances[1] + chances[2] + chances[3])):
hn_brawlers = game.get_havent_brawlers(tg_id, 5)
have_hromatics = game.get_havent_brawlers(tg_id, 7)
database.execute("SELECT id FROM brawlers WHERE rare_id = 7 ORDER BY id")
allh = database.fetchall()
if (allh[len(allh)-2][0] in have_hromatics):
hn_brawlers.append(allh[len(allh)-2][0])
if (hn_brawlers != []):
newb = hn_brawlers[random.randint(0, len(hn_brawlers)-1)]
database.execute("SELECT name, rare_id FROM brawlers WHERE id = ?", (newb,))
newb_stat = database.fetchall()[0]
newb_name = newb_stat[0]
items.append("Новый бравлер: " + newb_name)
database.execute("INSERT INTO have_brawlers (brawler_id, rare_id, tg_id) VALUES (?, ?, ?)", (newb, newb_stat[1], tg_id,))
db_connect.commit()
else:
coins += random.randint(8, 10)
# легендарный
elif (rand <= (chances[0] + chances[1] + chances[2] + chances[3] + chances[4])):
hn_brawlers = game.get_havent_brawlers(tg_id, 6)
have_hromatics = game.get_havent_brawlers(tg_id, 7)
database.execute("SELECT id FROM brawlers WHERE rare_id = 7 ORDER BY id")
allh = database.fetchall()
if (allh[len(allh)-1][0] in have_hromatics):
hn_brawlers.append(allh[len(allh)-1][0])
if (hn_brawlers != []):
newb = hn_brawlers[random.randint(0, len(hn_brawlers)-1)]
database.execute("SELECT name, rare_id FROM brawlers WHERE id = ?", (newb,))
newb_stat = database.fetchall()[0]
newb_name = newb_stat[0]
items.append("Новый бравлер: " + newb_name)
database.execute("INSERT INTO have_brawlers (brawler_id, rare_id, tg_id) VALUES (?, ?, ?)", (newb, newb_stat[1], tg_id,))
db_connect.commit()
else:
coins += random.randint(10, 12)
# воздух
if (items == []):
coins += random.randint(10, 20)
rnd = random.randint(1, 100)
if (rnd <= 1): gems = 12
elif (rnd <= 2.5): gems = 9
elif (rnd <= 3.75): gems = 5
elif (rnd <= 5): gems = 3
return [coins, gems, doublers, items]
# Получение невыпавших бравлеров #
def get_havent_brawlers(tg_id, rare):
database.execute("SELECT brawler_id FROM have_brawlers WHERE tg_id = ? AND rare_id = ?", (tg_id, rare))
hbs = database.fetchall()
database.execute("SELECT id FROM brawlers WHERE rare_id = ? ORDER BY id", (rare,))
allb = database.fetchall()
temp = []
i = 0
while i < len(allb):
haveb = 0
a = 0
while a < len(hbs):
if (int(allb[i][0]) == int(hbs[a][0])):
haveb = 1
a += 1
if (haveb == 0):
temp.append(allb[i][0])
i += 1
return temp
# Маленький ящик #
def box(tg_id):
stat = game.box_logic(tg_id)
txt = ""
database.execute("SELECT gems, coins FROM users WHERE tg_id = ?", (tg_id,))
player = database.fetchall()[0]
if (stat[0] > 0):
txt += "\nМонеты: " + str(stat[0])
database.execute("UPDATE users SET coins = ? WHERE tg_id = ?", (stat[0] + player[1], tg_id,))
if (stat[1] > 0):
txt += "\nКристаллы: " + str(stat[1])
database.execute("UPDATE users SET gems = ? WHERE tg_id = ?", (stat[1] + player[0], tg_id,))
if (stat[3] != []):
i = 0
while (i < len(stat[3])):
txt += "\n" + stat[3][i]
i += 1
db_connect.commit()
return ("Маленький ящик:" + txt)
# Большой ящик #
def big_box(tg_id):
stat1 = game.box_logic(tg_id)
stat2 = game.box_logic(tg_id)
stat3 = game.box_logic(tg_id)
rnd = random.randint(1, 100)
gems = 0
if (rnd <= 3): gems = 12
elif (rnd <= 7.5): gems = 9
elif (rnd <= 11.25): gems = 5
elif (rnd <= 15): gems = 3
allitems = []
allitems.extend(stat1[3])
allitems.extend(stat2[3])
allitems.extend(stat3[3])
stat = [(stat1[0] + stat2[0] + stat3[0]), gems, (stat1[2] + stat2[2] + stat3[2]), allitems]
txt = ""
database.execute("SELECT gems, coins FROM users WHERE tg_id = ?", (tg_id,))
player = database.fetchall()[0]
if (stat[0] > 0):
txt += "\nМонеты: " + str(stat[0])
database.execute("UPDATE users SET coins = ? WHERE tg_id = ?", (stat[0] + player[1], tg_id,))
if (stat[1] > 0):
txt += "\nКристаллы: " + str(stat[1])
database.execute("UPDATE users SET gems = ? WHERE tg_id = ?", (stat[1] + player[0], tg_id,))
if (stat[3] != []):
i = 0
while (i < len(stat[3])):
txt += "\n" + stat[3][i]
i += 1
db_connect.commit()
return ("Большой ящик:" + txt)
# Мегаящик #
def megabox(tg_id):
stat1 = game.box_logic(tg_id)
stat2 = game.box_logic(tg_id)
stat3 = game.box_logic(tg_id)
stat4 = game.box_logic(tg_id)
stat5 = game.box_logic(tg_id)
stat6 = game.box_logic(tg_id)
stat7 = game.box_logic(tg_id)
stat8 = game.box_logic(tg_id)
stat9 = game.box_logic(tg_id)
stat10 = game.box_logic(tg_id)
rnd = random.randint(1, 100)
gems = 0
if (rnd <= 5): gems = 12
elif (rnd <= 12.5): gems = 9
elif (rnd <= 18.75): gems = 5
elif (rnd <= 25): gems = 3
allitems = []
allitems.extend(stat1[3])
allitems.extend(stat2[3])
allitems.extend(stat3[3])
allitems.extend(stat4[3])
allitems.extend(stat5[3])
allitems.extend(stat6[3])
allitems.extend(stat7[3])
allitems.extend(stat8[3])
allitems.extend(stat9[3])
allitems.extend(stat10[3])
stat = [(stat1[0] + stat2[0] + stat3[0] + stat4[0] + stat5[0] + stat6[0] + stat7[0] + stat8[0] + stat9[0] + stat10[0]), gems, (stat1[1] + stat2[1] + stat3[1] + stat4[1] + stat5[1] + stat6[1] + stat7[1] + stat8[1] + stat9[1] + stat10[1]), allitems]
txt = ""
database.execute("SELECT gems, coins FROM users WHERE tg_id = ?", (tg_id,))
player = database.fetchall()[0]
if (stat[0] > 0):
txt += "\nМонеты: " + str(stat[0])
database.execute("UPDATE users SET coins = ? WHERE tg_id = ?", (stat[0] + player[1], tg_id,))
if (stat[1] > 0):
txt += "\nКристаллы: " + str(stat[1])
database.execute("UPDATE users SET gems = ? WHERE tg_id = ?", (stat[1] + player[0], tg_id,))
if (stat[3] != []):
i = 0
while (i < len(stat[3])):
txt += "\n" + stat[3][i]
i += 1
db_connect.commit()
return ("Мегаящик:" + txt)
# Бравл пасс #
def brawl_pass(msg):
database.execute("SELECT brawlpass_lvl, brawlpass_opened, tokens FROM users WHERE tg_id = ?", (msg.chat.id,))
stat = database.fetchall()[0]
txt = "Бравл пасс:\nТекущий уровень: " + str(stat[0])
items = []
i = stat[1] + 2
if (stat[1] < stat[0]):
q = "SELECT reward, count FROM brawl_pass WHERE level = " + str(stat[1] + 1)
while (i <= stat[0]):
q += " OR level = " + str(i)
i += 1
database.execute(q)
raw_items = database.fetchall()
i = 0
while (i < len(raw_items)):
tempt = ""
if (raw_items[i][0].lower() == "box"):
tempt = "Маленький ящик"
elif (raw_items[i][0].lower() == "bigbox"):
tempt = "Большой ящик"
elif (raw_items[i][0].lower() == "megabox"):
tempt = "Мегаящик"
elif (raw_items[i][0].lower() == "gems"):
tempt = str(raw_items[i][1]) + " гемов"
elif (raw_items[i][0].lower() == "money"):
tempt = str(raw_items[i][1]) + " монет"
elif (raw_items[i][0].lower() == "doublers"):
tempt = str(raw_items[i][1]) + " удвоителей"
items.append(tempt)
i += 1
if (items != []):
txt += "\nДоступно к открытию: "
txt += str(items[0])
i = 1
while (i < len(items)):
txt += ", " + str(items[i])
i += 1
bot.send_message(msg.chat.id, txt, reply_markup=ReplyKeyboardMarkup([["Открыть",], ["В меню",],], resize_keyboard=True))
def open_brawl_pass(msg):
database.execute("SELECT brawlpass_lvl, brawlpass_opened FROM users WHERE tg_id = ?", (msg.chat.id,))
stat = database.fetchall()[0]
if (stat[1] < stat[0]):
database.execute("SELECT reward, count FROM brawl_pass WHERE level = ?", (stat[1] + 1,))
lvl = database.fetchall()[0]
if (lvl[0] == "Box"):
txt = game.box(msg.chat.id)
bot.send_message(msg.chat.id, txt)
elif (lvl[0] == "Bigbox"):
txt = game.big_box(msg.chat.id)
bot.send_message(msg.chat.id, txt)
elif (lvl[0] == "Megabox"):
txt = game.megabox(msg.chat.id)
bot.send_message(msg.chat.id, txt)
elif (lvl[0] == "Gems"):
database.execute("SELECT gems FROM users WHERE tg_id = ?", (msg.chat.id,))
temp = database.fetchall()
database.execute("UPDATE users SET gems = ? WHERE tg_id = ?", (temp[0][0] + lvl[1], msg.chat.id,))
db_connect.commit()
bot.send_message(msg.chat.id, str(lvl[1]) + " гемов")
elif (lvl[0] == "Money"):
database.execute("SELECT coins FROM users WHERE tg_id = ?", (msg.chat.id,))
temp = database.fetchall()
database.execute("UPDATE users SET coins = ? WHERE tg_id = ?", (temp[0][0] + lvl[1], msg.chat.id,))
db_connect.commit()
bot.send_message(msg.chat.id, str(lvl[1]) + " монет")
elif (lvl[0] == "Doublers"):
database.execute("SELECT doublers FROM users WHERE tg_id = ?", (msg.chat.id,))
temp = database.fetchall()
database.execute("UPDATE users SET doublers = ? WHERE tg_id = ?", (temp[0][0] + lvl[1], msg.chat.id,))
db_connect.commit()
bot.send_message(msg.chat.id, str(lvl[1]) + " удвоителей")
database.execute("UPDATE users SET brawlpass_opened = ? WHERE tg_id = ?", (stat[1] + 1, msg.chat.id,))
db_connect.commit()
else:
bot.send_message(msg.chat.id, "Заработай больше токенов, чтобы открыть новый уровень!")
def update_tokens(msg):
database.execute("SELECT rtokens_update, rtokens, brawlpass_lvl, tokens FROM users WHERE tg_id = ?", (msg.chat.id,))
result = database.fetchall()[0]
ptokens = 0
if (time.time() > (result[0] + (3600 * 10))):
ptokens = 200
elif (time.time() > (result[0] + (3600 * 9))):
ptokens = 180
elif (time.time() > (result[0] + (3600 * 8))):
ptokens = 160
elif (time.time() > (result[0] + (3600 * 7))):
ptokens = 140
elif (time.time() > (result[0] + (3600 * 6))):
ptokens = 120
elif (time.time() > (result[0] + (3600 * 5))):
ptokens = 100
elif (time.time() > (result[0] + (3600 * 4))):
ptokens = 80
elif (time.time() > (result[0] + (3600 * 3))):
ptokens = 60
elif (time.time() > (result[0] + (3600 * 2))):
ptokens = 40
elif (time.time() > (result[0] + (3600 * 1))):
ptokens = 20
if (ptokens != 0):
if ((ptokens + result[1]) > 200):
database.execute("UPDATE users SET rtokens = 200 WHERE tg_id = ?", (msg.chat.id,))
else:
database.execute("UPDATE users SET rtokens = ? WHERE tg_id = ?", ((ptokens + result[1]), msg.chat.id,))
db_connect.commit()
i = 1
while (time.time() > (result[0] + (3600 * i))):
i += 1
database.execute("UPDATE users SET rtokens_update = ? WHERE tg_id = ?", (result[0] + (3600 * i), msg.chat.id,))
if (result[3] > 100):
o = result[3]
pllv = 0
while (o > 100):
pllv += 1
o -= 100
database.execute("UPDATE users SET tokens = ? WHERE tg_id = ?", ((o), msg.chat.id,))
database.execute("UPDATE users SET brawlpass_lvl = ? WHERE tg_id = ?", ((pllv + result[2]), msg.chat.id,))
db_connect.commit()
if (result[0] == 0):
database.execute("UPDATE users SET rtokens_update = ? WHERE tg_id = ?", (round(time.time()), msg.chat.id,))
def shop(msg, b = "0"):
if ((b == "0") or (b == "-1")):
keys = [[InlineKeyboardButton("Акции", "shop 1")], [InlineKeyboardButton("Ящики", "shop 2")], [InlineKeyboardButton("Донат", "shop 3")]]
if (b == "-1"):
bot.edit_message_text(msg.message.chat.id, msg.message.message_id, "Магазин:", reply_markup=InlineKeyboardMarkup(keys))
else:
bot.send_message(msg.chat.id, "Магазин:", reply_markup=InlineKeyboardMarkup(keys))
elif (b == "1"):
database.execute("SELECT * FROM sales")
result = database.fetchall()
sales = []
i = 0
database.execute("SELECT sale_id FROM buyed_sales WHERE tg_id = ?", (msg.message.chat.id,))
hb = database.fetchall()
while i < len(result):
haveb = 0
a = 0
while a < len(hb):
if (int(result[i][0]) == int(hb[a][0])):
haveb = 1
a += 1
if (haveb == 0):
sales.append([InlineKeyboardButton(result[i][1], "sale " + str(result[i][0]))])
i += 1
sales.append([InlineKeyboardButton("Назад", "shop -1")])
bot.edit_message_text(msg.message.chat.id, msg.message.message_id, "Акции:", reply_markup=InlineKeyboardMarkup(sales))
elif (b == "2"):
keys = [[InlineKeyboardButton("Большой ящик", "shop bigbox")], [InlineKeyboardButton("Мегаящик", "shop megabox")], [InlineKeyboardButton("Назад", "shop -1")]]
bot.edit_message_text(msg.message.chat.id, msg.message.message_id, "Ящики:", reply_markup=InlineKeyboardMarkup(keys))
elif (b == "3"):
keys = [[InlineKeyboardButton("Назад", "shop -1")]]
bot.edit_message_text(msg.message.chat.id, msg.message.message_id, "Донат проходит через систему DonationAlerts.\nДля того, что бы бот увидел донат, нужно в Message указать: <code>spike gems " + str(msg.message.chat.id) + "</code>. Ещё, донат нужно кидать в РУБЛЯХ!\n30 гемов - 15₽\n80 гемов - 35₽\n170 гемов - 70₽\n360 гемов - 150₽\n950 гемов - 440₽\n2000 гемов - 850₽\n\n<a href='https://www.donationalerts.com/r/boomkitty'>Ссылка на DonationAlerts</a> (кликабельно)\n*Если задонатить например 20₽ вместо 15₽, то зачислится всё равно 30 гемов, а 5₽ не вернутся.\nЕсли возникнут вопросы - @boom_kitty", reply_markup=InlineKeyboardMarkup(keys))
elif (b == "bigbox"):
database.execute("SELECT gems FROM users WHERE tg_id = ?", (msg.message.chat.id,))
result = database.fetchall()
if (result[0][0] >= 30):
database.execute("UPDATE users SET gems = ? WHERE tg_id = ?", (result[0][0] - 30, msg.message.chat.id,))
db_connect.commit()
txt = game.big_box(msg.message.chat.id)
bot.edit_message_text(msg.message.chat.id, msg.message.message_id, txt, reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Назад", "shop 2")]]))
else:
bot.edit_message_text(msg.message.chat.id, msg.message.message_id, "У тебя недостаточно гемов для покупки этого предмета.", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Назад", "shop 2")]]))
elif (b == "megabox"):
database.execute("SELECT gems FROM users WHERE tg_id = ?", (msg.message.chat.id,))
result = database.fetchall()
if (result[0][0] >= 80):
database.execute("UPDATE users SET gems = ? WHERE tg_id = ?", (result[0][0] - 80, msg.message.chat.id,))
db_connect.commit()
txt = game.megabox(msg.message.chat.id)
bot.edit_message_text(msg.message.chat.id, msg.message.message_id, txt, reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Назад", "shop 2")]]))
else:
bot.edit_message_text(msg.message.chat.id, msg.message.message_id, "У тебя недостаточно гемов для покупки этого предмета.", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("Назад", "shop 2")]]))
def select_sale(msg, sale):
database.execute("SELECT sale_id FROM buyed_sales WHERE tg_id = ? AND sale_id = ?", (msg.message.chat.id, sale))
hb = database.fetchall()
if (hb == []):
database.execute("SELECT * FROM sales WHERE id = ?", (sale,))
result = database.fetchall()[0]
text = "<b>" + result[1] + "</b>"
if (result[5] > 0):
text += "\nМонеты: " + str(result[5])
if (result[4] > 0):
text += "\nКристаллы: " + str(result[4])
if (result[6] > 0):
text += "\nДаблеры: " + str(result[6])
if (result[7] > 0):
text += "\nМаленькие ящики: " + str(result[7])
if (result[8] > 0):
text += "\nБольшие ящики: " + str(result[8])
if (result[9] > 0):
text += "\nМегаящики: " + str(result[9])
if (result[9] > 0):
text += "\nНовый бравлер: " + str(result[10])
if (result[9] > 0):
text += "\nНовый скин: " + str(result[11])
button = ""
if (result[2] == 1):
button = str(result[3]) + " кристаллов"
elif (result[2] == 2):
button = str(result[3]) + " монет"
elif (result[2] == 3):
button = str(result[3]) + "₽"
bot.edit_message_text(msg.message.chat.id, msg.message.message_id, text, reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton(button, "buy_sale " + str(sale))], [InlineKeyboardButton("Назад", "shop 1")]]))
def buy_sale(msg, sale):
database.execute("SELECT sale_id FROM buyed_sales WHERE tg_id = ? AND sale_id = ?", (msg.message.chat.id, sale))
hb = database.fetchall()
if (hb == []):
database.execute("SELECT * FROM sales WHERE id = ?", (sale,))
result = database.fetchall()[0]
if ((result[2] == 1) or (result[2] == 2)):
database.execute("SELECT * FROM users WHERE tg_id = ?", (msg.message.chat.id,))
stat = database.fetchall()[0]
if (stat[5] >= result[3]):
enough = 0
if (result[2] == 1):
if (stat[5] >= result[3]):
database.execute("UPDATE users SET gems = ? WHERE tg_id = ?", (stat[5] - result[3], msg.message.chat.id))
enough = 1
else:
if (stat[6] >= result[3]):
database.execute("UPDATE users SET coins = ? WHERE tg_id = ?", (stat[6] - result[3], msg.message.chat.id))
enough = 1
if (enough == 1):
text = "Акция <b>" + result[2] + "</b> куплена!"
if (result[5] > 0):
text += "\nМонеты: " + str(result[5])
database.execute("UPDATE users SET coins = ? WHERE tg_id = ?", (stat[6] + result[5], msg.message.chat.id))
if (result[4] > 0):
text += "\nКристаллы: " + str(result[4])
database.execute("UPDATE users SET gems = ? WHERE tg_id = ?", (stat[5] + result[4], msg.message.chat.id))
if (result[6] > 0):
text += "\nДаблеры: " + str(result[6])
database.execute("UPDATE users SET doublers = ? WHERE tg_id = ?", (stat[20] + result[6], msg.message.chat.id))
if (result[10] > 0):
text += "\nНовый бравлер: " + str(result[10])
database.execute("INSERT INTO have_brawlers (tg_id, brawler_id) VALUES (?, ?)", (msg.message.chat.id, result[10]))
if (result[11] > 0):
text += "\nНовый скин: " + str(result[11])
database.execute("INSERT INTO have_skins (tg_id, skin_id) VALUES (?, ?)", (msg.message.chat.id, result[11]))
bot.edit_message_text(msg.message.chat.id, msg.message.message_id, text)
if (result[7] > 0):
i = 0
while (i < result[7]):
bot.send_message(msg.message.chat.id, game.box(msg.message.chat.id))
i += 1
if (result[8] > 0):
while (i < result[8]):
bot.send_message(msg.message.chat.id, game.big_box(msg.message.chat.id))
i += 1
if (result[9] > 0):
while (i < result[9]):
bot.send_message(msg.message.chat.id, game.megabox(msg.message.chat.id))
i += 1
db_connect.commit()
elif (result[2] == 3):
database.execute("SELECT price FROM sales WHERE id = ?", (sale,))
bot.send_message("Донат проходит через систему DonationAlerts.\nДля того, что бы бот увидел донат, нужно в Message указать: <code>spike sale " + str(sale) + " " + str(msg.message.chat.id) + "</code>. Ещё, донат нужно кидать в РУБЛЯХ!\nСумма доната: " + database.fetchall()[0][0] + "\n\n<a href='https://www.donationalerts.com/r/boomkitty'>Ссылка на DonationAlerts</a> (кликабельно)\n*Донатить нужно больше суммы или равной ей.\nЕсли возникнут вопросы - @boom_kitty")
def skins(msg):
database.execute("SELECT skin_id FROM have_skins WHERE tg_id = ? AND brawler_id = ? AND ")
# Конфиг #
import os
token = os.environ['bot_token']
bot = Client("my_bot", bot_token=token, api_id=1234567, api_hash="123456789")
# Коннект к бд #
db_connect = sqlite3.connect('db.db', check_same_thread=False)
database = db_connect.cursor()
# Меню + регистрация #
# Registration: 0-5 = Game; 5-8 = Brawlers; 9 = Nickname #
@bot.on_message(filters.command("start", prefixes="/"))
def start(_, msg):
database.execute("SELECT registration FROM users WHERE tg_id = ?", (str(msg.chat.id),))
result = database.fetchall()
if (result == [] or result[0][0] == None):
bot.send_message(msg.chat.id, "Добро пожаловать в Спайка!\nНажми <b>Играть</b>, что бы сыграть первый бой.", reply_markup=ReplyKeyboardMarkup([["Играть",]], resize_keyboard=True))
database.execute("INSERT or IGNORE INTO users (tg_id) VALUES (?)", (str(msg.chat.id),))
db_connect.commit()
elif (result[0][0] == 8):
bot.send_message(msg.chat.id, "Придумай себе никнейм:", reply_markup=ReplyKeyboardRemove())
database.execute("UPDATE users SET registration = 9 WHERE tg_id = ?", (str(msg.chat.id),))
db_connect.commit()
else:
game.menu_cmd(msg)
# Кнопки
@bot.on_message()
def command(_, msg):
database.execute("SELECT registration FROM users WHERE tg_id = ?", (str(msg.chat.id),))
result = database.fetchall()
if (result[0][0] == 9):
bot.send_message(msg.chat.id, "Никнейм установлен!")
database.execute("UPDATE users SET nickname = ? WHERE tg_id = ?", (msg.text, str(msg.chat.id),))
database.execute("UPDATE users SET registration = 10 WHERE tg_id = ?", (str(msg.chat.id),))
db_connect.commit()
start(_, msg)
else:
if (msg.text == "Играть"):
if (antiflood(msg, 0.5)):
game.play_cmd(msg)
elif (msg.text == "Захват кристаллов"):
if (antiflood(msg, 0.5)):
game.playgame_cmd(msg, 1)
elif (msg.text == "Онлайн захват кристаллов"):
if (antiflood(msg, 0.5)):
game.playgame_cmd(msg, 3)
elif (msg.text == "Столкновение"):
if (antiflood(msg, 0.5)):
game.playgame_cmd(msg, 2)
elif (msg.text == "Играть снова"):
if (antiflood(msg, 0.7)):
database.execute("SELECT now_action FROM users WHERE tg_id = ?", (str(msg.chat.id),))
result2 = database.fetchall()
game.playgame_cmd(msg, result2[0][0])
elif (msg.text == "В меню"):
if (antiflood(msg, 0.5)):
#game.menu_cmd(msg)
database.execute("SELECT now_action FROM users WHERE tg_id = ?", (str(msg.chat.id),))
result2 = database.fetchall()
if (result2[0][0] == 3):
database.execute("SELECT * FROM online")
result3 = database.fetchall()
if (result3 != []):
if (result3[0][0] == msg.chat.id):
database.execute("DELETE FROM online")
db_connect.commit()
start(_, msg)
elif (msg.text == "Бравл пасс"):
if (antiflood(msg, 0.5)):
game.brawl_pass(msg)
elif (msg.text == "Открыть"):
if (antiflood(msg, 0.5)):
game.open_brawl_pass(msg)
elif (msg.text == "Бравлеры"):
if (antiflood(msg, 0.5)):
game.brawlers_cmd(msg, 0)
elif (msg.text == "Обычные"):
if (antiflood(msg, 0.5)):
game.brawlers_cmd(msg, 1)
elif (msg.text == "Редкие"):
if (antiflood(msg, 0.5)):
game.brawlers_cmd(msg, 2)
elif (msg.text == "Сверхредкие"):
if (antiflood(msg, 0.5)):
game.brawlers_cmd(msg, 3)
elif (msg.text == "Эпические"):
if (antiflood(msg, 0.5)):
game.brawlers_cmd(msg, 4)
elif (msg.text == "Мифические"):
if (antiflood(msg, 0.5)):
game.brawlers_cmd(msg, 5)
elif (msg.text == "Легендарные"):
if (antiflood(msg, 0.5)):
game.brawlers_cmd(msg, 6)
elif (msg.text == "Хроматические"):
if (antiflood(msg, 0.5)):
game.brawlers_cmd(msg, 7)
else:
if (antiflood(msg, 0.5)):
txt = msg.text.replace("🔒 ", "")
database.execute("SELECT * FROM brawlers WHERE name = ?", (str(txt),))
result2 = database.fetchall()
if (result2 != []):
game.select_brawler_cmd(msg, result2[0][0])
# Инлайн-кнопки
@bot.on_callback_query()
def buttons(client, query):
qcommand = query.data.title().split()
if (qcommand[0].lower() == "shop"):
game.shop(query, qcommand[1].lower())
if (qcommand[0].lower() == "sale"):
game.select_sale(query, qcommand[1].lower())
if (qcommand[0].lower() == "buy_sale"):
game.select_sale(query, qcommand[1].lower())
# DonationAlerts
'''da_token = os.environ['da_token']
from donationalerts_api import Alert
alert = Alert(da_token)
@alert.event()
def donation(event):
message = event.message.split()
if ((message[0] == "spike") and (message[1] == "gems")):
if (event.currency == "RUB"):
if (event.amount_main >= 850):
gems = 2000
elif (event.amount_main >= 440):
gems = 950
elif (event.amount_main >= 150):
gems = 360
elif (event.amount_main >= 70):
gems = 170
elif (event.amount_main >= 35):
gems = 80
elif (event.amount_main >= 15):
gems = 30
bot.send_message(message[2], "На твой аккаунт было задоначено " + str(gems) + " кристаллов от " + event.username + ". Большое спасибо за поддержку :^")
database.execute("SELECT gems FROM users WHERE tg_id = ?", (message[2],))
result = database.fetchall()[0][0]
database.execute("UPDATE users SET gems = ? WHERE tg_id = ?", (result + gems, message[2],))
db_connect.commit()
elif ((message[0] == "spike") and (message[1] == "sale")):
if (event.currency == "RUB"):
database.execute("SELECT * FROM sales WHERE id = ?", (message[2],))
bot.send_message(message[3], "Акция " + str(gems) + " куплена от " + event.username + ". Большое спасибо за поддержку :^")
db_connect.commit()
'''
bot.run()
'''
Примечания:
skins - type: 1 - гемы, 2 - монеты, 3 - донат
skins - excl: 0 - будет болтаться среди скинов в магазине
sales - type: 1 - гемы, 2 - монеты, 3 - донат
'''