-
Notifications
You must be signed in to change notification settings - Fork 6
/
tipcc_autocollect.py
965 lines (920 loc) · 36.4 KB
/
tipcc_autocollect.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
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
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
from asyncio import TimeoutError, sleep
from logging import (
CRITICAL,
DEBUG,
ERROR,
INFO,
WARNING,
Formatter,
StreamHandler,
getLogger,
)
from math import acosh, asinh, atanh, ceil, cos, cosh, e, erf, exp
from math import fabs as abs
from math import factorial, floor
from math import fmod as mod
from math import (
gamma,
gcd,
hypot,
log,
log1p,
log2,
log10,
pi,
pow,
sin,
sinh,
sqrt,
tan,
tau,
)
from random import randint, uniform
from re import compile
from time import time
from urllib.parse import quote, unquote
from aiohttp import ClientSession
from art import tprint
from discord import Client, HTTPException, LoginFailure, Message, NotFound, Status
from discord.ext import tasks
from questionary import checkbox, select, text
class ColourFormatter(
Formatter
): # Taken from discord.py-self and modified to my liking.
LEVEL_COLOURS = [
(DEBUG, "\x1b[40;1m"),
(INFO, "\x1b[34;1m"),
(WARNING, "\x1b[33;1m"),
(ERROR, "\x1b[31m"),
(CRITICAL, "\x1b[41m"),
]
FORMATS = {
level: Formatter(
f"\x1b[30;1m%(asctime)s\x1b[0m {colour}%(levelname)-8s\x1b[0m \x1b[35m%(name)s\x1b[0m %(message)s \x1b[30;1m(%(filename)s:%(lineno)d)\x1b[0m",
"%d-%b-%Y %I:%M:%S %p",
)
for level, colour in LEVEL_COLOURS
}
def format(self, record):
formatter = self.FORMATS.get(record.levelno)
if formatter is None:
formatter = self.FORMATS[DEBUG]
if record.exc_info:
text = formatter.formatException(record.exc_info)
record.exc_text = f"\x1b[31m{text}\x1b[0m"
output = formatter.format(record)
record.exc_text = None
return output
handler = StreamHandler()
formatter = ColourFormatter()
handler.setFormatter(formatter)
logger = getLogger("tipcc_autocollect")
logger.addHandler(handler)
logger.setLevel("INFO")
def cbrt(x):
return pow(x, 1 / 3)
try:
from ujson import dump, load
except ModuleNotFoundError:
logger.warning("ujson not found, using json instead.")
from json import dump, load
except ImportError:
logger.warning("ujson not found, using json instead.")
from json import dump, load
else:
logger.info("ujson found, using ujson.")
channel = None
print("\033[0;35m")
tprint("QuartzWarrior", font="smslant")
print("\033[0m")
try:
with open("config.json", "r") as f:
config = load(f)
except FileNotFoundError:
config = {
"TOKEN": "",
"PRESENCE": "invisible",
"CPM": [200, 310],
"FIRST": True,
"id": 0,
"channel_id": 0,
"TARGET_AMOUNT": 0.0,
"SMART_DELAY": True,
"RANGE_DELAY": False,
"DELAY": [0, 1],
"BANNED_WORDS": ["bot", "ban"],
"MESSAGES": [],
"WHITELIST": [],
"BLACKLIST": [],
"CHANNEL_WHITELIST": [],
"CHANNEL_BLACKLIST": [],
"IGNORE_USERS": [],
"SEND_MESSAGE": False,
"WHITELIST_ON": False,
"BLACKLIST_ON": False,
"CHANNEL_WHITELIST_ON": False,
"CHANNEL_BLACKLIST_ON": False,
"IGNORE_DROPS_UNDER": 0.0,
"IGNORE_TIME_UNDER": 0.0,
"IGNORE_THRESHOLDS": [],
"DISABLE_AIRDROP": False,
"DISABLE_TRIVIADROP": False,
"DISABLE_MATHDROP": False,
"DISABLE_PHRASEDROP": False,
"DISABLE_REDPACKET": False,
"DELAY_AIRDROP": True,
"DELAY_TRIVIADROP": True,
"DELAY_MATHDROP": True,
"DELAY_PHRASEDROP": True,
"DELAY_REDPACKET": False,
}
with open("config.json", "w") as f:
dump(config, f, indent=4)
token_regex = compile(r"[\w-]{24}\.[\w-]{6}\.[\w-]{27,}")
decimal_regex = compile(r"^-?\d+(?:\.\d+)$")
def validate_token(token):
if token_regex.search(token):
return True
else:
return False
def validate_decimal(decimal):
if decimal_regex.match(decimal):
return True
else:
return False
def validate_threshold_chance(s):
try:
threshold, chance = s.split(":")
return (
validate_decimal(threshold)
and chance.isnumeric()
and 0 <= int(chance) <= 100
)
except ValueError:
if s == "":
return True
return False
if config["TOKEN"] == "":
token_input = text(
"What is your discord token?",
qmark="->",
validate=lambda x: validate_token(x),
).ask()
if token_input is not None:
config["TOKEN"] = token_input
with open("config.json", "w") as f:
dump(config, f, indent=4)
logger.debug("Token saved.")
if config["FIRST"] == True:
config["PRESENCE"] = select(
"What do you want your presence to be?",
choices=[
"online",
"idle",
"dnd",
"invisible",
],
default="invisible",
qmark="->",
).ask()
config["CPM"][0] = int(
text(
"What is your minimum CPM (Characters Per Minute)?\nThis is to make the phrase drop collector more legit.\nRemember, the higher the faster!",
default="200",
qmark="->",
validate=lambda x: (validate_decimal(x) or x.isnumeric()) and float(x) >= 0,
).ask()
)
config["CPM"][1] = int(
text(
"What is your maximum CPM (Characters Per Minute)?\nThis is to make the phrase drop collector more legit.\nRemember, the higher the faster!",
default="310",
qmark="->",
validate=lambda x: (validate_decimal(x) or x.isnumeric()) and float(x) >= 0,
).ask()
)
config["FIRST"] = False
config["DISABLE_AIRDROP"] = False
config["DISABLE_TRIVIADROP"] = False
config["DISABLE_MATHDROP"] = False
config["DISABLE_PHRASEDROP"] = False
config["DISABLE_REDPACKET"] = False
config["DELAY_AIRDROP"] = True
config["DELAY_TRIVIADROP"] = True
config["DELAY_MATHDROP"] = True
config["DELAY_PHRASEDROP"] = True
config["DELAY_REDPACKET"] = False
disable_drops = checkbox(
"What drop types do you want to disable? (Leave blank for none)",
choices=[
"airdrop",
"triviadrop",
"mathdrop",
"phrasedrop",
"redpacket",
],
qmark="->",
).ask()
if not disable_drops:
disable_drops = []
if "airdrop" in disable_drops:
config["DISABLE_AIRDROP"] = True
if "triviadrop" in disable_drops:
config["DISABLE_TRIVIADROP"] = True
if "mathdrop" in disable_drops:
config["DISABLE_MATHDROP"] = True
if "phrasedrop" in disable_drops:
config["DISABLE_PHRASEDROP"] = True
if "redpacket" in disable_drops:
config["DISABLE_REDPACKET"] = True
delay_drops = checkbox(
"What drop types do you want to enable delay for? (Leave blank for none)",
choices=[
"airdrop",
"triviadrop",
"mathdrop",
"phrasedrop",
"redpacket",
],
qmark="->",
).ask()
if not delay_drops:
delay_drops = []
if "airdrop" in delay_drops:
config["DELAY_AIRDROP"] = True
if "triviadrop" in delay_drops:
config["DELAY_TRIVIADROP"] = True
if "mathdrop" in delay_drops:
config["DELAY_MATHDROP"] = True
if "phrasedrop" in delay_drops:
config["DELAY_PHRASEDROP"] = True
if "redpacket" in delay_drops:
config["DELAY_REDPACKET"] = True
ignore_drops_under = text(
"What is the minimum amount of money you want to ignore?",
default="0",
qmark="->",
validate=lambda x: ((validate_decimal(x) or x.isnumeric()) and float(x) >= 0)
or x == "",
).ask()
if ignore_drops_under != "":
config["IGNORE_DROPS_UNDER"] = float(ignore_drops_under)
else:
config["IGNORE_DROPS_UNDER"] = 0.0
ignore_time_under = text(
"What is the minimum time you want to ignore?",
default="0",
qmark="->",
validate=lambda x: ((validate_decimal(x) or x.isnumeric()) and float(x) >= 0)
or x == "",
).ask()
if ignore_time_under != "":
config["IGNORE_TIME_UNDER"] = float(ignore_time_under)
else:
config["IGNORE_TIME_UNDER"] = 0.0
ignore_thresholds = text(
"Enter your ignore thresholds and chances in the format 'threshold:chance', separated by commas (e.g. '0.10:10,0.20:20')",
validate=lambda x: all(validate_threshold_chance(pair) for pair in x.split(","))
or x == "",
default="",
qmark="->",
).ask()
if ignore_thresholds != "":
config["IGNORE_THRESHOLDS"] = [
{"threshold": float(pair.split(":")[0]), "chance": int(pair.split(":")[1])}
for pair in ignore_thresholds.split(",")
]
else:
config["IGNORE_THRESHOLDS"] = []
smart_delay = select(
"Do you want to enable smart delay? (This will make the bot wait for the drop to end before claiming it)",
choices=["yes", "no"],
qmark="->",
).ask()
if smart_delay == "yes":
config["SMART_DELAY"] = True
else:
config["SMART_DELAY"] = False
range_delay = select(
"Do you want to enable range delay? (This will make the bot wait for a random delay between two values)",
choices=["yes", "no"],
qmark="->",
).ask()
if range_delay == "yes":
config["RANGE_DELAY"] = True
min_delay = text(
"What is the minimum delay you want to use in seconds?",
validate=lambda x: (validate_decimal(x) or x.isnumeric()) and float(x) >= 0,
qmark="->",
).ask()
max_delay = text(
"What is the maximum delay you want to use in seconds?",
validate=lambda x: (validate_decimal(x) or x.isnumeric()) and float(x) >= 0,
qmark="->",
).ask()
config["DELAY"] = [float(min_delay), float(max_delay)]
else:
manual_delay = text(
"What is the delay you want to use in seconds? (Leave blank for none)",
validate=lambda x: (validate_decimal(x) or x.isnumeric()) or x == "",
default="0",
qmark="->",
).ask()
if manual_delay != "":
config["DELAY"] = [float(manual_delay), float(manual_delay)]
else:
config["DELAY"] = [0, 0]
banned_words = text(
"What words do you want to ban? Seperate each word with a comma.",
validate=lambda x: len(x) > 0 or x == "",
qmark="->",
).ask()
if not banned_words:
banned_words = []
else:
banned_words = banned_words.split(",")
config["BANNED_WORDS"] = banned_words
send_messages = select(
"Do you want to send messages after claiming a drop?",
choices=["yes", "no"],
qmark="->",
).ask()
config["SEND_MESSAGE"] = send_messages == "yes"
if config["SEND_MESSAGE"]:
messages = text(
"What messages do you want to send after claiming a drop? Seperate each message with a comma.",
validate=lambda x: len(x) > 0 or x == "",
qmark="->",
).ask()
if not messages:
messages = []
else:
messages = messages.split(",")
config["MESSAGES"] = messages
enable_whitelist = select(
"Do you want to enable whitelist? (This will only enter drops in the servers you specify)",
choices=["yes", "no"],
qmark="->",
).ask()
config["WHITELIST_ON"] = enable_whitelist == "yes"
if not config["WHITELIST_ON"]:
enable_blacklist = select(
"Do you want to enable blacklist? (This will ignore drops in the servers you specify)",
choices=["yes", "no"],
qmark="->",
).ask()
config["BLACKLIST_ON"] = enable_blacklist == "yes"
if config["BLACKLIST_ON"]:
blacklist = text(
"What servers do you want to blacklist? Seperate each server ID with a comma.",
validate=lambda x: (
len(x) > 0
and all(y.isnumeric() and 17 <= len(y) <= 19 for y in x.split(","))
)
or x == "",
qmark="->",
).ask()
if not blacklist:
blacklist = []
else:
blacklist = [int(x) for x in blacklist.split(",")]
config["BLACKLIST"] = blacklist
else:
whitelist = text(
"What servers do you want to whitelist? Seperate each server ID with a comma.",
validate=lambda x: (
len(x) > 0
and all(y.isnumeric() and 17 <= len(y) <= 19 for y in x.split(","))
)
or x == "",
qmark="->",
).ask()
if not whitelist:
whitelist = []
else:
whitelist = [int(x) for x in whitelist.split(",")]
config["WHITELIST"] = whitelist
enable_channel_whitelist = select(
"Do you want to enable channel whitelist? (This will only enter drops in the channels you specify)",
choices=["yes", "no"],
qmark="->",
).ask()
config["CHANNEL_WHITELIST_ON"] = enable_channel_whitelist == "yes"
if not config["CHANNEL_WHITELIST_ON"]:
enable_blacklist = select(
"Do you want to enable channel blacklist? (This will ignore drops in the channels you specify)",
choices=["yes", "no"],
qmark="->",
).ask()
config["CHANNEL_BLACKLIST_ON"] = enable_blacklist == "yes"
if config["CHANNEL_BLACKLIST_ON"]:
blacklist = text(
"What channels do you want to blacklist? Seperate each channel ID with a comma.",
validate=lambda x: (
len(x) > 0
and all(y.isnumeric() and 17 <= len(y) <= 19 for y in x.split(","))
)
or x == "",
qmark="->",
).ask()
if not blacklist:
blacklist = []
else:
blacklist = [int(x) for x in blacklist.split(",")]
config["CHANNEL_BLACKLIST"] = blacklist
else:
whitelist = text(
"What channels do you want to whitelist? Seperate each channel ID with a comma.",
validate=lambda x: (
len(x) > 0
and all(y.isnumeric() and 17 <= len(y) <= 19 for y in x.split(","))
)
or x == "",
qmark="->",
).ask()
if not whitelist:
whitelist = []
else:
whitelist = [int(x) for x in whitelist.split(",")]
config["CHANNEL_WHITELIST"] = whitelist
ignore_users = text(
"What users do you want to ignore? Seperate each user ID with a comma.",
validate=lambda x: (
len(x) > 0
and all(y.isnumeric() and 17 <= len(y) <= 19 for y in x.split(","))
)
or x == "",
qmark="->",
).ask()
if not ignore_users:
ignore_users = []
else:
ignore_users = [int(x) for x in ignore_users.split(",")]
config["IGNORE_USERS"] = ignore_users
user_id = int(
text(
"What is your main accounts id?\n\nIf you are sniping from your main, put your main accounts' id.",
validate=lambda x: x.isnumeric() and 17 <= len(x) <= 19,
qmark="->",
).ask()
)
config["id"] = user_id
channel_id = int(
text(
"What is the channel id where you want your alt to tip your main?\n(Remember, the tip.cc bot has to be in the server with this channel.)\n\nIf None, send 1.",
validate=lambda x: x.isnumeric() and (17 <= len(x) <= 19 or int(x) == 1),
default="1",
qmark="->",
).ask()
)
config["channel_id"] = channel_id
target_amount = float(
text(
"What is the target amount you want to tip your main at? Set it to 0 to disable.",
validate=lambda x: validate_decimal(x),
default="0",
qmark="->",
).ask()
)
config["TARGET_AMOUNT"] = target_amount
with open("config.json", "w") as f:
dump(config, f, indent=4)
logger.debug("Config saved.")
banned_words = set(config["BANNED_WORDS"])
client = Client(
status=(
Status.invisible
if config["PRESENCE"] == "invisible"
else (
Status.online
if config["PRESENCE"] == "online"
else (
Status.idle
if config["PRESENCE"] == "idle"
else Status.dnd if config["PRESENCE"] == "dnd" else Status.unknown
)
)
)
)
@client.event
async def on_ready():
global channel
channel = client.get_channel(config["channel_id"])
logger.info(f"Logged in as {client.user.name}#{client.user.discriminator}")
if config["channel_id"] != 1 and client.user.id != config["id"]:
tipping.start()
logger.info("Tipping started.")
else:
logger.warning("Disabling tipping as requested.")
@tasks.loop(minutes=10.0)
async def tipping():
await channel.send("$bals top")
logger.debug("Sent command: $bals top")
answer = await client.wait_for(
"message",
check=lambda message: message.author.id == 617037497574359050
and message.embeds,
)
try:
total_money = float(
answer.embeds[0]
.fields[-1]
.value.split("$")[1]
.replace(",", "")
.replace("**", "")
.replace(")", "")
.replace("\u200b", "")
.strip()
)
except Exception as e:
logger.exception("Error occurred while getting total money, skipping tipping.")
total_money = 0.0
logger.debug(f"Total money: {total_money}")
if total_money < config["TARGET_AMOUNT"]:
logger.info("Target amount not reached, skipping tipping.")
return
try:
pages = int(answer.embeds[0].author.name.split("/")[1].replace(")", ""))
except:
pages = 1
if not answer.components:
button_disabled = True
for _ in range(pages):
try:
button = answer.components[0].children[1]
button_disabled = button.disabled
except:
button_disabled = True
for crypto in answer.embeds[0].fields:
if "Estimated total" in crypto.name:
continue
if "DexKit" in crypto.name:
content = f"$tip <@{config['id']}> all {crypto.name.replace('*', '').replace('DexKit (BSC)', 'bKIT')}"
else:
content = f"$tip <@{config['id']}> all {crypto.name.replace('*', '')}"
async with channel.typing():
await sleep(len(content) / randint(config["CPM"][0], config["CPM"][1]) * 60)
await channel.send(content)
logger.debug(f"Sent tip: {content}")
if button_disabled:
try:
await answer.components[0].children[2].click()
logger.debug("Clicked next page button")
return
except IndexError:
try:
await answer.components[0].children[0].click()
logger.debug("Clicked first page button")
return
except IndexError:
return
else:
await button.click()
await sleep(1)
answer = await channel.fetch_message(answer.id)
@tipping.before_loop
async def before_tipping():
logger.info("Waiting for bot to be ready before tipping starts...")
await client.wait_until_ready()
@client.event
async def on_message(original_message: Message):
if (
original_message.content.startswith(
("$airdrop", "$triviadrop", "$mathdrop", "$phrasedrop", "$redpacket")
)
and not any(word in original_message.content.lower() for word in banned_words)
and (
not config["WHITELIST_ON"]
or (
config["WHITELIST_ON"]
and original_message.guild.id in config["WHITELIST"]
)
)
and (
not config["BLACKLIST_ON"]
or (
config["BLACKLIST_ON"]
and original_message.guild.id not in config["BLACKLIST"]
)
)
and (
not config["CHANNEL_WHITELIST_ON"]
or (
config["CHANNEL_WHITELIST_ON"]
and original_message.channel.id in config["CHANNEL_WHITELIST"]
)
)
and (
not config["CHANNEL_BLACKLIST_ON"]
or (
config["CHANNEL_BLACKLIST_ON"]
and original_message.channel.id not in config["CHANNEL_BLACKLIST"]
)
)
and original_message.author.id not in config["IGNORE_USERS"]
):
logger.debug(
f"Detected drop in {original_message.channel.name}: {original_message.content}"
)
try:
tip_cc_message = await client.wait_for(
"message",
check=lambda message: message.author.id == 617037497574359050
and message.channel.id == original_message.channel.id
and message.embeds
and message.embeds[0].footer
and (
"ends" in message.embeds[0].footer.text.lower()
or (
"Trivia time - " in message.embeds[0].title
and "ended" in message.embeds[0].footer.text.lower()
)
)
and str(original_message.author.id) in message.embeds[0].description,
timeout=15,
)
logger.debug("Detected tip.cc message from drop.")
except TimeoutError:
logger.exception(
"Timeout occurred while waiting for tip.cc message, skipping."
)
return
embed = tip_cc_message.embeds[0]
if "$" not in embed.description or "≈" not in embed.description:
money = 0.0
else:
try:
money = float(
embed.description.split("≈")[1]
.split(")")[0]
.strip()
.replace("$", "")
.replace(",", "")
)
except IndexError:
logger.exception(
"Index error occurred during money splitting, skipping..."
)
return
if money < config["IGNORE_DROPS_UNDER"]:
logger.info(
f"Ignored drop for {embed.description.split('**')[1]} {embed.description.split('**')[2].split(')')[0].replace(' (','')}"
)
return
for threshold in config["IGNORE_THRESHOLDS"]:
logger.debug(
f"Checking threshold: {threshold['threshold']} with chance: {threshold['chance']}"
)
if money <= threshold["threshold"]:
logger.debug(
f"Drop value {money} is less than or equal to threshold {threshold['threshold']}"
)
random_number = randint(0, 100)
if random_number < threshold["chance"]:
logger.info(
f"Ignored drop from failed threshold for {embed.description.split('**')[1]} {embed.description.split('**')[2].split(')')[0].replace(' (','')}"
)
return
logger.debug(f"Money: {money}")
logger.debug(f"Drop ends in: {embed.timestamp.timestamp() - time()}")
drop_ends_in = embed.timestamp.timestamp() - time()
if drop_ends_in < config["IGNORE_TIME_UNDER"]:
logger.info(
f"Ignored drop for {embed.description.split('**')[1]} {embed.description.split('**')[2].split(')')[0].replace(' (','')}"
)
return
if (
"An airdrop appears" in embed.title
and config["DELAY_AIRDROP"]
or "Trivia time - " in embed.title
and config["DELAY_TRIVIADROP"]
or "Math" in embed.title
and config["DELAY_MATHDROP"]
or "Phrase drop!" in embed.title
and config["DELAY_PHRASEDROP"]
or "appeared" in embed.title
and config["DELAY_REDPACKET"]
):
if config["SMART_DELAY"]:
logger.debug("Smart delay enabled, waiting...")
if drop_ends_in < 0:
logger.debug("Drop ended, skipping...")
return
delay = drop_ends_in / 4
logger.debug(f"Delay: {round(delay, 2)}")
await sleep(delay)
logger.info(f"Waited {round(delay, 2)} seconds before proceeding.")
elif config["RANGE_DELAY"]:
logger.debug("Range delay enabled, waiting...")
delay = uniform(config["DELAY"][0], config["DELAY"][1])
logger.debug(f"Delay: {delay}")
await sleep(delay)
logger.info(f"Waited {delay} seconds before proceeding.")
elif config["DELAY"] != [0, 0]:
logger.debug(f"Manual delay enabled, waiting {config['DELAY'][0]}...")
await sleep(config["DELAY"][0])
logger.info(f"Waited {config['DELAY'][0]} seconds before proceeding.")
try:
if "ended" in embed.footer.text.lower():
logger.debug("Drop ended, skipping...")
return
elif "An airdrop appears" in embed.title and not config["DISABLE_AIRDROP"]:
logger.debug("Airdrop detected, entering...")
try:
button = tip_cc_message.components[0].children[0]
except IndexError:
logger.exception(
"Index error occurred, meaning the drop most likely ended, skipping..."
)
return
if "Enter airdrop" in button.label:
await button.click()
logger.info(
f"Entered airdrop in {original_message.channel.name} for {embed.description.split('**')[1]} {embed.description.split('**')[2].split(')')[0].replace(' (','')}"
)
if config["SEND_MESSAGE"]:
message = config["MESSAGES"][
randint(0, len(config["MESSAGES"]) - 1)
]
length = len(message) / randint(config["CPM"][0], config["CPM"][1]) * 60
async with original_message.channel.typing():
await sleep(length)
await original_message.channel.send(message)
logger.info(f"Sent message: {message}")
return
elif "Phrase drop!" in embed.title and not config["DISABLE_PHRASEDROP"]:
logger.debug("Phrasedrop detected, entering...")
content = embed.description.replace("\n", "").replace("**", "")
content = content.split("*")
try:
content = content[1].replace("", "").replace("\u200b", "").strip()
except IndexError:
logger.exception("Index error occurred, skipping...")
pass
else:
logger.debug("Typing and sending message...")
length = len(content) / randint(config["CPM"][0], config["CPM"][1]) * 60
async with original_message.channel.typing():
await sleep(length)
await original_message.channel.send(content)
logger.info(
f"Entered phrasedrop in {original_message.channel.name} for {embed.description.split('**')[1]} {embed.description.split('**')[2].split(')')[0].replace(' (','')}"
)
if config["SEND_MESSAGE"]:
message = config["MESSAGES"][
randint(0, len(config["MESSAGES"]) - 1)
]
length = len(message) / randint(config["CPM"][0], config["CPM"][1]) * 60
async with original_message.channel.typing():
await sleep(length)
await original_message.channel.send(message)
logger.info(f"Sent message: {message}")
return
elif "appeared" in embed.title and not config["DISABLE_REDPACKET"]:
logger.debug("Redpacket detected, claiming...")
try:
button = tip_cc_message.components[0].children[0]
except IndexError:
logger.exception(
"Index error occurred, meaning the drop most likely ended, skipping..."
)
return
if "envelope" in button.label:
await button.click()
logger.info(
f"Claimed envelope in {original_message.channel.name} for {embed.description.split('**')[1]} {embed.description.split('**')[2].split(')')[0].replace(' (','')}"
)
if config["SEND_MESSAGE"]:
message = config["MESSAGES"][
randint(0, len(config["MESSAGES"]) - 1)
]
length = len(message) / randint(config["CPM"][0], config["CPM"][1]) * 60
async with original_message.channel.typing():
await sleep(length)
await original_message.channel.send(message)
logger.info(f"Sent message: {message}")
return
elif "Math" in embed.title and not config["DISABLE_MATHDROP"]:
logger.debug("Mathdrop detected, entering...")
content = embed.description.replace("\n", "").replace("**", "")
content = content.split("`")
try:
content = content[1].replace("", "").replace("\u200b", "")
except IndexError:
logger.exception("Index error occurred, skipping...")
pass
else:
logger.debug("Evaluating math and sending message...")
answer = eval(content)
if isinstance(answer, float) and answer.is_integer():
answer = int(answer)
logger.debug(f"Answer: {answer}")
if not config["SMART_DELAY"] and config["DELAY"] == 0:
length = len(str(answer)) / randint(config["CPM"][0], config["CPM"][1]) * 60
async with original_message.channel.typing():
await sleep(length)
await original_message.channel.send(answer)
logger.info(
f"Entered mathdrop in {original_message.channel.name} for {embed.description.split('**')[1]} {embed.description.split('**')[2].split(')')[0].replace(' (','')}"
)
if config["SEND_MESSAGE"]:
message = config["MESSAGES"][
randint(0, len(config["MESSAGES"]) - 1)
]
length = len(message) / randint(config["CPM"][0], config["CPM"][1]) * 60
async with original_message.channel.typing():
await sleep(length)
await original_message.channel.send(message)
logger.info(f"Sent message: {message}")
return
elif "Trivia time - " in embed.title and not config["DISABLE_TRIVIADROP"]:
logger.debug("Triviadrop detected, entering...")
category = embed.title.split("Trivia time - ")[1].strip()
bot_question = embed.description.replace("**", "").split("*")[1]
async with ClientSession() as session:
async with session.get(
f"https://raw.githubusercontent.com/QuartzWarrior/OTDB-Source/main/{quote(category)}.csv"
) as resp:
lines = (await resp.text()).splitlines()
for line in lines:
question, answer = line.split(",")
if bot_question.strip() == unquote(question).strip():
answer = unquote(answer).strip()
try:
buttons = tip_cc_message.components[0].children
except IndexError:
logger.exception(
"Index error occurred, meaning the drop most likely ended, skipping..."
)
return
for button in buttons:
if button.label.strip() == answer:
await button.click()
logger.info(
f"Entered triviadrop in {original_message.channel.name} for {embed.description.split('**')[1]} {embed.description.split('**')[2].split(')')[0].replace(' (','')}"
)
if config["SEND_MESSAGE"]:
message = config["MESSAGES"][
randint(0, len(config["MESSAGES"]) - 1)
]
length = len(message) / randint(config["CPM"][0], config["CPM"][1]) * 60
async with original_message.channel.typing():
await sleep(length)
await original_message.channel.send(message)
logger.info(f"Sent message: {message}")
return
except AttributeError:
logger.exception("Attribute error occurred")
return
except HTTPException:
logger.exception("HTTP exception occurred")
return
except NotFound:
logger.exception("Not found exception occurred")
return
elif original_message.content.startswith(
("$airdrop", "$triviadrop", "$mathdrop", "$phrasedrop", "$redpacket")
) and any(word in original_message.content.lower() for word in banned_words):
logger.info(
f"Banned word detected in {original_message.channel.name}, skipping..."
)
elif original_message.content.startswith(
("$airdrop", "$triviadrop", "$mathdrop", "$phrasedrop", "$redpacket")
) and (
config["WHITELIST_ON"] and original_message.guild.id not in config["WHITELIST"]
):
logger.info(
f"Whitelist enabled and drop not in whitelist, skipping {original_message.channel.name}..."
)
elif original_message.content.startswith(
("$airdrop", "$triviadrop", "$mathdrop", "$phrasedrop", "$redpacket")
) and (config["BLACKLIST_ON"] and original_message.guild.id in config["BLACKLIST"]):
logger.info(
f"Blacklist enabled and drop in blacklist, skipping {original_message.channel.name}..."
)
elif original_message.content.startswith(
("$airdrop", "$triviadrop", "$mathdrop", "$phrasedrop", "$redpacket")
) and (
config["CHANNEL_BLACKLIST_ON"]
and original_message.channel.id in config["CHANNEL_BLACKLIST"]
):
logger.info(
f"Channel blacklist enabled and drop in channel blacklist, skipping {original_message.channel.name}..."
)
elif (
original_message.content.startswith(
("$airdrop", "$triviadrop", "$mathdrop", "$phrasedrop", "$redpacket")
)
and original_message.author.id in config["IGNORE_USERS"]
):
logger.info(
f"User in ignore list detected in {original_message.channel.name}, skipping..."
)
if __name__ == "__main__":
try:
client.run(config["TOKEN"], log_handler=handler, log_formatter=formatter)
except LoginFailure:
logger.critical("Invalid token, restart the program.")
config["TOKEN"] = ""
with open("config.json", "w") as f:
dump(config, f, indent=4)