-
Notifications
You must be signed in to change notification settings - Fork 1
/
CartsManager.py
885 lines (829 loc) · 29.4 KB
/
CartsManager.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
"""
Hello and welcome to my code!
Before I begin, I want to make a couple disclaimers. A lot of waht I do in this program is considered
very rough around the edges and fairly brute force. For those of you developers looking at this,
I know that this program is not the cleanest, but I don't have the energy to completely redo it.
If you use this program, please give credit to me somehow.
Reach out to me on Discord:
Heroicos_HM#0310
"""
#These are the modules used by the program.
import asyncio
import time
import os
import random
import string
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import pymysql
import re
import logging
import traceback
import sys
import datetime
import json
global data, logs_channels
#Load all of the data from the configuration file.
with open("./Config.json") as file:
config = json.loads(file.read())
logs_channels = config['logs_channels']
data_file = config['data_file']
embed_color = config['embed_color']
footer_text = config['footer_text']
carts_original_channel = config['carts_original_channel']
carts_formatted_channel = config['carts_formatted_channel']
adi_table = config['adi_table']
latch_table = config['latch_table']
phantom_table = config['phantom_table']
balko_table = config['balko_table']
TOKEN = config['TOKEN']
db_ip = config['database_ip']
db_user = config['database_username']
db_pass = config['database_password']
db_name = config['database_name']
footer_icon = config['footer_icon_url']
online_message = config['online_message']
prefix = config['prefix']
#Get the start time for the uptime command.
start_time = time.time()
#Establish an initial connection to the database, and make sure the necessary tables exist.
conn = pymysql.connect(db_ip,user=db_user,passwd=db_pass,db=db_name,connect_timeout=30)
cur = conn.cursor(pymysql.cursors.DictCursor)
create_db = """CREATE TABLE IF NOT EXISTS """ + adi_table + """ (ID text, Title text, Link text, Email text, Password text, Size text, Desktop text, Mobile text, PID text, Thumbnail text, MessageID text, Timestamp text, Proxy text, HMAC text);"""
cur.execute(create_db)
create_db = """CREATE TABLE IF NOT EXISTS """ + latch_table + """ (ID text, Title text, Link text, Email text, Password text, Size text, Region text, PID text, Thumbnail text, MessageID text);"""
cur.execute(create_db)
create_db = """CREATE TABLE IF NOT EXISTS """ + phantom_table + """ (ID text, Title text, Description text, Name text, Size text, Profile text, Site text, Account text, MessageID text);"""
cur.execute(create_db)
create_db = """CREATE TABLE IF NOT EXISTS """ + balko_table + """ (ID text, Title text, Link text, Email text, Password text, Size text, Region text, PID text, Thumbnail text, MessageID text);"""
cur.execute(create_db)
conn.commit()
#Read information from data files (allows carts to persist through sudden shutdowns and restarts).
if os.path.isfile(data_file):
file = open(data_file).read()
if len(file) > 0:
data = json.loads(file)
print(data)
else:
data = {}
data['IsDeleting'], data['AdiSplashMessages'], data['LatchKeyMessages'], data['PhantomMessages'], data['BalkoMessages'] = [], [], [], [], []
else:
file = open(data_file, 'w+')
file.close()
data = {}
data['IsDeleting'], data['AdiSplashMessages'], data['LatchKeyMessages'], data['PhantomMessages'], data['BalkoMessages'] = [], [], [], [], []
file = open(data_file, 'w+')
file.write(json.dumps(data, indent=4, sort_keys=True))
file.close()
"""
A personal note..I always forget how to do this right so I have it in almost all my programs.
Writing data to json method:
file = open(data_file, 'w+')
file.write(json.dumps(data, indent=4, sort_keys=True))
file.close()
"""
#Create the Discord bot object.
Client = discord.Client()
bot = commands.Bot(command_prefix = "?")
#Triggers when the bot is ready to receive commands.
#This sends the online message.
@bot.event
async def on_ready():
print('Logged in as {0} and connected to Discord! (ID: {0.id})'.format(bot.user))
embed = discord.Embed(
title = online_message,
color = embed_color
)
embed.set_footer(
text = footer_text,
icon_url = footer_icon
)
if len(sys.argv) > 1:
await bot.send_message(discord.Object(id=sys.argv[1]), embed = embed)
else:
for log in logs_channels:
await bot.send_message(discord.Object(id=log), embed = embed)
#Triggers whenever a message is sent by anyone in a channel the bot can see.
@bot.event
async def on_message(message):
#Makes sure the cart is in a server.
if message.server:
#A little helper bit i put in to make sure things didn't break during the deletion of claimed carts.
if len(message.embeds) > 0 and 'title' in message.embeds[0].keys() and (message.embeds[0]['title'] == "**You must include a command.**" or message.embeds[0]['title'] == "**Unrecognized Command**" or message.embeds[0]['title'] == "**Insufficient Permissions**") and message not in data['IsDeleting']:
data['IsDeleting'].append(message)
await asyncio.sleep(15)
await bot.delete_message(message)
data['IsDeleting'].remove(message)
#Command to get the uptime of the bot. Can be used in any channel.
if message.content.upper().startswith(prefix + "UPTIME"):
now_time = time.time()
diff = int(now_time - start_time)
hour = int(diff / 3600)
diff = diff - (hour * 1600)
minutes = int(diff / 60)
if message.server:
await bot.delete_message(message)
await bot.send_typing(message.channel)
embed_time = discord.Embed(
title = "Bot Status: `ONLINE`",
description = "I have been online for {0} hours and {1} minutes on {2}.".format(hour, minutes, message.server),
color = embed_color,
timestamp = datetime.datetime.now(datetime.timezone.utc)
)
embed_time.set_thumbnail(
url = message.server.icon_url
)
else:
await bot.send_typing(message.author)
embed_time = discord.Embed(
title = "Bot Status: `ONLINE`",
description = "I have been online for {0} hours and {1} minutes.".format(hour, minutes),
color = embed_color,
timestamp = datetime.datetime.now(datetime.timezone.utc)
)
embed_time.set_thumbnail(
url = bot.user.avatar_url
)
embed_time.set_footer(
text = footer_text,
icon_url = footer_icon
)
if message.server:
await bot.send_message(message.channel, embed = embed_time)
else:
await bot.send_message(message.author, embed = embed_time)
#This whole chunk is what gets the carts from the private channel and sends it in the public channel.
if len(message.embeds) > 0:
#Establish database connection.
conn = pymysql.connect(db_ip,user=db_user,passwd=db_pass,db=db_name,connect_timeout=30)
cur = conn.cursor(pymysql.cursors.DictCursor)
#Make sure the message is in a carts channel.
if str(message.channel.id) == carts_original_channel and message.author.id != bot.user.id:
diction = message.embeds[0]
#Check to make sure it is an acceptable cart type.
if "AdiSplash" in str(message.embeds[0]['footer']['text']):
#Extract all of the information from the cart.
title = diction['title']
link = diction['url']
for item in diction['fields']:
if 'ACCOUNT DETAILS' in item['name']:
email = item['value'].split('\n')[0]
password = item['value'].split('\n')[1]
if 'SIZE' in item['name']:
size = item['value']
if 'DESKTOP' in item['name']:
desktop_link = item['value']
if 'MOBILE' in item['name']:
mobile_link = item['value']
if ('PRODUCT' in item['name']) or ('PID' in item['name']):
pid = item['value']
if 'PROXY' in item['name']:
proxy = item['value']
if 'TIMESTAMP' in item['name']:
timestamp = item['value']
if 'HMAC' in item['name']:
hmac = item['value']
try:
thumbnail = diction['thumbnail']['url']
except:
thumbnail = "N/A"
entry_number = str(len(data['LatchKeyMessages']) + len(data['AdiSplashMessages']) + len(data['PhantomMessages']) + len(data['BalkoMessages']) + 1)
message_id = message.id
#Insert all of that information into the database for that specific cart type.
insert_data = """INSERT INTO """ + adi_table + """ (ID, Title, Link, Email, Password, Size, Desktop, Mobile, PID, Thumbnail, MessageID, Timestamp, Proxy, HMAC) VALUES ('""" + entry_number + """', '""" + title + """', '""" + link + """', '""" + email + """', '""" + password + """', '""" + size + """', '""" + desktop_link + """', '""" + mobile_link + """', '""" + pid + """', '""" + thumbnail + """','""" + message_id + """', '""" + timestamp + """', '""" + proxy + """', '""" + hmac + """');"""
cur.execute(insert_data)
conn.commit()
#Send the reformatted cart into the public cart channel.
embed = discord.Embed(
title = title,
url = "https://www.google.com/search?q=" + pid,
color = embed_color,
timestamp = datetime.datetime.now(datetime.timezone.utc)
)
embed.add_field(
name = "**PRODUCT ID**",
value = pid
)
embed.add_field(
name = "**SIZE**",
value = size
)
embed.add_field(
name = "**TIMESTAMP**",
value = timestamp
)
if thumbnail != "N/A":
embed.set_thumbnail(
url = thumbnail
)
else:
embed.set_thumbnail(
url = bot.user.avatar_url
)
embed.set_footer(
text = "{} | Cart #{}".format(footer_text, entry_number),
icon_url = bot.user.avatar_url
)
r = await bot.send_message(discord.Object(id=carts_formatted_channel), embed = embed)
data['AdiSplashMessages'].append(r.id)
file = open(data_file, 'w+')
file.write(json.dumps(data, indent=4, sort_keys=True))
file.close()
#Repeat, but for Latchkey.
elif "LatchKey" in str(message.embeds[0]['footer']['text']):
title = diction['title']
link = diction['url']
for item in diction['fields']:
if 'Region' in item['name']:
region = item['value']
if ('Product ID' or 'PID') in item['name']:
pid = item['value']
if 'Size' in item['name']:
size = item['value']
if 'Email' in item['name']:
email = item['value']
if 'Password' in item['name']:
password = item['value']
if 'Cart Expires' in item['name']:
expiry = item['value']
try:
thumbnail = diction['thumbnail']['url']
except:
thumbnail = "N/A"
entry_number = str(len(data['LatchKeyMessages']) + len(data['AdiSplashMessages']) + len(data['PhantomMessages']) + len(data['BalkoMessages']) + 1)
message_id = message.id
insert_data = """INSERT INTO """ + latch_table + """ (ID, Title, Link, Email, Password, Size, Region, PID, Thumbnail, MessageID) VALUES ('""" + entry_number + """', '""" + title + """', '""" + link + """', '""" + email + """', '""" + password + """', '""" + size + """', '""" + region + """', '""" + pid + """', '""" + thumbnail + """','""" + message_id + """');"""
cur.execute(insert_data)
conn.commit()
embed = discord.Embed(
title = title,
url = "https://www.google.com/search?q=" + pid,
color = embed_color,
timestamp = datetime.datetime.now(datetime.timezone.utc)
)
embed.add_field(
name = "**PRODUCT ID**",
value = pid
)
embed.add_field(
name = "**SIZE**",
value = size
)
embed.add_field(
name = "**Cart Expires**",
value = expiry
)
if thumbnail != "N/A":
embed.set_thumbnail(
url = thumbnail
)
else:
embed.set_thumbnail(
url = bot.user.avatar_url
)
embed.set_footer(
text = "{} | Cart #{}".format(footer_text, entry_number),
icon_url = bot.user.avatar_url
)
r = await bot.send_message(discord.Object(id=carts_formatted_channel), embed = embed)
data['LatchKeyMessages'].append(r.id)
file = open(data_file, 'w+')
file.write(json.dumps(data, indent=4, sort_keys=True))
file.close()
#Repeat, but for Phatom.
elif "Phantom" in str(message.embeds[0]['footer']['text']):
title = diction['title']
description = diction['description']
for item in diction['fields']:
if 'Item' in item['name']:
name = item['value']
elif 'Size' in item['name']:
size = item['value']
elif 'Profile' in item['name']:
profile = item['value']
elif 'Site' in item['name']:
site = item['value']
elif 'Account' in item['name']:
account = item['value']
entry_number = str(len(data['LatchKeyMessages']) + len(data['AdiSplashMessages']) + len(data['PhantomMessages']) + len(data['BalkoMessages']) + 1)
message_id = message.id
insert_data = """INSERT INTO """ + phantom_table + """ (ID, Title, Description, Name, Size, Profile, Site, Account, MessageID) VALUES ('""" + entry_number + """', '""" + title + """', '""" + description + """', '""" + name + """', '""" + size + """', '""" + profile + """', '""" + site + """', '""" + account + """','""" + message_id + """');"""
cur.execute(insert_data)
conn.commit()
embed = discord.Embed(
title = title,
description = description,
color = embed_color,
timestamp = datetime.datetime.now(datetime.timezone.utc)
)
embed.add_field(
name = "**Item**",
value = name
)
embed.add_field(
name = "**Size**",
value = size
)
embed.add_field(
name = "**Site**",
value = site
)
embed.set_footer(
text = "{} | Cart #{}".format(footer_text, entry_number),
icon_url = bot.user.avatar_url
)
r = await bot.send_message(discord.Object(id=carts_formatted_channel), embed = embed)
data['PhantomMessages'].append(r.id)
file = open(data_file, 'w+')
file.write(json.dumps(data, indent=4, sort_keys=True))
file.close()
#Repeat, but for Balkobot.
elif "Balkobot" in str(message.embeds[0]['footer']['text']):
title = diction['title']
url = diction['url']
for item in diction['fields']:
if 'Email' in item['name']:
email = item['value']
elif 'Password' in item['name']:
password = item['value']
elif 'Size' in item['name']:
size = item['value']
elif 'Site' in item['name']:
site = item['value']
elif 'Region' in item['name']:
region = item['value']
elif 'PID' in item['name']:
pid = item['value']
try:
thumbnail = diction['thumbnail']['url']
except:
thumbnail = "N/A"
entry_number = str(len(data['LatchKeyMessages']) + len(data['AdiSplashMessages']) + len(data['PhantomMessages']) + len(data['BalkoMessages']) + 1)
message_id = message.id
insert_data = """INSERT INTO """ + balko_table + """ (ID, Title, Link, Email, Password, Size, Region, PID, Thumbnail, MessageID) VALUES ('""" + entry_number + """', '""" + title + """', '""" + url + """', '""" + email + """', '""" + password + """', '""" + size + """', '""" + region + """', '""" + pid + """', '""" + thumbnail + """', '""" + message_id + """');"""
cur.execute(insert_data)
conn.commit()
embed = discord.Embed(
title = title,
url = url,
color = embed_color,
timestamp = datetime.datetime.now(datetime.timezone.utc)
)
embed.add_field(
name = "**Size**",
value = size
)
embed.add_field(
name = "**Region**",
value = region
)
embed.add_field(
name = "**PID**",
value = pid
)
embed.set_footer(
text = "{} | Cart #{}".format(footer_text, entry_number),
icon_url = bot.user.avatar_url
)
if thumbnail != "N/A":
embed.set_thumbnail(
url = thumbnail
)
else:
embed.set_thumbnail(
url = bot.user.avatar_url
)
r = await bot.send_message(discord.Object(id=carts_formatted_channel), embed = embed)
data['BalkoMessages'].append(r.id)
file = open(data_file, 'w+')
file.write(json.dumps(data, indent=4, sort_keys=True))
file.close()
#Add the intial reaction from the bot to make it clear what reaction people will add to claim the cart.
elif str(message.channel.id) == carts_formatted_channel and message.author.id == bot.user.id:
await bot.add_reaction(message, "🛒")
else:
pass
#This chunk will handle claiming the carts.
@bot.event
async def on_socket_raw_receive(the_reaction):
#Gets the event and makes sure it is a reaction that was added.
if not isinstance(the_reaction, str):
return
reaction = json.loads(the_reaction)
type = reaction.get("t")
dat = reaction.get("d")
if not dat:
return
if type == "MESSAGE_REACTION_ADD":
emoji = dat.get("emoji")
user_id = dat.get("user_id")
message_id = dat.get("message_id")
channel_id = dat.get("channel_id")
global data
#Makes sure the bot isnt allowed to claim the cart.
if user_id == bot.user.id:
pass
#Checks if the message the reaction was added to is a valid cart to react to.
elif message_id in data['AdiSplashMessages']:
#Immediately mark the cart as claimed, or rather, no longer *not* claimed.
data['AdiSplashMessages'].remove(message_id)
#Establish DB connection
conn = pymysql.connect(db_ip,user=db_user,passwd=db_pass,db=db_name,connect_timeout=30)
cur = conn.cursor(pymysql.cursors.DictCursor)
file = open(data_file, 'w+')
file.write(json.dumps(data, indent=4, sort_keys=True))
file.close()
channel = channel_id
#Get cart information and create a message with the information.
if str(channel) == carts_formatted_channel:
my_channel = bot.get_channel(channel_id)
message = await bot.get_message(my_channel, message_id)
await bot.clear_reactions(message)
diction = message.embeds[0]
cart_text = diction['footer']['text']
cart_number = int(re.search(r'\d+', cart_text).group(0))
sql = """SELECT * FROM """ + adi_table + """ WHERE ID = %s""" % cart_number
cur.execute(sql)
cart_info = cur.fetchall()[0]
cart_id = cart_info['ID']
cart_title = cart_info['Title']
cart_link = cart_info['Link']
cart_email = cart_info['Email']
cart_pass = cart_info['Password']
cart_size = cart_info['Size']
cart_desktop = cart_info['Desktop']
cart_mobile = cart_info['Mobile']
cart_pid = cart_info['PID']
cart_thumbnail = cart_info['Thumbnail']
cart_discord_link = cart_info['MessageID']
cart_proxy = cart_info['Proxy']
cart_hmac = cart_info['HMAC']
cart_timestamp = cart_info['Timestamp']
#Create message with the information extracted from the database.
embed = discord.Embed(
title = cart_title,
url = cart_link,
color = embed_color,
timestamp = datetime.datetime.now(datetime.timezone.utc)
)
embed.add_field(
name = "**PRODUCT**",
value = cart_pid,
inline = True
)
embed.add_field(
name = "**SIZE**",
value = cart_size,
inline = True
)
embed.add_field(
name = "**ACCOUNT DETAILS**",
value = cart_email + "\n" + cart_pass,
inline = False
)
embed.add_field(
name = "**DESKTOP**",
value = cart_desktop,
inline = False
)
embed.add_field(
name = "**MOBILE**",
value = cart_mobile,
inline = True
)
embed.add_field(
name = "**HMAC**",
value = cart_hmac,
inline = False
)
embed.add_field(
name = "**PROXY**",
value = cart_proxy,
inline = False
)
embed.add_field(
name = "**TIMESTAMP**",
value = cart_timestamp,
inline = False
)
embed.set_footer(
text = "{} | Cart #{}".format(footer_text, cart_id),
icon_url = bot.user.avatar_url
)
if cart_thumbnail == "N/A":
embed.set_thumbnail(
url = bot.user.avatar_url
)
else:
embed.set_thumbnail(
url = cart_thumbnail
)
sql = """DELETE FROM """ + adi_table + """ WHERE ID = %s""" % cart_number
cur.execute(sql)
conn.commit()
server = message.server
author = server.get_member(user_id)
#Send the full cart directly to the user.
await bot.send_message(author, embed = embed)
user = await bot.get_user_info(user_id)
new_title = "Cart Claimed!"
new_link = diction['url']
new_footer_text = "%s | Claimed by %s" % (bot.user.name, user.name)
new_footer_icon_url = diction['footer']['icon_url']
try:
new_thumbnail = diction['thumbnail']['url']
except:
new_thumbnail = "N/A"
#Edit the public cart to show that it was claimed by someone and is no longer available.
new_embed = discord.Embed(
title = new_title,
url = new_link,
description = "*This cart was claimed by `%s` and is no longer available.*" % user.name,
color = embed_color,
timestamp = datetime.datetime.now(datetime.timezone.utc)
)
new_embed.set_footer(
text = new_footer_text,
icon_url = new_footer_icon_url
)
await bot.edit_message(message, embed = new_embed)
else:
pass
#Repeat for Latchkey.
elif message_id in data['LatchKeyMessages']:
data['LatchKeyMessages'].remove(message_id)
conn = pymysql.connect(db_ip,user=db_user,passwd=db_pass,db=db_name,connect_timeout=30)
cur = conn.cursor(pymysql.cursors.DictCursor)
file = open(data_file, 'w+')
file.write(json.dumps(data, indent=4, sort_keys=True))
file.close()
channel = channel_id
if str(channel) == carts_formatted_channel:
my_channel = bot.get_channel(channel_id)
message = await bot.get_message(my_channel, message_id)
await bot.clear_reactions(message)
diction = message.embeds[0]
cart_text = diction['footer']['text']
cart_number = int(re.search(r'\d+', cart_text).group(0))
sql = """SELECT * FROM """ + latch_table + """ WHERE ID = %s""" % cart_number
cur.execute(sql)
cart_info = cur.fetchall()[0]
cart_id = cart_info['ID']
cart_title = cart_info['Title']
cart_link = cart_info['Link']
cart_email = cart_info['Email']
cart_pass = cart_info['Password']
cart_size = cart_info['Size']
cart_region = cart_info['Region']
cart_pid = cart_info['PID']
cart_thumbnail = cart_info['Thumbnail']
cart_discord_link = cart_info['MessageID']
embed = discord.Embed(
title = cart_title,
url = cart_link,
color = embed_color,
timestamp = datetime.datetime.now(datetime.timezone.utc)
)
embed.add_field(
name = "Region",
value = cart_region,
inline = True
)
embed.add_field(
name = "Product ID",
value = cart_pid,
inline = True
)
embed.add_field(
name = "Size",
value = cart_size,
inline = True
)
embed.add_field(
name = "Account Details",
value = "||" + cart_email + "||\n||" + cart_pass + "||",
inline = True
)
embed.set_footer(
text = "{} | Cart #{}".format(footer_text, cart_id),
icon_url = bot.user.avatar_url
)
if cart_thumbnail == "N/A":
embed.set_thumbnail(
url = bot.user.avatar_url
)
else:
embed.set_thumbnail(
url = cart_thumbnail
)
sql = """DELETE FROM """ + latch_table + """ WHERE ID = %s""" % cart_number
cur.execute(sql)
conn.commit()
server = message.server
author = server.get_member(user_id)
await bot.send_message(author, embed = embed)
user = await bot.get_user_info(user_id)
new_title = "Cart Claimed!"
new_link = diction['url']
new_footer_text = "%s | Claimed by %s" % (footer_text, user.name)
new_footer_icon_url = diction['footer']['icon_url']
try:
new_thumbnail = diction['thumbnail']['url']
except:
new_thumbnail = "N/A"
new_embed = discord.Embed(
title = new_title,
url = new_link,
description = "*This cart was claimed by `%s` and is no longer available.*" % user.name,
color = embed_color,
timestamp = datetime.datetime.now(datetime.timezone.utc)
)
new_embed.set_footer(
text = new_footer_text,
icon_url = new_footer_icon_url
)
await bot.edit_message(message, embed = new_embed)
else:
pass
#Repeat for Phantom.
elif message_id in data['PhantomMessages']:
data['PhantomMessages'].remove(message_id)
conn = pymysql.connect(db_ip,user=db_user,passwd=db_pass,db=db_name,connect_timeout=30)
cur = conn.cursor(pymysql.cursors.DictCursor)
file = open(data_file, 'w+')
file.write(json.dumps(data, indent=4, sort_keys=True))
file.close()
channel = channel_id
if str(channel) == carts_formatted_channel:
my_channel = bot.get_channel(channel_id)
message = await bot.get_message(my_channel, message_id)
await bot.clear_reactions(message)
diction = message.embeds[0]
cart_text = diction['footer']['text']
cart_number = int(re.search(r'\d+', cart_text).group(0))
sql = """SELECT * FROM """ + phantom_table + """ WHERE ID = %s""" % cart_number
cur.execute(sql)
cart_info = cur.fetchall()[0]
cart_id = cart_info['ID']
cart_title = cart_info['Title']
cart_description = cart_info['Description']
cart_name = cart_info['Name']
cart_size = cart_info['Size']
cart_profile = cart_info['Profile']
cart_site = cart_info['Site']
cart_account = cart_info['Account']
cart_discord_link = cart_info['MessageID']
embed = discord.Embed(
title = cart_title,
description = cart_description,
color = embed_color,
timestamp = datetime.datetime.now(datetime.timezone.utc)
)
embed.add_field(
name = "Item",
value = cart_name
)
embed.add_field(
name = "Size",
value = cart_size
)
embed.add_field(
name = "Profile",
value = cart_profile
)
embed.add_field(
name = "Site",
value = cart_site
)
embed.add_field(
name = "Account",
value = cart_account
)
embed.set_footer(
text = "{} | Cart #{}".format(footer_text, cart_id),
icon_url = bot.user.avatar_url
)
sql = """DELETE FROM """ + phantom_table + """ WHERE ID = %s""" % cart_number
cur.execute(sql)
conn.commit()
server = message.server
author = server.get_member(user_id)
await bot.send_message(author, embed = embed)
user = await bot.get_user_info(user_id)
new_title = "Cart Claimed!"
new_footer_text = "%s | Claimed by %s" % (footer_text, user.name)
new_footer_icon_url = diction['footer']['icon_url']
try:
new_thumbnail = diction['thumbnail']['url']
except:
new_thumbnail = "N/A"
new_embed = discord.Embed(
title = new_title,
description = "*This cart was claimed by `%s` and is no longer available.*" % user.name,
color = embed_color,
timestamp = datetime.datetime.now(datetime.timezone.utc)
)
new_embed.set_footer(
text = new_footer_text,
icon_url = new_footer_icon_url
)
await bot.edit_message(message, embed = new_embed)
else:
pass
#Repeat for Balkobot.
elif message_id in data['BalkoMessages']:
data['BalkoMessages'].remove(message_id)
conn = pymysql.connect(db_ip,user=db_user,passwd=db_pass,db=db_name,connect_timeout=30)
cur = conn.cursor(pymysql.cursors.DictCursor)
file = open(data_file, 'w+')
file.write(json.dumps(data, indent=4, sort_keys=True))
file.close()
channel = channel_id
if str(channel) == carts_formatted_channel:
my_channel = bot.get_channel(channel_id)
message = await bot.get_message(my_channel, message_id)
await bot.clear_reactions(message)
diction = message.embeds[0]
cart_text = diction['footer']['text']
cart_number = int(re.search(r'\d+', cart_text).group(0))
sql = """SELECT * FROM """ + balko_table + """ WHERE ID = %s""" % cart_number
cur.execute(sql)
cart_info = cur.fetchall()[0]
cart_id = cart_info['ID']
cart_title = cart_info['Title']
cart_link = cart_info['Link']
cart_email = cart_info['Email']
cart_pass = cart_info['Password']
cart_size = cart_info['Size']
cart_region = cart_info['Region']
cart_pid = cart_info['PID']
cart_thumbnail = cart_info['Thumbnail']
cart_discord_link = cart_info['MessageID']
embed = discord.Embed(
title = cart_title,
url = cart_link,
color = embed_color,
timestamp = datetime.datetime.now(datetime.timezone.utc)
)
embed.add_field(
name = "Account Details",
value = "Email: ||" + cart_email + "||\nPassword: ||" + cart_pass + "||"
)
embed.add_field(
name = "Region",
value = cart_region
)
embed.add_field(
name = "Product ID",
value = cart_pid
)
embed.add_field(
name = "Size",
value = cart_size
)
embed.set_footer(
text = "{} | Cart #{}".format(footer_text, cart_id),
icon_url = bot.user.avatar_url
)
if cart_thumbnail == "N/A":
embed.set_thumbnail(
url = bot.user.avatar_url
)
else:
embed.set_thumbnail(
url = cart_thumbnail
)
sql = """DELETE FROM """ + balko_table + """ WHERE ID = %s""" % cart_number
cur.execute(sql)
conn.commit()
server = message.server
author = server.get_member(user_id)
await bot.send_message(author, embed = embed)
user = await bot.get_user_info(user_id)
new_title = "Cart Claimed!"
new_link = diction['url']
new_footer_text = "%s | Claimed by %s" % (footer_text, user.name)
new_footer_icon_url = diction['footer']['icon_url']
try:
new_thumbnail = diction['thumbnail']['url']
except:
new_thumbnail = "N/A"
new_embed = discord.Embed(
title = new_title,
url = new_link,
description = "*This cart was claimed by `%s` and is no longer available.*" % user.name,
color = embed_color,
timestamp = datetime.datetime.now(datetime.timezone.utc)
)
new_embed.set_footer(
text = new_footer_text,
icon_url = new_footer_icon_url
)
await bot.edit_message(message, embed = new_embed)
else:
pass
else:
pass
#Actuallly start the dang bot.
bot.run(TOKEN)