This repository has been archived by the owner on Jun 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathGDPS-Creator.py
1686 lines (1590 loc) · 85.2 KB
/
GDPS-Creator.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
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from logging import exception
import os
import nextcord as discord
import string
import random
import asyncio
import shutil
import time
import json
import requests
import pymysql
import re
from datetime import datetime
from nextcord.ext import commands
from dotenv import load_dotenv, find_dotenv
from os import path
intents = discord.Intents().all()
intents.members = True
load_dotenv(find_dotenv())
bot_token = os.environ.get("bot_token")
prefix = os.environ.get("prefix")
mysql_ip = os.environ.get("mysql_ip")
mysql_port = os.environ.get("mysql_port")
mysql_database = os.environ.get("mysql_database")
mysql_user = os.environ.get("mysql_user")
mysql_pass = os.environ.get("mysql_pass")
web_api_key = os.environ.get("web_api_key")
cloudflare_email = os.environ.get("cloudflare_email")
cloudflare_api_key = os.environ.get("cloudflare_api_key")
client = commands.Bot(command_prefix = prefix, help_command=None, intents=intents)
connection = None
try:
connection = pymysql.connect(host=mysql_ip,
database=mysql_database,
user=mysql_user,
port = int(mysql_port),
password=mysql_pass,
autocommit=True)
print("Connected to the DB!")
except:
print("Couldn't connect to the database.")
exit()
if connection is None:
exit()
cursor = connection.cursor()
currently_creating = []
in_setup = []
in_setup_gdpsbrowser = []
donator_roles = [743031850435477594, #Perms
743031374251950131, #Admin
746663126338109581, #Developer
789529083372634183, #Super Moderator
767099706861027429, #VIP
764639361999962143, #Patreon Level 6
764639282857246800, #Patreon Level 5
764639157661597756, #Patreon Level 4
764639093207597066, #Patreon Level 3
764638878320689183, #Patreon Level 2
743031628212994130, #Patreon Level 1
803894379982880778, #Donator
763337908211154955, #Server Booster
863465353437904906, #Server Booster (GDPSFH RU)
832310593657896970] #Big gdps owner
@client.command()
async def c(ctx):
print(f"command ps!c used by {ctx.author.id}")
language = checklang(ctx.guild.id)
if language is False:
await ctx.send("An error occured with the language selector.")
return
lang = language[0]
server_config = language[1]
cursor = execute_sql("select * from gdps_creator_userdata where userID = %s", [ctx.author.id])
data = cursor.fetchall()
allowed_channels = [797900335070183474, #test-bot - GDPSFH
748238238736711761, #create-gdps - GDPSFH
863435775197839369] #create-gdps - GDPSFH RU
cursor = execute_sql("select lockdown_status from gdps_creator_config where id = %s", [server_config])
lockdown_status = cursor.fetchall()
if lockdown_status[0][0] == 1:
puser = is_admin(ctx.author.id, server_config)
if puser is not True:
embed = discord.Embed(title=getlang(f"{lang}_ccmd_lockdown_enabled"), description=getlang(f"{lang}_ccmd_lockdown_enabled_description"), color = discord.Colour.red())
await ctx.send(embed=embed)
return
if ctx.channel.id not in allowed_channels:
embed = discord.Embed(description=getlang(f"{lang}_ccmd_only_in_creategdps_channel"), color = discord.Colour.red())
await ctx.send(embed=embed)
return
if ctx.author.id in currently_creating:
embed = discord.Embed(title=getlang(f"{lang}_ccmd_finish_setup"), color = discord.Colour.red())
await ctx.send(embed=embed)
return
check_has_gdps = has_gdps(ctx.author.id)
if check_has_gdps == True:
if data[0][5] == 1:
embed = discord.Embed(title=getlang(f"{lang}_ccmd_banned_creating_gdps"), color = discord.Colour.red())
await ctx.send(embed=embed)
return
else:
embed = discord.Embed(title=getlang(f"{lang}_ccmd_already_has_gdps"), color = discord.Colour.red())
await ctx.send(embed=embed)
return
else:
try:
valid_versions = ["2.1"]
def check(m):
return m.author == ctx.message.author and m.guild is None
first_msg = discord.Embed(title=getlang(f"{lang}_ccmd_provide_us_information"), description=getlang(f"{lang}_ccmd_provide_gdps_name"), color = discord.Colour.green())
await ctx.author.send(embed=first_msg)
currently_creating.append(ctx.author.id)
embed = discord.Embed(title=getlang(f"{lang}_ccmd_gdps_setup_begun"), color = discord.Colour.green())
await ctx.send(embed=embed)
while True:
gdps_name = await client.wait_for('message', check=check)
result = re.match(r"^[a-zA-Z0-9]{1,20}$", gdps_name.content)
if result:
break
else:
embed = discord.Embed(title="This name is invalid, please only use letters, numbers, no spaces and a maximum of 20 characters.", color = discord.Colour.red())
await ctx.author.send(embed=embed)
embed = discord.Embed(title=getlang(f"{lang}_ccmd_gdps_custom_url_title"), description=getlang(f"{lang}_ccmd_gdps_custom_url_description"), color = discord.Colour.green())
await ctx.author.send(embed=embed)
name_exist_error = discord.Embed(title=getlang(f"{lang}_ccmd_gdps_custom_url_exist_error"), color = discord.Colour.red())
while True:
gdps_custom_url = await client.wait_for('message', check=check)
result = re.match(r"^[a-zA-Z0-9]{12}$", gdps_custom_url.content)
if result:
cursor = execute_sql("select null from gdps_creator_userdata where gdps_custom_url = %s", [gdps_custom_url.content])
if cursor.rowcount > 0:
await ctx.author.send(embed=name_exist_error)
else:
break
else:
embed = discord.Embed(title="This custom url is invalid, please only use letters, numbers, no spaces and a maximum of 12 characters.", color = discord.Colour.red())
await ctx.author.send(embed=embed)
embed = discord.Embed(title=getlang(f"{lang}_ccmd_gdps_version"), color = discord.Colour.green())
await ctx.author.send(embed=embed)
while True:
gdps_version = await client.wait_for('message', check=check)
result = re.match(r"^[0-9]{1}.[0-9]{1}$", gdps_version.content)
if gdps_version.content in valid_versions and result:
break
embed = discord.Embed(title=getlang(f"{lang}_ccmd_gdps_version_invalid_error"), color = discord.Colour.red())
await ctx.author.send(embed=embed)
printable = f'{string.ascii_letters}{string.digits}'
printable = list(printable)
random.shuffle(printable)
random_password = random.choices(printable, k=22)
password = ''.join(random_password)
userid = ctx.author.id
in_setup.append(ctx.author.id)
cursor = execute_sql("insert into gdps_creator_userdata (userID, gdps_name, gdps_custom_url, gdps_version, gdps_password, left_server, moderators, on_gdps_browser, created_in) values (%s, %s, %s, %s, %s, %s, %s, %s, %s)", [int(userid), gdps_name.content, gdps_custom_url.content, gdps_version.content, password, 0, "[]", 0, server_config])
embed = discord.Embed(title="<a:loading:762295133747413022> " + getlang(f"{lang}_ccmd_creating_gdps"), color = discord.Colour.green())
creating = await ctx.author.send(embed=embed)
f = open("/etc/apache2/sites-available/gdps.conf", "r")
contents = f.readlines()
f.close()
value = f" <Directory \"/var/www/gdps/{str(gdps_custom_url.content)}/\">\n ProxyFCGISetEnvIf \"true\" PHP_ADMIN_VALUE \"open_basedir=/var/www/gdps/{str(gdps_custom_url.content)}/:/usr/share/phpmyadmin/:/usr/share/php\"\n </Directory>\n\n"
contents.insert(5, value)
f = open("/etc/apache2/sites-available/gdps.conf", "w")
contents = "".join(contents)
f.write(contents)
f.close()
process = await asyncio.create_subprocess_shell(f'./CreateGDPS-Bot.sh {str(gdps_name.content)} {str(gdps_version.content)} {str(gdps_custom_url.content)} {str(password)}')
await process.communicate()
process = await asyncio.create_subprocess_shell('service apache2 reload')
await process.communicate()
await creating.delete()
in_setup.remove(ctx.author.id)
currently_creating.remove(ctx.message.author.id)
embed = discord.Embed(title=getlang(f"{lang}_ccmd_final_embed_title"), description=f"<@{userid}>", color = discord.Colour.green())
embed.add_field(name=getlang(f"{lang}_ccmd_final_embed_mysql_link"), value="http://ps.fhgdps.com/phpmyadmin/", inline=False)
embed.add_field(name=getlang(f"{lang}_ccmd_final_embed_mysql_user"), value=f"```gdps_{gdps_custom_url.content}```", inline=True)
embed.add_field(name=getlang(f"{lang}_ccmd_final_embed_mysql_password"), value=f"```{password}```", inline=True)
embed.add_field(name="\u200b", value="\u200b", inline=False)
embed.add_field(name=getlang(f"{lang}_ccmd_final_embed_ftp_ip"), value=f"```ftp.fhgdps.com```", inline=True)
embed.add_field(name=getlang(f"{lang}_ccmd_final_embed_ftp_port"), value=f"```21```", inline=True)
embed.add_field(name=getlang(f"{lang}_ccmd_final_embed_ftp_user"), value=f"```gdps_{gdps_custom_url.content}```", inline=False)
embed.add_field(name=getlang(f"{lang}_ccmd_final_embed_ftp_password"), value=f"```{password}```", inline=False)
embed.add_field(name="\u200b", value="\u200b", inline=False)
embed.add_field(name=getlang(f"{lang}_ccmd_final_embed_main_website"), value=f"http://ps.fhgdps.com/{gdps_custom_url.content}", inline=False)
embed.add_field(name=getlang(f"{lang}_ccmd_final_embed_tools_page"), value=f"http://ps.fhgdps.com/{gdps_custom_url.content}/tools")
embed.add_field(name="\u200b", value="\u200b", inline=False)
embed.add_field(name=getlang(f"{lang}_ccmd_final_embed_optional_bot_title"), value=getlang(f"{lang}_ccmd_final_embed_optional_bot_description"))
await ctx.author.send(embed=embed)
embed = discord.Embed(title="Warning", description=f"The download links provided below are **temporary** and will be deleted in 20 minutes. You should download both version and re-upload these somewhere else (Dropbox, Mega.nz, ...) and share it as the main download link for other people to download and play on your GDPS. \nYou can re-download those at any time using `ps!getdownload`. \n\nPC: [Download](http://ps.fhgdps.com/{gdps_custom_url.content}/download/{gdps_name.content}.zip) \nMobile: [Download](http://ps.fhgdps.com/{gdps_custom_url.content}/download/{gdps_name.content}.apk)", color = discord.Colour.orange())
await ctx.author.send(embed=embed)
await asyncio.sleep(1200)
shutil.rmtree(f"/var/www/gdps/{gdps_custom_url.content}/download/")
embed = discord.Embed(title="The 20 minutes passed, game files deleted.", color = discord.Colour.red())
await ctx.author.send(embed=embed)
except Exception as e:
if "Cannot send messages to this user" in str(e):
embed = discord.Embed(title=getlang(f"{lang}_global_pm_disabled"), color = discord.Colour.red())
await ctx.send(embed=embed)
else:
print(e)
@client.command()
async def deluser(ctx, arg1=None):
language = checklang(ctx.guild.id)
if language is False:
await ctx.send("An error occured with the language selector.")
return
lang = language[0]
server_config = language[1]
try:
arg1 = await commands.MemberConverter().convert(ctx, arg1)
except:
embed = discord.Embed(description=getlang(f"{lang}_global_cant_find_user_error"), color = discord.Colour.red())
await ctx.send(embed=embed)
return
print("command used: ps!deluser")
userid = str(arg1.id)
authorid = str(ctx.author.id)
puser = is_admin(authorid, server_config)
if puser is not True:
embed = discord.Embed(description=getlang(f"{lang}_global_not_allowed_use_command"), color = discord.Colour.red())
await ctx.send(embed=embed)
return
check_has_gdps = has_gdps(userid)
if check_has_gdps == True:
cursor = execute_sql("select * from gdps_creator_userdata where userID = %s", [ctx.author.id])
data = cursor.fetchall()
if server_config != data[0][8]:
await ctx.send("This GDPS wasn't created on this discord server, you can't delete it.")
return
cursor = execute_sql("delete from gdps_creator_userdata where userID = %s", [userid])
embed = discord.Embed(title=getlang(f"{lang}_cdeluser_confirmation_title"), description=f"**{arg1.name}** " + getlang(f"{lang}_cdeluser_confirmation_description"), color = discord.Colour.green())
await ctx.send(embed=embed)
else:
embed = discord.Embed(description=f"**{arg1.name}** " + getlang(f"{lang}_cdeluser_not_in_database_error"), color = discord.Colour.red())
await ctx.send(embed=embed)
@client.command()
async def getdownload(ctx):
right_channel = await in_right_channel(ctx)
userid = None
if not right_channel:
return
print("command used: ps!getdownload")
userid = str(ctx.author.id)
cursor = execute_sql("select * from gdps_creator_userdata where userID = %s", [userid])
user = cursor.fetchall()
check_has_gdps = has_gdps(userid)
if check_has_gdps == True:
cooldown_check = await command_cooldown(ctx, userid, "getdownload", 3600000)
if cooldown_check:
return
else:
if user[0][5] == 0:
try:
user_custom_url = user[0][2]
user_gdps_name = user[0][1]
user_gdps_version = user[0][3]
pc_download_link = f"https://ps.fhgdps.com/tools/download/{user_custom_url}/{user_gdps_name}.zip"
mobile_download_link = f"https://ps.fhgdps.com/tools/download/{user_custom_url}/{user_gdps_name}.apk"
embed = discord.Embed(description="When the links are ready you will recieve a private message with the link to download it", color = discord.Colour.green())
await ctx.send(embed=embed)
process = await asyncio.create_subprocess_shell(f'./CreateDownload-Bot.sh {user_gdps_name} {user_gdps_version} {user_custom_url}')
await process.communicate()
embed = discord.Embed(title="Your download liks are ready!", description=f"You have 10 minutes to download your GDPS here:\n\n [PC Version]({pc_download_link})\n[Mobile Version]({mobile_download_link})", color = discord.Colour.green())
await ctx.author.send(embed=embed)
await asyncio.sleep(600)
shutil.rmtree(f"/var/www/gdps/tools/download/{user_custom_url}")
embed = discord.Embed(title="Download link deleted.", color = discord.Colour.red())
await ctx.author.send(embed=embed)
except Exception as e:
if "Cannot send messages to this user" in str(e):
embed = discord.Embed(title="You have private messages disabled, enable them and try again.", color = discord.Colour.red())
await ctx.send(embed=embed)
else:
print(e)
else:
embed = discord.Embed(title="Your gdps got deleted because you left the server.", color = discord.Colour.red())
await ctx.send(embed=embed)
else:
embed = discord.Embed(title="You don't have a GDPS!", color = discord.Colour.red())
await ctx.send(embed=embed)
@client.command()
async def delgdps(ctx, arg1=None):
language = checklang(ctx.guild.id)
if language is False:
await ctx.send("An error occured with the language selector.")
return
lang = language[0]
server_config = language[1]
try:
arg1 = await commands.MemberConverter().convert(ctx, arg1)
except:
embed = discord.Embed(description=getlang(f"{lang}_cdeluser_cant_find_user_error"), color = discord.Colour.red())
await ctx.send(embed=embed)
return
userid = str(arg1.id)
puser = is_admin(ctx.author.id, server_config)
if puser is not True:
embed = discord.Embed(description=getlang(f"{lang}_global_not_allowed_use_command"), color = discord.Colour.red())
await ctx.send(embed=embed)
return
check_has_gdps = has_gdps(userid)
if check_has_gdps == True:
cursor = execute_sql("select * from gdps_creator_userdata where userID = %s", [arg1.id])
data = cursor.fetchall()
if server_config != data[0][8]:
await ctx.send("This GDPS wasn't created on this discord server, you can't delete it.")
return
process = await asyncio.create_subprocess_shell(f'./DelGDPS-Bot.sh {data[0][2]}')
await process.communicate()
cursor = execute_sql("delete from gdps_creator_userdata where userID = %s", [userid])
embed = discord.Embed(title=getlang(f"{lang}_cdelgdps_deletion_title"), description=f"<@{arg1.id}>" + getlang(f"{lang}_cdelgdps_deletion_description"), color = discord.Colour.green())
await ctx.send(embed=embed)
else:
embed = discord.Embed(description=getlang(f"{lang}_global_plural_no_gdps_error"), color = discord.Colour.red())
await ctx.send(embed=embed)
@client.command()
async def permission(ctx, arg1="null", arg2="null"):
print("command used: ps!permission")
language = checklang(ctx.guild.id)
if language is False:
await ctx.send("An error occured with the language selector.")
return
lang = language[0]
server_config = language[1]
if ctx.author.id != 195598321501470720:
embed = discord.Embed(description=getlang(f"{lang}_global_not_allowed_use_command"), color = discord.Colour.red())
await ctx.send(embed=embed)
try:
arg2 = await commands.MemberConverter().convert(ctx, arg2)
userid = str(arg2.id)
except:
embed = discord.Embed(description=getlang(f"{lang}_global_not_allowed_use_command"), color = discord.Colour.red())
await ctx.send(embed=embed)
return
cursor = execute_sql("select authorised_users from gdps_creator_config where id = %s", [server_config])
data = cursor.fetchall()
if data[0][0] == "[]":
mod_list = []
else:
replaced = data[0][0].strip("][").replace(",", "")
mod_list = replaced.split()
if arg1 == "give":
if userid in str(data):
embed = discord.Embed(description="This user already has permissions to use admin commands.", color = discord.Colour.red())
await ctx.send(embed=embed)
else:
mod_list.append(arg2.id)
mod_list = map(int, mod_list)
mod_list = list(mod_list)
cursor = execute_sql("update gdps_creator_config set authorised_users = %s where id = %s", [str(mod_list), server_config])
embed = discord.Embed(description=f"<@{arg2.id}> can now use admin commands!", color = discord.Colour.green())
await ctx.send(embed=embed)
elif arg1 == "remove":
if userid in str(data):
mod_list.remove(str(arg2.id))
mod_list = map(int, mod_list)
mod_list = list(mod_list)
cursor = execute_sql("update gdps_creator_config set authorised_users = %s where id = %s", [str(mod_list), server_config])
embed = discord.Embed(description=f"<@{arg2.id}> no longer has permission to use admin commands!", color = discord.Colour.green())
await ctx.send(embed=embed)
else:
embed = discord.Embed(description="This user didn't have permission to use admin commands.", color = discord.Colour.red())
await ctx.send(embed=embed)
else:
embed = discord.Embed(description="Invalid option.", color = discord.Colour.red())
await ctx.send(embed=embed)
@client.command()
async def info(ctx, arg1=None):
right_channel = await in_right_channel(ctx)
if not right_channel:
return
language = checklang(ctx.guild.id)
if language is False:
await ctx.send("An error occured with the language selector.")
return
lang = language[0]
if arg1 is None:
userid = str(ctx.author.id)
no_gdps_msg = "You don't have a GDPS!"
embed_title = "Your GDPS info"
gdps_deleted = "Your gdps got deleted because you left the server."
else:
try:
arg1 = await commands.MemberConverter().convert(ctx, arg1)
except:
embed = discord.Embed(description=getlang(f"{lang}_global_not_allowed_use_command"), color = discord.Colour.red())
await ctx.send(embed=embed)
return
userid = str(arg1.id)
no_gdps_msg = "This user doesn't have a GDPS!"
embed_title = "Info of " + arg1.name + "'s GDPS"
gdps_deleted = "The GDPS of this user got deleted because he left the server."
check_has_gdps = has_gdps(userid)
if check_has_gdps == True:
cursor = execute_sql("select * from gdps_creator_userdata where userID = %s", [userid])
data = cursor.fetchall()
if data[0][5] == 1:
embed = discord.Embed(title=gdps_deleted, color = discord.Colour.red())
await ctx.send(embed=embed)
else:
if data[0][8] == "gdpsfh":
created_in = "GDPS Free Hosting"
elif data[0][8] == "gdpsfhru":
created_in = "GDPS Free Hosting RU"
elif data[0][8] == "gdpshub":
created_in = "GDPS Hub"
else:
created_in = "Unknown"
api_banned = "Unknown"
if data[0][10] == 1:
api_banned = "No"
elif data[0][10] == 0:
api_banned = "Yes"
embed = discord.Embed(title=embed_title, description = f"**Server name** : {data[0][1]} \n**Custom URL** : {data[0][2]} \n**Original version** : {data[0][3]} \n**Created in** : {created_in} \n**API Banned** : {api_banned}", color = discord.Colour.green())
await ctx.send(embed=embed)
else:
embed = discord.Embed(title=no_gdps_msg, color = discord.Colour.red())
await ctx.send(embed=embed)
@client.command()
async def offinfo(ctx, arg1=None):
user = await client.fetch_user(arg1)
if arg1 is None:
embed = discord.Embed(description="You need to specify a user!", color = discord.Colour.red())
await ctx.send(embed=embed)
return
else:
userid = str(user.id)
no_gdps_msg = "This user doesn't have a GDPS!"
embed_title = "Info of " + user.name + "'s GDPS"
gdps_deleted = "The GDPS of this user got deleted because he left the server."
check_has_gdps = has_gdps(userid)
if check_has_gdps == True:
cursor = execute_sql("select * from gdps_creator_userdata where userID = %s", [user.id])
data = cursor.fetchall()
if data[0][5] == 1:
embed = discord.Embed(title=gdps_deleted, color = discord.Colour.red())
await ctx.send(embed=embed)
else:
embed = discord.Embed(title=embed_title, description = f"**Server name** : {data[0][1]} \n**Custom URL** : {data[0][2]} \n**Original version** : {data[0][3]}", color = discord.Colour.green())
await ctx.send(embed=embed)
else:
embed = discord.Embed(title=no_gdps_msg, color = discord.Colour.red())
await ctx.send(embed=embed)
@client.command()
async def delete(ctx):
right_channel = await in_right_channel(ctx)
if not right_channel:
return
language = checklang(ctx.guild.id)
print("command used: ps!delete")
userid = str(ctx.author.id)
check_has_gdps = has_gdps(userid)
if check_has_gdps == True:
cooldown_check = await command_cooldown(ctx, userid, "delete", 10800000)
if cooldown_check:
return
else:
cursor = execute_sql("select * from gdps_creator_userdata where userID = %s", [ctx.author.id])
data = cursor.fetchall()
if data[0][5] == 0:
embed = discord.Embed(title="Are you sure that you want to delete your gdps? all your data will be gone. (yes/no)", color = discord.Colour.from_rgb(255, 128, 0))
await ctx.send(embed=embed)
confirmation = await client.wait_for('message', check=lambda message: message.author == ctx.author)
if confirmation.content.lower() == "yes":
process = await asyncio.create_subprocess_shell(f'./DelGDPS-Bot.sh {data[0][2]}')
await process.communicate()
cursor = execute_sql("delete from gdps_creator_userdata where userID = %s", [userid])
embed = discord.Embed(title="Your gdps got deleted!", color = discord.Colour.green())
await ctx.send(embed=embed)
elif confirmation.content == "no":
with open("on_cooldown.json", "r+") as cooldown_file:
cooldown_data = json.load(cooldown_file)
cooldown_file.seek(0)
del cooldown_data[userid]["delete"]
json.dump(cooldown_data, cooldown_file, indent=4)
cooldown_file.truncate()
embed = discord.Embed(title="GDPS deletion cancelled!", color = discord.Colour.green())
await ctx.send(embed=embed)
else:
with open("on_cooldown.json", "r+") as cooldown_file:
cooldown_data = json.load(cooldown_file)
cooldown_file.seek(0)
del cooldown_data[userid]["delete"]
json.dump(cooldown_data, cooldown_file, indent=4)
cooldown_file.truncate()
await ctx.send("Not a valid answer")
else:
embed = discord.Embed(title="Your gdps got deleted because you left the server.", color = discord.Colour.red())
await ctx.send(embed=embed)
else:
embed = discord.Embed(title="You don't have a GDPS!", color = discord.Colour.red())
await ctx.send(embed=embed)
@client.command()
async def gdpsbrowser(ctx, arg1 = None):
right_channel = await in_right_channel(ctx)
if not right_channel:
return
is_donator = await check_donator(ctx)
if is_donator is False:
return
if ctx.author.id in in_setup_gdpsbrowser:
await ctx.send("Finish your current setup first!")
return
print("command used: ps!gdpsbrowser")
userid = str(ctx.message.author.id)
cursor = execute_sql("select * from gdps_creator_userdata where userID = %s", [ctx.author.id])
data = cursor.fetchall()
check_has_gdps = has_gdps(userid)
if check_has_gdps == True:
if data[0][5] == 0:
if data[0][7] == 1:
await ctx.send("You are already on gdpsbrowser.com!")
return
gdps_curl = data[0][2]
in_setup_gdpsbrowser.append(ctx.author.id)
embed = discord.Embed(description="Type your GDPS name that will displayed on the website", color = discord.Colour.from_rgb(255, 128, 0))
await ctx.send(embed=embed)
gdps_name = await client.wait_for('message', check=lambda message: message.author == ctx.author)
gdps_name = gdps_name.content
embed = discord.Embed(description="Type the GDPS owner name that will be displayed on the website", color = discord.Colour.from_rgb(255, 128, 0))
await ctx.send(embed=embed)
gdps_author_name = await client.wait_for('message', check=lambda message: message.author == ctx.author)
gdps_author_name = gdps_author_name.content
embed = discord.Embed(description="Link that users will be redirected to, can be any link like a discord server / youtube channel/ twitch link, whatever you want.", color = discord.Colour.from_rgb(255, 128, 0))
await ctx.send(embed=embed)
gdps_author_pub = await client.wait_for('message', check=lambda message: message.author == ctx.author)
gdps_author_pub = gdps_author_pub.content
url = "https://api.cloudflare.com/client/v4/zones/f432e22c3a07264921c8a1f22acaecef/dns_records"
headers = {"X-Auth-Email": cloudflare_email,
"X-Auth-Key": cloudflare_api_key,
"Content-type": "application/json"}
req_data = {"type": "CNAME",
"name": f"{gdps_curl}.gdpsbrowser.com",
"content": "gdpsbrowser.com",
"ttl": 1,
"proxied": True}
try:
req = requests.post(url, data=json.dumps(req_data), headers=headers, timeout=5)
except Exception as e:
print(e)
await ctx.send("An error occured with the cloudflare api.")
return
with open("/home/gdps/gdps_browser/servers.json", "r+") as servers_file:
servers_data = json.load(servers_file)
servers_file.seek(0)
json_data = {"name": gdps_name,
"link": f"http://ps.fhgdps.com/{gdps_curl}/",
"author": gdps_author_name,
"authorLink": gdps_author_pub,
"id": gdps_curl,
"endpoint": f"http://ps.fhgdps.com/{gdps_curl}/"}
servers_data.insert(len(servers_data), json_data)
json.dump(servers_data, servers_file, indent=4)
process = await asyncio.create_subprocess_shell(f'screen -X -S GDPS-Browser quit')
await process.communicate()
process = await asyncio.create_subprocess_shell(f'cd /home/gdps/gdps_browser/ && screen -d -m S GDPS-Bro-wser node index.js')
await process.communicate()
cursor = execute_sql("update gdps_creator_userdata set on_gdps_browser = 1 where userID = %s", [userid])
embed = discord.Embed(description="Your gdps was added to https://gdpsbrowser.com/ !", color = discord.Colour.green())
await ctx.send(embed=embed)
in_setup_gdpsbrowser.remove(ctx.author.id)
else:
embed = discord.Embed(title="You don't have a GDPS!", color = discord.Colour.red())
await ctx.send(embed=embed)
@client.command()
async def destroy(ctx):
await ctx.send("https://tenor.com/view/nuke-press-the-button-bomb-them-nuke-them-cat-gif-16361990")
@client.command()
async def power(ctx, option = None, status = None):
if ctx.author.id != 195598321501470720:
await ctx.send("no")
return
if option is None:
await ctx.send("Please enter an option: apache, mysql, ftp")
return
if status is None:
await ctx.send("Please enter a service status: on, off")
return
if option == "apache":
if status == "on":
process = await asyncio.create_subprocess_shell(f'service apache2 start')
await process.communicate()
elif status == "off":
process = await asyncio.create_subprocess_shell(f'service apache2 stop')
await process.communicate()
elif option == "mysql":
if status == "on":
process = await asyncio.create_subprocess_shell(f'service mysql start')
await process.communicate()
elif status == "off":
process = await asyncio.create_subprocess_shell(f'service mysql stop')
await process.communicate()
elif option == "ftp":
if status == "on":
process = await asyncio.create_subprocess_shell(f'service proftpd start')
await process.communicate()
elif status == "off":
process = await asyncio.create_subprocess_shell(f'service proftpd stop')
await process.communicate()
await ctx.send("Done!")
@client.command()
async def help(ctx, arg1="null"):
if arg1 == "admin":
embed = discord.Embed(title="GDPS Creator admin commands", description = f"**{prefix}deluser** : Delete a user from the DB\n"
+ f"**{prefix}delgdps <user>** : Delete a gdps\n"
+ f"**{prefix}rc <cooldown> <user>** : Removes the cooldown of a specific command\n"
+ f"**{prefix}lockdown <enable/disable>** : Enable / Disable the option to create new gdps\n"
+ f"**{prefix}banwave** : Ban users that left the server and delete their GDPS\n"
+ f"**{prefix}delallgdps** : NANI??\n", color = discord.Colour.red())
else:
embed = discord.Embed(title="GDPS Creator commands", description = f"**{prefix}c** : Start your GDPS setup\n"
+ f"**{prefix}info** : Displays the info of your GDPS\n"
+ f"**{prefix}logininfo** : Gives you the login info for phpmyadmin with no embeds\n"
+ f"**{prefix}getbackup** : Create a downloadable backup of your GDPS\n"
+ f"**{prefix}changepass** : Change the password of your gdps\n"
+ f"**{prefix}delete** : Delete your gdps\n"
+ f"**{prefix}status** : Shows the current server status\n"
+ f"**{prefix}lockdown** : Shows if lockdown is activated\n"
+ f"**{prefix}access** <add/remove> <user>: Gives the user access to use admin commands on your GDPS\n"
+ f"**{prefix}credits** : Shows some infos about the bot", color = discord.Colour.red())
await ctx.send(embed=embed)
@client.command()
async def fixftp(ctx):
if ctx.author.id != 195598321501470720:
await ctx.send("no")
return
cursor = execute_sql("select gdps_custom_url,gdps_password from gdps_creator_userdata where left_server = 0")
gdps_curl = cursor.fetchall()
for gcurl in gdps_curl:
curl = gcurl[0]
password = gcurl[1]
process = await asyncio.create_subprocess_shell(f'./CreateFTP-Bot.sh {curl} {password}')
await process.communicate()
print(f"create ftp: {curl}")
await ctx.send("done.")
@client.command()
async def delftp(ctx):
if ctx.author.id != 195598321501470720:
await ctx.send("no")
return
cursor = execute_sql("select gdps_custom_url from gdps_creator_userdata")
gdps_curl = cursor.fetchall()
for gcurl in gdps_curl:
curl = gcurl[0]
process = await asyncio.create_subprocess_shell(f'deluser gdps_{curl}')
await process.communicate()
print(f"delete ftp: {curl}")
await ctx.send("done.")
@client.command()
async def fixdata(ctx):
if ctx.author.id != 195598321501470720:
await ctx.send("no")
return
cursor = execute_sql("select * from gdps_creator_userdata")
data = cursor.fetchall()
folders = os.listdir("/var/www/gdps")
count = 0
total_gdps = 0
wait_ban = []
curl_in_db = []
for curl in data:
total_gdps += 1
if curl[5] != 1:
curl_in_db.append(curl[2])
for directories in folders:
if str(directories) not in str(curl_in_db):
count += 1
wait_ban.append(directories)
await ctx.send(f"{len(wait_ban)} curl are in the ban list")
confirmation = await client.wait_for('message', check=lambda message: message.author == ctx.author)
confirmation = confirmation.content.lower()
if confirmation != "yes":
await ctx.send("Cancelled.")
return
await ctx.send(f"{count} are not in the db, starting deletion process")
for curl in wait_ban:
process = await asyncio.create_subprocess_shell(f'./DelGDPS-Bot.sh {curl}')
await process.communicate()
await ctx.send("done.")
@client.command()
async def fixapk(ctx):
right_channel = await in_right_channel(ctx)
if not right_channel:
return
userid = ctx.author.id
check_has_gdps = has_gdps(userid)
if check_has_gdps == True:
cooldown_check = await command_cooldown(ctx, userid, "fixapk", 86400000)
if cooldown_check:
return
embed = discord.Embed(title="<a:loading:762295133747413022> Trying to fix your GDPS APK please wait..", color = discord.Colour.green())
message = await ctx.send(embed=embed)
cursor = execute_sql("select * from gdps_creator_userdata where userID = %s", [userid])
data = cursor.fetchall()
process = await asyncio.create_subprocess_shell(f'./FixAPK-Bot.sh {data[0][1]} {str(data[0][2])}')
await process.communicate()
await message.delete()
embed = discord.Embed(title="APK successfully fixed!", color = discord.Colour.green())
await ctx.send(embed=embed)
else:
embed = discord.Embed(title="You don't have a GDPS!", color = discord.Colour.red())
await ctx.send(embed=embed)
@client.command()
async def getbackup(ctx, arg1=None, offline=None):
right_channel = await in_right_channel(ctx)
userid = None
language = checklang(ctx.guild.id)
if language is False:
await ctx.send("An error occured with the language selector.")
return
lang = language[0]
if not right_channel:
return
arg1_data = None
if arg1 is not None:
try:
arg1 = await commands.MemberConverter().convert(ctx, arg1)
except:
if offline is None:
embed = discord.Embed(description=getlang(f"{lang}_global_not_allowed_use_command"), color = discord.Colour.red())
await ctx.send(embed=embed)
return
else:
arg1 = await client.fetch_user(arg1)
#if ctx.author.id != 195598321501470720 and ctx.author.id != 180790976128745472:
#is_donator = await check_donator(ctx, arg1)
#if is_donator is False:
#return
cursor = execute_sql("select * from gdps_creator_userdata where userID = %s", [arg1.id])
arg1_data = cursor.fetchall()
#else:
#is_donator = await check_donator(ctx)
#if is_donator is False:
#return
print("command used: ps!getbackup")
userid = str(ctx.author.id)
cursor = execute_sql("select * from gdps_creator_userdata where userID = %s", [userid])
user = cursor.fetchall()
if arg1 is not None:
if userid not in arg1_data[0][6] and ctx.author.id != 195598321501470720:
embed = discord.Embed(description=f"You don't have access to this GDPS!", color = discord.Colour.red())
await ctx.send(embed=embed)
return
else:
user = arg1_data
check_has_gdps = has_gdps(userid)
if check_has_gdps == True:
cooldown_check = await command_cooldown(ctx, userid, "getbackup", 3600000)
if cooldown_check:
return
else:
if user[0][5] == 0:
try:
printable = f'{string.ascii_letters}{string.digits}'
printable = list(printable)
random.shuffle(printable)
random_id = random.choices(printable, k=30)
backup_id = ''.join(random_id)
user_custom_url = user[0][2]
download_link = f"https://backups.fhgdps.com/backup/{backup_id}/{user_custom_url}-backup.zip"
embed = discord.Embed(description="When the backup will be created you will recieve a private message with the link to download it", color = discord.Colour.green())
await ctx.send(embed=embed)
process = await asyncio.create_subprocess_shell(f'./CreateBackup-Bot.sh {user[0][2]} {backup_id}')
await process.communicate()
if arg1 is None:
embed = discord.Embed(title="Your backup is ready!", description=f"You have 10 minutes to download your backup here: [Link]({download_link})", color = discord.Colour.green())
await ctx.author.send(embed=embed)
else:
embed = discord.Embed(title=f"The backup from {arg1.name}'s GDPS is ready!", description=f"You have 10 minutes to download the backup here: [Link]({download_link})", color = discord.Colour.green())
await ctx.author.send(embed=embed)
embed = discord.Embed(description=f"{ctx.author.name} ({ctx.author.id}) created a backup of your gdps.", color = discord.Colour.green())
await arg1.send(embed=embed)
await asyncio.sleep(600)
shutil.rmtree("/var/www/gdps/tools/backup/" + backup_id)
embed = discord.Embed(title="Backup deleted.", color = discord.Colour.red())
await ctx.author.send(embed=embed)
except Exception as e:
if "Cannot send messages to this user" in str(e):
if userid == str(ctx.author.id):
embed = discord.Embed(title="You have private messages disabled, enable them and try again.", color = discord.Colour.red())
await ctx.send(embed=embed)
else:
embed = discord.Embed(title="You or the GDPS owner have private messages disabled, enable them and try again.", color = discord.Colour.red())
await ctx.send(embed=embed)
else:
print(e)
else:
embed = discord.Embed(title="Your gdps got deleted because you left the server.", color = discord.Colour.red())
await ctx.send(embed=embed)
else:
if userid == str(ctx.author.id):
embed = discord.Embed(title="You don't have a GDPS!", color = discord.Colour.red())
await ctx.send(embed=embed)
else:
embed = discord.Embed(title="This user doesn't have a GDPS!", color = discord.Colour.red())
await ctx.send(embed=embed)
@client.command()
async def changepass(ctx, arg1=None):
right_channel = await in_right_channel(ctx)
if not right_channel:
return
language = checklang(ctx.guild.id)
if language is False:
await ctx.send("An error occured with the language selector.")
return
lang = language[0]
if arg1 is not None:
try:
arg1 = await commands.MemberConverter().convert(ctx, arg1)
except:
embed = discord.Embed(description=getlang(f"{lang}_global_not_allowed_use_command"), color = discord.Colour.red())
await ctx.send(embed=embed)
return
print("command used: ps!changepass")
userid = str(ctx.message.author.id)
cursor = execute_sql("select * from gdps_creator_userdata where userID = %s", [userid])
user = cursor.fetchall()
if arg1 != None:
cursor = execute_sql("select * from gdps_creator_userdata where userID = %s", [arg1.id])
arg1_data = cursor.fetchall()
if int(userid) not in arg1_data[0][6]:
embed = discord.Embed(description=f"You don't have access to this GDPS!", color = discord.Colour.red())
await ctx.send(embed=embed)
return
else:
user = arg1_data
check_has_gdps = has_gdps(userid)
if check_has_gdps == True:
cooldown_check = await command_cooldown(ctx, userid, "changepass", 1800000)
if cooldown_check:
return
else:
if user[0][5] == 0:
try:
printable = f'{string.ascii_letters}{string.digits}'
printable = list(printable)
random.shuffle(printable)
random_password = random.choices(printable, k=22)
password = ''.join(random_password)
process = await asyncio.create_subprocess_shell(f'./ChangePass-Bot.sh {user[0][2]} {password}')
await process.communicate()
cursor = execute_sql("update gdps_creator_userdata set gdps_password = %s where userID = %s", [password, userid])
if arg1 is None:
embed = discord.Embed(description="Your new password was sent to you in your private messages!", color = discord.Colour.green())
await ctx.send(embed=embed)
embed = discord.Embed(title="Password changed!", description=f"New password: {password}", color = discord.Colour.green())
await ctx.message.author.send(embed=embed)
else:
embed = discord.Embed(description="The new password was sent to you and the gdps owner in private messages!", color = discord.Colour.green())
await ctx.send(embed=embed)
embed = discord.Embed(title=f"The password from {arg1.name}'s GDPS has been changed!", description=f"New password: {password}", color = discord.Colour.green())
await ctx.message.author.send(embed=embed)
embed = discord.Embed(title=f"Password changed by {ctx.author.name} ({ctx.author.id})!", description=f"New password: {password}", color = discord.Colour.green())
await arg1.send(embed=embed)
except Exception as e:
if "Cannot send messages to this user" in str(e):
if userid == str(ctx.author.id):
embed = discord.Embed(title="You have private messages disabled, enable them and try again. (The password has been changed anyway)", color = discord.Colour.red())
await ctx.send(embed=embed)
else:
embed = discord.Embed(title="You or the GDPS owner have private messages disabled, enable them and try again. (The password has been changed anyway)", color = discord.Colour.red())
await ctx.send(embed=embed)
else:
print(e)
else:
embed = discord.Embed(title="Your gdps got deleted because you left the server.", color = discord.Colour.red())
await ctx.send(embed=embed)
else:
if userid == str(ctx.author.id):
embed = discord.Embed(title="You don't have a GDPS!", color = discord.Colour.red())
await ctx.send(embed=embed)
else:
embed = discord.Embed(title="This user doesn't have a GDPS!", color = discord.Colour.red())
await ctx.send(embed=embed)
@client.command()
async def logininfo(ctx, arg1=None):
right_channel = await in_right_channel(ctx)
if not right_channel:
return
language = checklang(ctx.guild.id)
if language is False:
await ctx.send("An error occured with the language selector.")
return
lang = language[0]
userid = str(ctx.message.author.id)
cursor = execute_sql("select * from gdps_creator_userdata where userID = %s", [userid])
user = cursor.fetchall()
if arg1 != None:
try:
arg1 = await commands.MemberConverter().convert(ctx, arg1)
except:
embed = discord.Embed(description=getlang(f"{lang}_global_not_allowed_use_command"), color = discord.Colour.red())
await ctx.send(embed=embed)
return
cursor = execute_sql("select * from gdps_creator_userdata where userID = %s", [arg1.id])
arg1_data = cursor.fetchall()
if str(userid) not in arg1_data[0][6] and ctx.author.id != 195598321501470720:
embed = discord.Embed(description=f"You don't have access to this GDPS!", color = discord.Colour.red())
await ctx.send(embed=embed)
return
else:
user = arg1_data
check_has_gdps = has_gdps(userid)
if check_has_gdps == True:
if user[0][5] == 0:
try:
if arg1 is None:
await ctx.author.send(f"Your phpmyadmin login info:\n\nUser: gdps_{user[0][2]}\nPassword: {user[0][4]}")
embed = discord.Embed(title="Your phpmyadmin login info was sent to you in private messages!", color = discord.Colour.green())
await ctx.send(embed=embed)
else:
await ctx.author.send(f"{arg1.name}'s GDPS phpmyadmin login info:\n\nUser: gdps_{user[0][2]}\nPassword: {user[0][4]}")
embed = discord.Embed(description=f"{arg1.name}'s GDPS login info was sent to you in private messages!", color = discord.Colour.green())
await ctx.send(embed=embed)
embed = discord.Embed(description=f"{ctx.author.name} ({ctx.author.id}) entered the gdps!logininfo command on your gdps to get your GDPS database infos.", color = discord.Colour.green())
await arg1.send(embed=embed)
except Exception as e:
if "Cannot send messages to this user" in str(e):
if userid == str(ctx.author.id):
embed = discord.Embed(title="You have private messages disabled, enable them and try again.", color = discord.Colour.red())
await ctx.send(embed=embed)
else:
embed = discord.Embed(title="You or the GDPS owner have private messages disabled, enable them and try again.", color = discord.Colour.red())
await ctx.send(embed=embed)
else:
print(e)
else:
embed = discord.Embed(title="Your gdps got deleted because you left the server.", color = discord.Colour.red())
await ctx.send(embed=embed)
else:
if userid == str(ctx.author.id):
embed = discord.Embed(title="You don't have a GDPS!", color = discord.Colour.red())
await ctx.send(embed=embed)
else:
embed = discord.Embed(title="This user doesn't have a GDPS!", color = discord.Colour.red())
await ctx.send(embed=embed)
@client.command()
async def access(ctx, arg1="null", user=None):
right_channel = await in_right_channel(ctx)
if not right_channel:
return
language = checklang(ctx.guild.id)