-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
937 lines (736 loc) · 38 KB
/
Copy pathmain.py
File metadata and controls
937 lines (736 loc) · 38 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
import discord
import random
import string
import json
import asyncio
import os
import qrcode
import configparser
import io
import psutil
import datetime
from discord.ext import commands
from utils import *
import chat_exporter
import platform
config = configparser.ConfigParser()
config.read('config.ini')
embed_color = int(config['EmbedSettings']['embed_color'], 16)
footer_text = config['EmbedSettings']['footer_text']
icon_url = config['EmbedSettings']['icon_url']
thumbnail_url = config['EmbedSettings']['thumbnail_url']
loading_url = config['EmbedSettings']['loading_url']
ltc_image = config['EmbedSettings']['ltc_image']
tick_image = config['EmbedSettings']['tick_image']
TATUM_APIKEY = config['APIKeys']['TATUM_APIKEY']
mm_log_channel_id = int(config['ChannelSettings']['mm_log_channel_id'])
category_id = int(config['ChannelSettings']['category_id'])
admin_role_id = int(config['RoleSettings']['admin_role_id'])
show_buyer_seller = config.getboolean('DisplaySettings', 'show_buyer_seller')
start_time = datetime.datetime.now()
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='/', intents=intents)
@bot.event
async def on_ready():
bot.add_view(PersistentCreateTicket())
print(f'connected to {bot.user}!')
await bot.tree.sync()
@bot.tree.command(name='automm-panel', description='Displays the automm panel embed')
async def ticket_panel(interaction: discord.Interaction):
await interaction.response.defer()
member = interaction.user
guild = interaction.guild
required_role = discord.utils.get(guild.roles, id=admin_role_id)
if required_role not in member.roles:
return
embed = discord.Embed(
title="Auto MM",
description="- Safe & Easy\n- No Fees\n- Available 24/7\n- Supports LTC only",
color=embed_color
)
embed.set_footer(text=footer_text, icon_url=icon_url)
embed.set_thumbnail(url=thumbnail_url)
view = PersistentCreateTicket()
await interaction.channel.send(embed=embed, view=view)
class PersistentCreateTicket(discord.ui.View):
def __init__(self):
super().__init__(timeout=None)
@discord.ui.button(label="Create Auto MM", style=discord.ButtonStyle.grey, custom_id="CreateTicket")
async def create_button(self, interaction: discord.Interaction, button: discord.ui.Button):
modal = UserIdModal()
await interaction.response.send_modal(modal)
class UserIdModal(discord.ui.Modal):
def __init__(self):
super().__init__(title="User ID Input")
self.user_id = discord.ui.TextInput(label="Enter the User ID you are dealing with:", required=True)
self.add_item(self.user_id)
async def on_submit(self, interaction: discord.Interaction):
await interaction.response.defer()
user_id = self.user_id.value
user = interaction.guild.get_member(int(user_id))
if user is None:
await interaction.followup.send("The user id is invalid/not in the server.", ephemeral=True)
return
deal_id = ''.join(random.choices(string.ascii_uppercase + string.digits, k=7))
category = interaction.guild.get_channel(category_id)
if category is None or not isinstance(category, discord.CategoryChannel):
await interaction.followup.send("Category ID is invalid, please contact a staff member!", ephemeral=True)
return
new_channel = await interaction.guild.create_text_channel(
name=f"automm-{interaction.user.name}",
category=category
)
await new_channel.set_permissions(interaction.guild.default_role, read_messages=False)
await new_channel.set_permissions(interaction.user, read_messages=True, send_messages=True)
await new_channel.set_permissions(user, read_messages=True, send_messages=True)
await new_channel.edit(topic=f"{deal_id}")
deal_info = {
"deal_id": deal_id,
"channel_id": new_channel.id,
"buyer": None,
"seller": None,
"deal_amount_usd": None,
"amount_in_ltc": None,
"timestamp": interaction.created_at.isoformat(),
}
data = load_data()
data[deal_id] = deal_info
save_data(data)
embed = discord.Embed(
title="AUTO MM",
description=f"||Deal ID: {deal_id}||\n\nTo start, identify the buyer & seller by selecting the appropriate buttons below. Press the Next button to proceed.",
color=embed_color
)
embed.set_footer(text=footer_text, icon_url=icon_url)
embed.set_thumbnail(url=thumbnail_url)
await new_channel.send(embed=embed)
embed = discord.Embed(
title="Choose Your Role:",
color=embed_color
)
embed.add_field(name="Seller:", value=f"None", inline=True)
embed.add_field(name="Buyer:", value=f"None")
embed.set_footer(text=footer_text, icon_url=icon_url)
embed.set_thumbnail(url=thumbnail_url)
view = RoleSelectorView(creator=interaction.user, other_user=user)
await new_channel.send(embed=embed, view=view)
await interaction.followup.send(f"Ticket created: {new_channel.mention}", ephemeral=True)
class RoleSelectorView(discord.ui.View):
def __init__(self, creator: discord.Member, other_user: discord.Member):
super().__init__(timeout=None)
self.creator = creator
self.other_user = other_user
self.buyer = None
self.seller = None
async def get_deal_id(self, interaction: discord.Interaction):
return interaction.channel.topic
def save_to_json(self, deal_id: str, buyer_id: int, seller_id: int):
file_path = 'Database/Data.json'
with open(file_path, 'r') as f:
data = json.load(f)
if deal_id in data:
data[deal_id]['buyer'] = buyer_id
data[deal_id]['seller'] = seller_id
with open(file_path, 'w') as f:
json.dump(data, f, indent=4)
@discord.ui.button(label="Seller", style=discord.ButtonStyle.gray)
async def seller_button(self, interaction: discord.Interaction, button: discord.ui.Button):
if self.buyer and interaction.user.id == self.buyer.id:
await interaction.response.send_message("You cannot select yourself as both buyer and seller.", ephemeral=True)
return
self.seller = interaction.user
self.buyer = self.other_user if interaction.user == self.creator else self.creator
await self.update_roles(interaction)
@discord.ui.button(label="Buyer", style=discord.ButtonStyle.gray)
async def buyer_button(self, interaction: discord.Interaction, button: discord.ui.Button):
if self.seller and interaction.user.id == self.seller.id:
await interaction.response.send_message("You cannot select yourself as both buyer and seller.", ephemeral=True)
return
self.buyer = interaction.user
self.seller = self.other_user if interaction.user == self.creator else self.creator
await self.update_roles(interaction)
@discord.ui.button(label="Confirm", style=discord.ButtonStyle.green)
async def confirm_button(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.defer()
if not self.buyer or not self.seller:
await interaction.followup.send("Both buyer and seller need to be selected before confirming.", ephemeral=True)
return
for child in self.children:
child.disabled = True
await interaction.message.edit(view=self)
deal_id = await self.get_deal_id(interaction)
self.save_to_json(deal_id, self.buyer.id, self.seller.id)
await interaction.followup.send("Roles confirmed!", ephemeral=True)
embed = discord.Embed(
title="Set Deal Details",
description=f"{self.seller.mention}, please click the button below to enter the deal amount and select the currency.",
color=0xffff00
)
view = SetDealDetailsView(self.buyer, self.seller)
await interaction.channel.send(embed=embed, view=view)
@discord.ui.button(label="Cancel", style=discord.ButtonStyle.red)
async def cancel_button(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.defer()
for child in self.children:
child.disabled = True
await interaction.message.edit(view=self)
embed = discord.Embed(
title="Transaction Cancelled",
description="This transaction has been cancelled. The channel will be deleted in 15 seconds.",
color=discord.Color.red()
)
await interaction.followup.send(embed=embed)
await asyncio.sleep(15)
await interaction.channel.delete()
async def update_roles(self, interaction: discord.Interaction):
embed = interaction.message.embeds[0]
embed.clear_fields()
seller_mention = self.seller.mention if self.seller else "None"
buyer_mention = self.buyer.mention if self.buyer else "None"
embed.add_field(name="Seller Role", value=seller_mention, inline=False)
embed.add_field(name="Buyer Role", value=buyer_mention, inline=False)
await interaction.message.edit(embed=embed)
await interaction.response.send_message(f"Roles updated:\nBuyer: {buyer_mention}\nSeller: {seller_mention}", ephemeral=True)
class SetDealDetailsView(discord.ui.View):
def __init__(self, buyer: discord.Member, seller: discord.Member):
super().__init__(timeout=None)
self.buyer = buyer
self.seller = seller
@discord.ui.button(label="Set Deal Amount & Currency", style=discord.ButtonStyle.primary)
async def set_details_button(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user != self.seller:
await interaction.response.send_message("Only the seller can set the deal details.", ephemeral=True)
return
modal = SetDealDetailsModal(self.buyer, self.seller, self)
await interaction.response.send_modal(modal)
class SetDealDetailsModal(discord.ui.Modal):
def __init__(self, buyer: discord.Member, seller: discord.Member, parent_view: discord.ui.View):
super().__init__(title="Enter Deal Details")
self.buyer = buyer
self.seller = seller
self.parent_view = parent_view
self.amount_input = discord.ui.TextInput(
label="Deal Amount (e.g., 50.00)",
placeholder="Enter the transaction amount",
required=True
)
self.currency_input = discord.ui.TextInput(
label="Currency (e.g., USD, EUR, GBP)",
placeholder="USD",
default="USD",
required=False,
max_length=5
)
self.add_item(self.amount_input)
self.add_item(self.currency_input)
async def on_submit(self, interaction: discord.Interaction):
await interaction.response.defer()
raw_amount = self.amount_input.value
raw_currency = self.currency_input.value or "USD"
try:
amount = parse_amount(raw_amount)
except ValueError as e:
await interaction.followup.send(f"❌ Invalid amount: {str(e)}. Please click the button and try again.", ephemeral=True)
return
currency = raw_currency.upper().strip()
try:
get_ltc_to_currency_exchange_rate(currency)
except Exception as e:
await interaction.followup.send(f"❌ Currency '{currency}' is not supported or API error: {str(e)}. Please click the button and try again.", ephemeral=True)
return
for child in self.parent_view.children:
child.disabled = True
await interaction.message.edit(view=self.parent_view)
confirmation_embed = discord.Embed(
title="Deal Details Confirmation",
description=f"- Amount : **{amount:.2f} {currency}**\n\n- Accept or Reject the deal.",
color=embed_color
)
confirmation_embed.set_footer(text=footer_text, icon_url=icon_url)
confirmation_embed.set_thumbnail(url=thumbnail_url)
view = DealConfirmationView(self.buyer, self.seller, amount, currency)
await interaction.channel.send(f"{self.buyer.mention}", embed=confirmation_embed, view=view)
class DealConfirmationView(discord.ui.View):
def __init__(self, buyer, seller, amount, currency="USD"):
super().__init__(timeout=None)
self.buyer = buyer
self.seller = seller
self.amount = amount # This is the fiat amount
self.currency = currency
self.dealid = None
self.confirmed = False
self.ltc_wallet_address = None
self.payment_channel = None
self.pending_sent = False
self.pending_detected = False
async def check_balance(self, ltc_wallet_address2):
max_checks = 50
check_count = 0
while check_count < max_checks or self.pending_detected:
balance_data = get_ltc_balance(ltc_wallet_address2)
if balance_data:
incoming = float(balance_data["incoming"])
incoming_pending = float(balance_data["incomingPending"])
ltc_to_currency = get_ltc_to_currency_exchange_rate(self.currency)
if incoming_pending > 0 and not self.pending_detected:
pending_amount_fiat = incoming_pending * ltc_to_currency
pending_embed = discord.Embed(
title="Pending Payment Detected",
description=(
f"> A Pending Transaction Is Detected.\n\n"
f"- {pending_amount_fiat:.2f} {self.currency} ({incoming_pending:.4f} LTC)"
),
color=embed_color
)
pending_embed.set_footer(text=f"{footer_text} • Awaiting confirmation", icon_url=icon_url)
pending_embed.set_thumbnail(url=loading_url)
await self.payment_channel.send(embed=pending_embed)
self.pending_detected = True
self.pending_sent = True
if self.pending_detected and incoming_pending == 0 and incoming > 0:
confirmed_amount_fiat = incoming * ltc_to_currency
confirmed_embed = discord.Embed(
title="Payment Received",
description=(
f"> The Pending Transaction Is Now Confirmed.\n\n"
f"- **{confirmed_amount_fiat:.2f} {self.currency} ({incoming:.4f} LTC)**\n\n"
),
color=0x00FF00
)
view = PaymentActionView(buyer=self.buyer, seller=self.seller, amount=incoming, currency=self.currency, original_fiat_amount=confirmed_amount_fiat)
confirmed_embed.set_footer(text=f"{footer_text} • Payment Confirmed", icon_url=icon_url)
confirmed_embed.set_thumbnail(url=tick_image)
database_folder = "Database"
data_file = os.path.join(database_folder, "Data.json")
os.makedirs(database_folder, exist_ok=True)
if os.path.exists(data_file):
with open(data_file, 'r') as file:
data = json.load(file)
else:
data = {}
ltc_to_usd = get_ltc_to_usd_exchange_rate()
confirmed_amount_usd = incoming * ltc_to_usd
if self.dealid in data:
data[self.dealid]["received_amount_ltc"] = incoming
data[self.dealid]["received_amount_usd"] = confirmed_amount_usd
data[self.dealid]["received_amount_fiat"] = confirmed_amount_fiat
data[self.dealid]["received_currency"] = self.currency
with open(data_file, 'w') as file:
json.dump(data, file, indent=4)
await self.payment_channel.send(embed=confirmed_embed, view=view)
break
if not self.pending_detected:
check_count += 1
await asyncio.sleep(15)
if check_count >= max_checks and not self.pending_detected:
timeout_embed = discord.Embed(
title="Payment Not Detected",
description="Payment was not detected after multiple checks. Closing the ticket.",
color=discord.Color.red()
)
timeout_embed.set_footer(text=footer_text, icon_url=icon_url)
timeout_embed.set_thumbnail(url=thumbnail_url)
await self.payment_channel.send(embed=timeout_embed)
@discord.ui.button(label="Accept", style=discord.ButtonStyle.green)
async def accept_button(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user != self.buyer:
await interaction.response.send_message("Only the buyer can accept the deal.", ephemeral=True)
return
self.payment_channel = interaction.channel
self.confirmed = True
for child in self.children:
child.disabled = True
await interaction.message.edit(view=self)
confirmation_embed = interaction.message.embeds[0]
confirmation_embed.set_footer(text=f"Deal accepted by {self.buyer.display_name}")
await interaction.message.edit(embed=confirmation_embed)
ltc_wallet_address, private_key = create_new_ltc_address()
ltc_to_currency = get_ltc_to_currency_exchange_rate(self.currency)
ltc_amount = self.amount / ltc_to_currency
ltc_to_usd = get_ltc_to_usd_exchange_rate()
usd_amount = ltc_amount * ltc_to_usd
store_deal_data(interaction.channel.topic, ltc_wallet_address, private_key, ltc_amount, usd_amount, self.amount, self.currency)
self.dealid = interaction.channel.topic
payment_embed = discord.Embed(
title="Waiting For Payment",
description=(
f"> Payment Credentials Are Given Below :\n\n"
f"- **Address:** `{ltc_wallet_address}`\n"
f"- **Amount to pay:** **{ltc_amount:.4f} LTC**\n\n"
"> Your Payment Will Be Detected Automatically"
),
color=embed_color
)
payment_embed.set_footer(text=footer_text, icon_url=icon_url)
payment_embed.set_thumbnail(url=ltc_image)
view = PaymentEmbedView(ltc_wallet_address, ltc_amount)
await interaction.channel.send(embed=payment_embed, view=view)
asyncio.create_task(self.check_balance(ltc_wallet_address))
@discord.ui.button(label="Reject", style=discord.ButtonStyle.red)
async def reject_button(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user != self.buyer:
await interaction.response.send_message("Only the buyer can reject the deal.", ephemeral=True)
return
for child in self.children:
child.disabled = True
await interaction.message.edit(view=self)
confirmation_embed = interaction.message.embeds[0]
confirmation_embed.set_footer(text=f"Deal rejected by {self.buyer.display_name}")
await interaction.message.edit(embed=confirmation_embed)
embed = discord.Embed(
title="Set Deal Details",
description=f"{self.seller.mention}, please click the button below to enter the deal amount and select the currency.",
color=0xffff00
)
view = SetDealDetailsView(self.buyer, self.seller)
await interaction.channel.send(embed=embed, view=view)
self.confirmed = False
class PaymentEmbedView(discord.ui.View):
def __init__(self, ltc_wallet_address: str, ltc_amount: float):
super().__init__(timeout=None)
self.ltc_wallet_address = ltc_wallet_address
self.ltc_amount = ltc_amount
@discord.ui.button(label="Copy Address", style=discord.ButtonStyle.primary)
async def copy_address(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.channel.send(f"{self.ltc_wallet_address}")
await interaction.channel.send(f"{self.ltc_amount:.4f}")
button.disabled = True
await interaction.message.edit(view=self)
@discord.ui.button(label="QR Code", style=discord.ButtonStyle.secondary)
async def qr_code(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.defer()
qr_data = f"litecoin:{self.ltc_wallet_address}?amount={self.ltc_amount:.4f}"
qr_image = qrcode.make(qr_data)
buffer = io.BytesIO()
qr_image.save(buffer)
buffer.seek(0)
qr_embed = discord.Embed(
title="Scan to Pay",
description="Scan the QR code below to pay with Litecoin.",
color=embed_color
)
qr_embed.set_image(url="attachment://qr_code.png")
await interaction.followup.send(embed=qr_embed, file=discord.File(fp=buffer, filename='qr_code.png'))
button.disabled = True
await interaction.message.edit(view=self)
class PaymentActionView(discord.ui.View):
def __init__(self, buyer, seller, amount, currency="USD", original_fiat_amount=None):
super().__init__(timeout=None)
self.buyer = buyer
self.seller = seller
self.amount = amount # This is the LTC amount
self.currency = currency
self.original_fiat_amount = original_fiat_amount
@discord.ui.button(label="Release", style=discord.ButtonStyle.green)
async def release_button(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user != self.buyer:
embed = discord.Embed(
title="Unauthorized Action",
description="> **Only the buyer can release the payment.**",
color=0xFFFFFF
)
embed.set_footer(text=footer_text, icon_url=icon_url)
embed.set_thumbnail(url=thumbnail_url)
await interaction.response.send_message(embed=embed, ephemeral=True)
return
confirm_view = ConfirmReleaseView(self.buyer, self.seller, self.amount, self.currency, self.original_fiat_amount)
fiat_desc = f"`{self.original_fiat_amount:.2f} {self.currency}`" if self.original_fiat_amount else f"`{self.amount} LTC`"
embed = discord.Embed(
title="Release Payment Confirmation",
description=(
"> **Are you sure you want to release the payment?**\n\n"
f"**Amount:** {fiat_desc} ({self.amount:.4f} LTC)\n"
"- Click the button below to confirm your action."
),
color=0xFFFFFF
)
embed.set_footer(text=footer_text, icon_url=icon_url)
embed.set_thumbnail(url=thumbnail_url)
await interaction.response.send_message(embed=embed, view=confirm_view)
@discord.ui.button(label="Refund", style=discord.ButtonStyle.red)
async def refund_button(self, interaction: discord.Interaction, button: discord.ui.Button):
fiat_desc = f"`{self.original_fiat_amount:.2f} {self.currency}`" if self.original_fiat_amount else f"`{self.amount} LTC`"
if interaction.user == self.buyer:
confirm_view = ConfirmRefundView(self.seller, self.buyer, self.amount, self.currency, self.original_fiat_amount, refund_initiator=self.buyer)
embed = discord.Embed(
title="Refund Requested by Buyer",
description=(
f"> **Refund request initiated by** {self.buyer.mention}.\n\n"
f"**Amount:** {fiat_desc} ({self.amount:.4f} LTC)\n"
f"**Waiting for** {self.seller.mention} **to confirm the refund.**"
),
color=0xFFFFFF
)
embed.set_footer(text=footer_text, icon_url=icon_url)
embed.set_thumbnail(url=thumbnail_url)
await interaction.response.send_message(embed=embed, view=confirm_view)
elif interaction.user == self.seller:
confirm_view = ConfirmRefundView(self.seller, self.buyer, self.amount, self.currency, self.original_fiat_amount, refund_initiator=self.seller)
embed = discord.Embed(
title="Refund Requested by Seller",
description=(
f"> **Refund request initiated by** {self.seller.mention}.\n\n"
f"**Amount:** {fiat_desc} ({self.amount:.4f} LTC)\n"
f"**Waiting for** {self.buyer.mention} **to confirm the refund.**"
),
color=0xFFFFFF
)
embed.set_footer(text=footer_text, icon_url=icon_url)
embed.set_thumbnail(url=thumbnail_url)
await interaction.response.send_message(embed=embed, view=confirm_view)
class ConfirmReleaseView(discord.ui.View):
def __init__(self, buyer, seller, amount_ltc, currency="USD", original_fiat_amount=None):
super().__init__(timeout=None)
self.buyer = buyer
self.seller = seller
self.amount_ltc = amount_ltc
self.currency = currency
self.original_fiat_amount = original_fiat_amount
@discord.ui.button(label="Confirm Release", style=discord.ButtonStyle.green)
async def confirm_release(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user != self.buyer:
embed = discord.Embed(
title="Unauthorized Action",
description="> **Only the buyer can confirm the release.**",
color=embed_color
)
embed.set_footer(text=footer_text, icon_url=icon_url)
embed.set_thumbnail(url=thumbnail_url)
await interaction.response.send_message(embed=embed, ephemeral=True)
return
for child in self.children:
child.disabled = True
await interaction.message.edit(view=self)
fiat_desc = f"{self.original_fiat_amount:.2f} {self.currency}" if self.original_fiat_amount else f"{self.amount_ltc} LTC"
embed = discord.Embed(
title="Payment Released",
description=(
f"- 💸 **Payment Is Now Released:** `{fiat_desc}`\n\n"
f"- {self.seller.mention}, please click the button below to provide your LTC address."
),
color=embed_color
)
embed.set_footer(text=footer_text, icon_url=icon_url)
embed.set_thumbnail(url=thumbnail_url)
view = EnterLtcAddressView(recipient=self.seller, amount_ltc=self.amount_ltc)
await interaction.channel.send(f"{self.seller.mention}", embed=embed, view=view)
class ConfirmRefundView(discord.ui.View):
def __init__(self, seller, buyer, amount_ltc, currency="USD", original_fiat_amount=None, refund_initiator=None):
super().__init__(timeout=None)
self.seller = seller
self.buyer = buyer
self.amount_ltc = amount_ltc
self.currency = currency
self.original_fiat_amount = original_fiat_amount
self.refund_initiator = refund_initiator
@discord.ui.button(label="Confirm Refund", style=discord.ButtonStyle.red)
async def confirm_refund(self, interaction: discord.Interaction, button: discord.ui.Button):
if (interaction.user == self.seller and self.refund_initiator == self.buyer) or (interaction.user == self.buyer and self.refund_initiator == self.seller):
for child in self.children:
child.disabled = True
await interaction.message.edit(view=self)
fiat_desc = f"{self.original_fiat_amount:.2f} {self.currency}" if self.original_fiat_amount else f"{self.amount_ltc} LTC"
embed = discord.Embed(
title="Refund Confirmed",
description=(
f"- 💸 **Refund Is Now Confirmed:** `{fiat_desc}`\n\n"
f"- {self.buyer.mention}, please click the button below to provide your LTC address."
),
color=embed_color
)
embed.set_footer(text=footer_text, icon_url=icon_url)
embed.set_thumbnail(url=thumbnail_url)
view = EnterLtcAddressView(recipient=self.buyer, amount_ltc=self.amount_ltc)
await interaction.channel.send(f"{self.buyer.mention}", embed=embed, view=view)
else:
embed = discord.Embed(
title="Unauthorized Action",
description="> **You are not authorized to confirm this refund.**",
color=embed_color
)
embed.set_footer(text=footer_text, icon_url=icon_url)
embed.set_thumbnail(url=thumbnail_url)
await interaction.response.send_message(embed=embed, ephemeral=True)
class EnterLtcAddressView(discord.ui.View):
def __init__(self, recipient: discord.Member, amount_ltc: float):
super().__init__(timeout=None)
self.recipient = recipient
self.amount_ltc = amount_ltc
@discord.ui.button(label="Enter LTC Address", style=discord.ButtonStyle.green)
async def enter_address_button(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user != self.recipient:
await interaction.response.send_message(f"Only {self.recipient.display_name} can enter the wallet address.", ephemeral=True)
return
modal = LtcAddressModal(self.recipient, self.amount_ltc, self)
await interaction.response.send_modal(modal)
class LtcAddressModal(discord.ui.Modal):
def __init__(self, recipient: discord.Member, amount_ltc: float, parent_view: discord.ui.View):
super().__init__(title="Enter Wallet Address")
self.recipient = recipient
self.amount_ltc = amount_ltc
self.parent_view = parent_view
self.address_input = discord.ui.TextInput(
label="LTC Wallet Address",
placeholder="L... or M... or ltc1...",
required=True
)
self.add_item(self.address_input)
async def on_submit(self, interaction: discord.Interaction):
await interaction.response.defer()
address = self.address_input.value.strip()
if not is_valid_ltc_address(address):
await interaction.followup.send("❌ Invalid Litecoin (LTC) address format. Please check the address and try again.", ephemeral=True)
return
for child in self.parent_view.children:
child.disabled = True
await interaction.message.edit(view=self.parent_view)
await interaction.channel.send(f"**> LTC ADDRESS :** `{address}`.")
deal_id = interaction.channel.topic if interaction.channel.topic else "Unknown Deal ID"
await send_ltc(address, self.amount_ltc, interaction, deal_id)
@bot.tree.command(name="release", description="Release LTC to a specified address for a given deal")
async def release(interaction: discord.Interaction, deal_id: str, ltc_address: str, ltc_amount: float = None):
await interaction.response.defer()
interaction_channel = interaction
guild = interaction.guild
member = interaction.user
required_role = discord.utils.get(guild.roles, id=admin_role_id)
if required_role not in member.roles:
await interaction_channel.send(f"❌ You do not have the required role to use this command.", ephemeral=True)
return
try:
with open('Database/Data.json', 'r') as f:
data = json.load(f)
except FileNotFoundError:
await interaction_channel.channel.send("Database file not found.")
return
deal_data = data.get(deal_id)
if not deal_data:
await interaction_channel.channel.send(f"Deal ID `{deal_id}` not found.")
return
if ltc_amount is None:
ltc_amount = deal_data.get("received_amount_ltc")
if ltc_amount is None:
await interaction_channel.send(f"LTC amount not found for deal ID `{deal_id}`.")
return
await send_ltc(ltc_address, ltc_amount, interaction_channel, deal_id)
@bot.tree.command(name="transcript", description="Generate a transcript of this channel")
async def transcript(interaction: discord.Interaction):
channel = interaction.channel
await interaction.response.send_message("Generating transcript, please wait...")
messages = []
async for message in channel.history(limit=None):
messages.append(message)
transcript = await chat_exporter.raw_export(channel, messages)
if transcript is None:
await interaction.channel.send("Unable to generate the transcript. Please try again.")
return
file_name = f"{channel.name}-transcript.html"
file_path = f"Database/Transcripts/{file_name}"
os.makedirs(os.path.dirname(file_path), exist_ok=True)
with open(file_path, "w", encoding="utf-8") as f:
f.write(transcript)
with open(file_path, "rb") as f:
await interaction.channel.send(file=discord.File(f, file_name))
@bot.tree.command(name="delete", description="Delete this channel (Admin Only)")
async def delete(interaction: discord.Interaction):
admin_role = interaction.guild.get_role(admin_role_id)
if admin_role not in interaction.user.roles:
await interaction.response.send_message("You do not have permission to use this command.", ephemeral=True)
return
if interaction.channel.category and interaction.channel.category.id == category_id:
embed = discord.Embed(
title="Channel Deletion",
description="This channel will be deleted in **5 seconds**.",
color=embed_color
)
await interaction.response.send_message(embed=embed)
await asyncio.sleep(5)
await interaction.channel.delete(reason="Deleted by admin command.")
else:
await interaction.response.send_message("This channel cannot be deleted because it is not in the specified category.", ephemeral=True)
@bot.tree.command(name="profile", description="Show user exchange profile")
async def profile(interaction: discord.Interaction, user: discord.Member = None):
user = user or interaction.user
user_data_file = 'Database/User.json'
try:
with open(user_data_file, 'r') as f:
user_data = json.load(f)
except FileNotFoundError:
user_data = {}
user_info = user_data.get(str(user.id), None)
if user_info is None:
embed = discord.Embed(
title="Profile Not Found",
description=f"No exchange data found for {user.mention}.",
color=embed_color
)
await interaction.response.send_message(embed=embed)
return
total_spent = user_info.get('total_spent', 0)
total_earned = user_info.get('total_earned', 0)
embed = discord.Embed(
title=f"{user.name}'s Profile",
color=embed_color
)
embed.add_field(name="Total Spent (USD)", value=f"${total_spent:.3f}", inline=False)
embed.add_field(name="Total Earned (USD)", value=f"${total_earned:.3f}", inline=False)
embed.set_thumbnail(url=user.avatar.url)
embed.set_footer(text=f"Requested by {interaction.user.name}", icon_url=interaction.user.avatar.url)
await interaction.response.send_message(embed=embed)
@bot.tree.command(name="about", description="Displays bot statistics and specs.")
async def about(interaction: discord.Interaction):
uptime = datetime.datetime.now() - start_time
total_seconds = int(uptime.total_seconds())
hours, remainder = divmod(total_seconds, 3600)
minutes, seconds = divmod(remainder, 60)
cpu_usage = psutil.cpu_percent(interval=1)
ram_usage = psutil.virtual_memory().percent
ping = round(bot.latency * 1000)
try:
with open('Database/DealStats.json', 'r') as f:
data = json.load(f)
total_deals_completed = data.get("total_deals", 0)
total_amount_deals = data.get("total_amount_usd", 0.0)
except Exception as e:
print(f"Error loading deal stats: {e}")
total_deals_completed = 0
total_amount_deals = 0.0
embed = discord.Embed(
title="Bot Statistics",
description="Here are the current statistics and specifications of the bot.",
color=embed_color
)
embed.add_field(name="Ping", value=f"{ping} ms", inline=True)
embed.add_field(name="Uptime", value=f"{hours}h {minutes}m {seconds}s", inline=True)
embed.add_field(name="CPU Usage", value=f"{cpu_usage}%", inline=True)
embed.add_field(name="RAM Usage", value=f"{ram_usage}%", inline=True)
embed.add_field(name="Developer Tag", value="Alberto Ortiz", inline=True)
embed.add_field(name="Py Version", value=f"{platform.python_version()}", inline=True)
embed.set_footer(text=footer_text, icon_url=icon_url)
embed.set_thumbnail(url=thumbnail_url)
await interaction.response.send_message(embed=embed)
@bot.tree.command(name="statistics", description="Displays statistics about deals.")
async def statistics(interaction: discord.Interaction):
try:
with open('Database/DealStats.json', 'r') as f:
data = json.load(f)
total_deals_completed = data.get("total_deals", 0)
total_amount_deals = data.get("total_amount_usd", 0.0)
except Exception as e:
print(f"Error loading deal stats: {e}")
total_deals_completed = 0
total_amount_deals = 0.0
python_version = platform.python_version()
developer_tag = "Developer: Alberto Ortiz"
embed = discord.Embed(
title="Deal Statistics",
description=(
f"- Total Deals : **{total_deals_completed}**\n"
f"- Total Amount : **${total_amount_deals:.2f}**"
),
color=embed_color
)
embed.set_footer(text=footer_text, icon_url=icon_url)
embed.set_thumbnail(url=thumbnail_url)
await interaction.response.send_message(embed=embed)
bot.run(config['Token']['TOKEN'], reconnect=True)