-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
1801 lines (1480 loc) · 85.7 KB
/
main.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
# Imports
try:
import nextcord
from nextcord.ext import commands, tasks
from links import *
from responses import *
from dotenv import load_dotenv
import _mysql_connector
import os
import random
import calendar
import pytz
import datetime
import asyncio
import regex
# import praw
import pytube
import imdb
import requests
import urllib.request
import youtube_dl
import wikipedia
import googlesearch
from cryptography.fernet import Fernet
print("All modules and libraries imported.")
except ImportError as ie:
print(ie)
# Setup
prefixes = ["_"]
intents = nextcord.Intents.default()
intents.members = True
intents.message_content = True
bot = commands.Bot(
command_prefix=[prefix for prefix in prefixes],
intents=intents,
case_insensitive=True,
)
color = nextcord.Color.from_rgb(223, 31, 45)
bot.remove_command("help")
# Enviroment Variables
global auth
load_dotenv(".env")
# Audio
server_index = {}
FFMPEG_OPTS = {
"before_options": "-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5",
"options": "-vn",
}
ydl_op = {
"format": "bestaudio/best",
"postprocessors": [
{
"key": "FFmpegExtractAudio",
"preferredcodec": "mp3",
"preferredquality": "128",
}
],
}
# SQL Connection
try:
conn = _mysql_connector.connect(
host = "localhost",
user = "root",
passwd = os.getenv("sql_pass"),
database = "discord"
)
cursor = conn.cursor()
print("Connection to Main DB established.")
except Exception as exception:
print(exception)
# SQL Connection (Feature)
try:
conn_test = _mysql_connector.connect(
host = "localhost",
user = "root",
passwd = os.getenv("sql_pass"),
database = "discord_sql_func"
)
cursor_test = conn_test.cursor()
print("Connection to Feature DB established.")
except Exception as exception: print(exception)
# Reddit
# reddit = praw.Reddit(
# client_id=os.getenv("reddit_client_id"),
# client_secret=os.getenv("reddit_client_secret"),
# user_agent=os.getenv("reddit_user_agent"),
# username=os.getenv("reddit_username"),
# password=os.getenv("reddit_userpass")
# )
# default_topic = {}
# Key for ED
key = Fernet.generate_key()
cipher = Fernet(key)
# Snipe, Number of requests, timezone (default), help page number, quip list
deleted_messages, num, default_tz, help_toggle, dialogue_list = {}, 0, "Asia/Kolkata", 0, []
# ---------------------------------------------- NON ASYNC FUNCTIONS -----------------------------------------
def help_menu():
global help_toggle
embed_help_menu = nextcord.Embed(title="🕸𝗖𝗼𝗺𝗺𝗮𝗻𝗱 𝗠𝗲𝗻𝘂🕸", description="Prefixes: `_`", color=color)
embed_help_menu.set_thumbnail(url=random.choice(url_thumbnails))
embed_help_menu.set_footer(text="New Features Coming Soon ⚙️")
if help_toggle == 0 or help_toggle < 0:
help_toggle = 0
embed_help_menu.add_field(
name="Standard",
value="`_hello` to greet bot\n`_help` to get this menu\n`_gif` or `_img `to see cool spiderman photos and GIFs\n`_quips` to get a famous dialogue\n`@Thwipper` to get more info about thwipper",
inline=False
)
embed_help_menu.set_image(url=bot.user.avatar.url)
if help_toggle == 1:
embed_help_menu.add_field(
name="The Web",
value="`_wiki topic` for wikipedia\n`_g topic` to google\n`_imdb movie` to get movie details from IMDb\n `_reddit topic` to get reddit memes",
inline=False
)
embed_help_menu.set_image(url=help_page1)
if help_toggle == 2:
embed_help_menu.add_field(
name="Shells",
value="`_; query` to running simple queries\n`_py expression` for running simple code\n`_pydoc function` to get information about that python function",
inline=False
)
embed_help_menu.add_field(
name="Notes",
value="Functions, when using `pydoc` command, will not be executed. Try without `()`.\nThere is a test database connected with the SQL command, so you can run whatever queries you like.",
inline=False
)
embed_help_menu.set_image(url=help_page2)
if help_toggle == 3:
embed_help_menu.add_field(
name="Encrypter Decrypter",
value="`_hush en text`to encrypt message\n`_hush dec text` to decrypt message\n",
inline=False,
)
embed_help_menu.set_image(url=help_page3)
if help_toggle == 4:
embed_help_menu.add_field(
name="Spider-Punk Radio™\n\nVoice Controls",
value="🔉 `_cn` to get the bot to join voice channel\n🔇 `_dc` to remove bot from voice channel",
inline=False,
)
embed_help_menu.add_field(
name="Player Controls",
value="🎶 `_p name/index` to play songs\n▶ `_res` to resume a song\n⏸ `_pause` to pause a song\n⏹ `_st` to stop a song\n🔂 `_rep` to repeat song\n⏭ `_skip` to skip song\n⏮ `_prev` for previous song",
inline=False
)
embed_help_menu.add_field(
name="Queue Controls",
value="🔼 `_q` scroll queue `up`\n🔽 `_q` scroll queue `down`\n🔠 `_lyrics name` to display current song's lyrics\n*️⃣ `_songinfo` to get current song's info\n✅ `_q name` to add a song to the queue\n❌ `_rem index` to remove song from queue\n💥 `_cq` to clear queue",
inline=False
)
embed_help_menu.set_image(url=help_page4)
if help_toggle == 5:
embed_help_menu.add_field(
name="Birthdays",
value="`_addbday mention month day` to add a member's birthday\n`_bday` to get thwipper to wish the members of your server\n`_rembday mention` to remove a member's birthday",
inline=False
)
embed_help_menu.set_image(url=help_page5)
if help_toggle == 6 or help_toggle > 6:
help_toggle = 6
embed_help_menu.add_field(
name="Utility",
value="`_web` to see deleted message\n`_ping` to get bot's latency\n`_serverinfo` to get server's information\n`_pfp mention` to get user's profile picture\n`_setbit` to set quality of bitrate\n`_polls` to see how to conduct a poll\n`_dt timezone` to get date and time\n`_cal year month` to get calendar",
inline=False
)
embed_help_menu.add_field(
name="Notes",
value="The default timezone for `_dt` is set as `Asia/Kolkata`. Check above on how to get date time of your timezone.",
inline=False
)
embed_help_menu.set_image(url=help_page6)
return embed_help_menu
def time_converter(seconds):
mins, secs = divmod(seconds, 60)
hours, mins = divmod(mins, 60)
# return "%d hrs %02d mins %02d secs" % (hours, mins, secs)
if hours == 0:
return "%02d mins %02d secs" % (mins, secs)
if hours > 0:
if len(str(secs)) == 1:
secs = "0" + str(secs)
return "%d hrs %02d mins %02d secs" % (hours, mins, secs)
def youtube_download(ctx, url):
if True:
with youtube_dl.YoutubeDL(ydl_op) as ydl:
URL = ydl.extract_info(url, download=False)["formats"][0]["url"]
return URL
def play_music(voice, URL_queue):
voice.play(nextcord.FFmpegPCMAudio(URL_queue, **FFMPEG_OPTS))
# ----------------------------------------- EVENTS --------------------------------------
@bot.event
async def on_ready():
print("{0.user} is now online.".format(bot))
stop = 0
# QUIPS
global dialogue_list
site = (
requests.get("https://geektrippers.com/spiderman-quotes/")
.content.decode()
.replace("<br>", "\n")
.replace("<strong>", " ")
.replace("</strong>", " ")
.replace("<em>", " ")
.replace("</em>", " ")
.replace("’", "'")
.replace("”", '"\n\r')
.replace("…", "...")
.replace("“", '"')
.replace(" ", " ")
.replace("–", "-")
.replace("‘", "'")
.replace("]", "]\n")
.replace("[", "\n[")
)
for i in range(0, 1000):
q = site.find('<p class="has-background" style="background-color:#dedfe0">', stop) + len('<p class="has-background style="background-color:#dedfe0">')
w = site.find("</p>", stop)
stop = w + len("</p>")
dialogues = ""
if not site[q:w]:
continue
else:
dialogues = site[q:w]
dialogue_list += [dialogues]
# STATUSES
@tasks.loop(minutes=10)
async def multiple_statuses():
while True:
for status in status_list:
await asyncio.sleep(300)
await bot.change_presence(activity=nextcord.Activity(type=nextcord.ActivityType.playing, name=status))
multiple_statuses.start()
@bot.event
async def on_message(message):
if f"<@{bot.user.id}>" == message.content:
embed = nextcord.Embed(
title="Your friendly neighborhood spider-bot",
description=f"Hi {message.author.name}!\nI am `Thwipper`. My name comes from the onomatopoeia of Spider-Man's Webshooters. Pretty slick, eh? I have lots of cool features that you may find interesting. Check them out with `_help` command. As always, more exciting features are always in the works. Stay tuned and have fun with them.\n_Excelsior!_",
color=color
)
embed.add_field(name="Made by", value="[Tamonud](https://www.github.com/spidey711)", inline=True)
embed.add_field(name="Source Code", value="[Github Repo](https://www.github.com/spidey711/Thwipper-bot)", inline=True)
embed.set_thumbnail(url=bot.user.avatar.url)
await message.reply(embed=embed)
else:
await bot.process_commands(message)
@bot.event
async def on_message_delete(message):
if not message.channel.id in list(deleted_messages.keys()):
deleted_messages[message.channel.id] = []
if len(message.embeds) <= 0:
deleted_messages[message.channel.id].append((str(message.author.id), message.content))
else:
deleted_messages[message.channel.id].append((str(message.author.id), message.embeds[0], True))
@bot.event
async def on_reaction_add(reaction, user):
if not user.bot:
# if reaction.emoji == "🖱":
# if str(user) != str(bot.user) and reaction.message.author == bot.user:
# await reaction.remove(user)
# try:
# sub = reddit.subreddit(default_topic[str(reaction.message.guild.id)]).random()
# embed = nextcord.Embed(description=f"**Caption:\n**{sub.title}", color=color)
# embed.set_author(name=f"Post by: {sub.author}", icon_url=url_reddit_author)
# # embed.set_thumbnail(url=url_reddit_thumbnail)
# embed.set_image(url=sub.url)
# embed.set_footer(text=f"🔺: {sub.ups} 🔻: {sub.downs} 💬: {sub.num_comments}")
# await reaction.message.edit(embed=embed)
# except Exception:
# embed = nextcord.Embed(description="Default topic is not set", color=color)
# embed.set_author(name="Uh oh...", icon_url=url_reddit_author)
# await reaction.message.edit(embed=embed)
global help_toggle
if reaction.emoji == "➡":
help_toggle += 1
if str(user) != str(bot.user) and reaction.message.author == bot.user:
await reaction.remove(user)
await reaction.message.edit(embed=help_menu())
if reaction.emoji == "⬅":
help_toggle -= 1
if str(user) != str(bot.user) and reaction.message.author == bot.user:
await reaction.remove(user)
await reaction.message.edit(embed=help_menu())
if reaction.emoji == "🕸":
if str(user) != str(bot.user) and reaction.message.author == bot.user:
await reaction.remove(user)
embed = nextcord.Embed(title="🕸Mutual Guilds🕸", description="\n".join([servers.name for servers in user.mutual_guilds]), color=color)
embed.set_thumbnail(url=random.choice(url_thumbnails))
embed.set_footer(text="New Features Coming Soon 🛠")
await reaction.message.edit(embed=embed)
# MUSIC PLAYER
voice = nextcord.utils.get(bot.voice_clients, guild=reaction.message.guild)
voice_client = reaction.message.guild.voice_client
if not voice_client:
return
playing = reaction.message.guild.voice_client.is_playing()
pause = reaction.message.guild.voice_client.is_paused()
# SERVER QUEUE
operation_view = f"SELECT song_name, song_url FROM music_queue WHERE server={str(reaction.message.guild.id)}"
cursor.execute(operation_view)
# due to enumerate() in below line, some reactions may stop working, I'll fix them soon
server_queue = list(enumerate(cursor.fetchall(), start=0)) #song[0] is counter, song[1] is (name, url)
members_in_vc = [str(names) for names in reaction.message.guild.voice_client.channel.members]
string = ""
if reaction.emoji == "🔇":
if str(user) != str(bot.user) and reaction.message.author == bot.user:
await reaction.remove(user)
if members_in_vc.count(str(user)) > 0:
try:
if voice_client.is_connected():
embed = nextcord.Embed(description=f"Disconnected from {reaction.message.guild.voice_client.channel.name}", color=color)
embed.set_author(name="Spider-Punk Radio™", icon_url=url_author_music)
embed.set_footer(text=random.choice(disconnections))
await reaction.message.edit(embed=embed)
await voice_client.disconnect()
except AttributeError:
embed = nextcord.Embed(description="I am not connected to a voice channel", color=color)
embed.set_author(name="Spider-Punk Radio™", icon_url=url_author_music)
await reaction.message.edit(embed=embed)
else:
embed = nextcord.Embed(description="Connect to the voice channel first 🔊", color=color)
embed.set_author(name="Spider-Punk Radio™", icon_url=url_author_music)
await reaction.message.edit(embed=embed)
# under works
if reaction.emoji == "🔼":
if str(user) != str(bot.user) and reaction.message.author == bot.user:
await reaction.remove(user)
# under works
if reaction.emoji == "🔽":
if str(user) != str(bot.user) and reaction.message.author == bot.user:
await reaction.remove(user)
# under works
if reaction.emoji == "🔠":
if str(user) != str(bot.user) and reaction.message.author == bot.user:
await reaction.remove(user)
embed = nextcord.Embed(description="Working on lyrics...", color=color)
embed.set_author(name="Spider-Punk Radio™", icon_url=url_author_music)
embed.set_footer(text=f"Voice Channel Bitrate: {reaction.message.guild.voice_client.channel.bitrate/1000} kbps")
await reaction.message.edit(embed=embed)
if reaction.emoji == "▶":
if str(user) != str(bot.user) and reaction.message.author == bot.user:
await reaction.remove(user)
if members_in_vc.count(str(user)) > 0:
try:
if server_index[str(reaction.message.guild.id)] is not None:
if pause == True:
voice_client.resume()
embed = nextcord.Embed(description="Song has resumed playing 🎸", color=color)
embed.set_author(name="Spider-Punk Radio™", icon_url=url_author_music)
embed.set_footer(text=f"Voice Channel Bitrate: {reaction.message.guild.voice_client.channel.bitrate/1000} kbps")
await reaction.message.edit(embed=embed)
else:
if playing == True:
embed = nextcord.Embed(description="Song is not paused 🤔", color=color)
else:
embed = nextcord.Embed(description="Nothing is playing right now ❗", color=color)
embed.set_author(name="Spider-Punk Radio™", icon_url=url_author_music)
embed.set_footer(text=f"Voice Channel Bitrate: {reaction.message.guild.voice_client.channel.bitrate/1000} kbps")
await reaction.message.edit(embed=embed)
else:
if playing != True:
voice_client.resume()
embed = nextcord.Embed(description="Song has resumed playing ▶", color=color)
else:
embed = nextcord.Embed(description="Song is already playing 🎸", color=color)
embed.set_author(name="Spider-Punk Radio™", icon_url=url_author_music)
embed.set_footer(text=f"Voice Channel Bitrate: {reaction.message.guild.voice_client.channel.bitrate/1000} kbps")
await reaction.message.edit(embed=embed)
except Exception as e:
embed = nextcord.Embed(description=str(e), color=color)
embed.set_author(name="Error", icon_url=url_author_music)
await reaction.message.edit(embed=embed)
else:
embed = nextcord.Embed(description=f"Connect to the voice channel first 🔊", color=color)
embed.set_author(name="Spider-Punk Radio™", icon_url=url_author_music)
await reaction.message.edit(embed=embed)
if reaction.emoji == "⏸":
if str(user) != str(bot.user) and reaction.message.author == bot.user:
await reaction.remove(user)
if members_in_vc.count(str(user)) > 0:
try:
if playing == True:
voice_client.pause()
embed = nextcord.Embed(description="Song is paused ⏸", color=color)
embed.set_author(name="Spider-Punk Radio™", icon_url=url_author_music)
embed.set_footer(text=f"Voice Channel Bitrate: {reaction.message.guild.voice_client.channel.bitrate/1000} kbps")
await reaction.message.edit(embed=embed)
else:
if pause == True:
embed = nextcord.Embed(description="Song is already paused ⏸", color=color)
else:
embed = nextcord.Embed(description="No song playing currently ❗", color=color)
embed.set_author(name="Spider-Punk Radio™", icon_url=url_author_music)
embed.set_footer(text=f"Voice Channel Bitrate: {reaction.message.guild.voice_client.channel.bitrate/1000} kbps")
await reaction.message.edit(embed=embed)
except Exception as e:
embed = nextcord.Embed(description=str(e), color=color)
embed.set_author(name="Error", icon_url=url_author_music)
await reaction.message.edit(embed=embed)
else:
embed = nextcord.Embed(description=f"Connect to the voice channel first 🔊", color=color)
embed.set_author(name="Spider-Punk Radio™", icon_url=url_author_music)
await reaction.message.edit(embed=embed)
if reaction.emoji == "⏮":
if str(user) != str(bot.user) and reaction.message.author == bot.user:
await reaction.remove(user)
server_index[str(reaction.message.guild.id)] -= 1
if members_in_vc.count(str(user)) > 0:
try:
URL_queue = youtube_download(reaction.message, server_queue[server_index[str(reaction.message.guild.id)]][1])
if playing != True:
pass
else:
voice.stop()
embed = nextcord.Embed(description="**Song: **{a}\n**Queue Index: **{b}".format(a=server_queue[server_index[str(reaction.message.guild.id)]][0], b=server_index[str(reaction.message.guild.id)],).replace(" - YouTube", " "), color=color,)
embed.set_author(name="Now playing", icon_url=url_author_music)
embed.set_thumbnail(url=pytube.YouTube(url=server_queue[server_index[str(reaction.message.guild.id)]][1]).thumbnail_url)
embed.add_field(name="Uploader", value=pytube.YouTube(url=server_queue[server_index[str(reaction.message.guild.id)]][1]).author, inline=True)
embed.add_field(name="Duration", value=time_converter(pytube.YouTube(url=server_queue[server_index[str(reaction.message.guild.id)]][1]).length), inline=True)
embed.set_footer(text=f"Voice Channel Bitrate: {reaction.message.guild.voice_client.channel.bitrate/1000} kbps")
await reaction.message.edit(embed=embed)
voice.play(nextcord.FFmpegPCMAudio(URL_queue, **FFMPEG_OPTS))
except IndexError:
embed = nextcord.Embed(description="Looks like there is no song at this index", color=color)
embed.set_author(name="Oops...", icon_url=url_author_music)
await reaction.message.edit(embed=embed)
else:
embed = nextcord.Embed(description=f"Connect to the voice channel first 🔊", color=color)
embed.set_author(name="Spider-Punk Radio™", icon_url=url_author_music)
await reaction.message.edit(embed=embed)
if reaction.emoji == "⏭":
if str(user) != str(bot.user) and reaction.message.author == bot.user:
await reaction.remove(user)
server_index[str(reaction.message.guild.id)] += 1
if members_in_vc.count(str(user)) > 0:
try:
URL_queue = youtube_download(reaction.message, server_queue[server_index[str(reaction.message.guild.id)]][1])
if playing != True:
pass
else:
voice.stop()
embed = nextcord.Embed(description="**Song: **{a}\n**Queue Index: **{b}".format(
a=server_queue[server_index[str(reaction.message.guild.id)]][0],
b=server_index[str(reaction.message.guild.id)]).replace(" - YouTube", " "),
color=color
)
embed.set_author(name="Now Playing", icon_url=url_author_music)
embed.set_thumbnail(url=pytube.YouTube(url=server_queue[server_index[str(reaction.message.guild.id)]][1]).thumbnail_url)
embed.add_field(name="Uploader", value=pytube.YouTube(url=server_queue[server_index[str(reaction.message.guild.id)]][1]).author, inline=True)
embed.add_field(name="Duration", value=time_converter(pytube.YouTube(url=server_queue[server_index[str(reaction.message.guild.id)]][1]).length), inline=True)
embed.set_footer(text=f"Voice Channel Bitrate: {reaction.message.guild.voice_client.channel.bitrate/1000} kbps")
await reaction.message.edit(embed=embed)
voice.play(nextcord.FFmpegPCMAudio(URL_queue, **FFMPEG_OPTS))
except IndexError:
embed = nextcord.Embed(description="Looks like there is no song at this index", color=color)
embed.set_author(name="Oops...", icon_url=url_author_music)
await reaction.message.edit(embed=embed)
else:
embed = nextcord.Embed(description=f"Connect to the voice channel first 🔊", color=color)
embed.set_author(name="Spider-Punk Radio™", icon_url=url_author_music)
await reaction.message.edit(embed=embed)
if reaction.emoji == "⏹":
if str(user) != str(bot.user) and reaction.message.author == bot.user:
await reaction.remove(user)
if members_in_vc.count(str(user)) > 0:
try:
if playing == True or pause == True:
voice_client.stop()
embed = nextcord.Embed(description="Song has been stopped ⏹", color=color)
else:
embed = nextcord.Embed(description="Nothing is playing at the moment❗", color=color)
embed.set_author(name="Spider-Punk Radio™", icon_url=url_author_music)
embed.set_footer(text="Voice Channel Bitrate: {} kbps".format(reaction.message.guild.voice_client.channel.bitrate/1000))
await reaction.message.edit(embed=embed)
except Exception as e:
embed = nextcord.Embed(description=str(e), color=color)
embed.set_author(name="Error", icon_url=url_author_music)
await reaction.message.edit(embed=embed)
else:
embed = nextcord.Embed(description=f"Connect to the voice channel first 🔊", color=color)
embed.set_author(name="Spider-Punk Radio™", icon_url=url_author_music)
await reaction.message.edit(embed=embed)
if reaction.emoji == "*️⃣":
if str(user) != str(bot.user) and reaction.message.author == bot.user:
await reaction.remove(user)
if len(server_queue) <= 0:
embed = nextcord.Embed(description=random.choice(empty_queue), color=color)
embed.set_author(name="Uh oh...", icon_url=url_author_music)
await reaction.message.edit(embed=embed)
else:
try:
try:
embed = nextcord.Embed(
description="**Song: **{a}\n**Index: **{b}\n**Views: **{c}\n**Description: **\n{d}".format(
a=server_queue[server_index[str(reaction.message.guild.id)]][0],
b=server_index[str(reaction.message.guild.id)],
c=pytube.YouTube(url=server_queue[server_index[str(reaction.message.guild.id)]][1]).views,
d=pytube.YouTube(url=server_queue[server_index[str(reaction.message.guild.id)]][1]).description),
color=color
)
embed.set_author(name="Currently Playing", url=server_queue[server_index[str(reaction.message.guild.id)]][1], icon_url=url_author_music)
embed.set_footer(text="Voice Channel Bitrate: {} kbps".format(reaction.message.guild.voice_client.channel.bitrate/1000))
embed.set_thumbnail(url=pytube.YouTube(url=server_queue[server_index[str(reaction.message.guild.id)]][1]).thumbnail_url)
await reaction.message.edit(embed=embed)
# if description crosses embed length
except nextcord.errors.HTTPException:
embed = nextcord.Embed(description="**Song: **{a}\n**Index: **{b}\n**Views: **{c}\n**Description: **\n{d}".format(
a=server_queue[server_index[str(reaction.message.guild.id)]][0],
b=server_index[str(reaction.message.guild.id)],
c=pytube.YouTube(url=server_queue[server_index[str(reaction.message.guild.id)]][1]).views,
d=random.choice(description_embed_errors)),
color=color
)
embed.set_author(name="Currently Playing", url=server_queue[server_index[str(reaction.message.guild.id)]][1], icon_url=url_author_music)
embed.set_footer(text="Voice Channel Bitrate: {} kbps".format(reaction.message.guild.voice_client.channel.bitrate/1000))
embed.set_thumbnail(url=pytube.YouTube(url=server_queue[server_index[str(reaction.message.guild.id)]][1]).thumbnail_url)
await reaction.message.edit(embed=embed)
except KeyError:
embed = nextcord.Embed(description=random.choice(default_index), color=color)
embed.set_author(name="Uh oh...", icon_url=url_author_music)
await reaction.message.edit(embed=embed)
if reaction.emoji == "🔂":
if str(user) != str(bot.user) and reaction.message.author == bot.user:
await reaction.remove(user)
if members_in_vc.count(str(user)) > 0:
try:
URL_queue = youtube_download(reaction.message, server_queue[server_index[str(reaction.message.guild.id)]][1])
if reaction.message.guild.voice_client.is_playing() != True:
pass
else:
voice.stop()
embed = nextcord.Embed(description="**Song: **{}".format(server_queue[server_index[str(reaction.message.guild.id)]][0]).replace(" - YouTube", " "), color=color)
embed.set_author(name="Repeating Song", icon_url=url_author_music)
embed.set_thumbnail(url=pytube.YouTube(url=server_queue[server_index[str(reaction.message.guild.id)]][1]).thumbnail_url)
embed.add_field(name="Uploader", value=pytube.YouTube(url=server_queue[server_index[str(reaction.message.guild.id)]][1]).author, inline=True)
embed.add_field(name="Duration", value=time_converter(pytube.YouTube(url=server_queue[server_index[str(reaction.message.guild.id)]][1]).length), inline=True)
embed.set_footer(text="Voice Channel Bitrate: {} kbps".format(reaction.message.guild.voice_client.channel.bitrate/1000))
await reaction.message.edit(embed=embed)
voice.play(nextcord.FFmpegPCMAudio(URL_queue, **FFMPEG_OPTS))
except Exception as e:
embed = nextcord.Embed(description=str(e), color=color)
embed.set_author(name="Error", icon_url=url_author_music)
await reaction.message.edit(embed=embed)
else:
embed = nextcord.Embed(description=f"Connect to the voice channel first 🔊", color=color)
embed.set_author(name="Spider-Punk Radio™", icon_url=url_author_music)
await reaction.message.edit(embed=embed)
if reaction.emoji == "🔀":
if str(user) != str(bot.user) and reaction.message.author == bot.user:
await reaction.remove(user)
if members_in_vc.count(str(user)) > 0:
# choosing a random song
random_song = random.choice(server_queue)
queue_index = server_index[str(reaction.message.guild.id)]
for index in range(len(server_queue)):
if random_song == server_queue[index]:
# random song has set index
queue_index = int(index)
# setting server index to new randomly chosen index
server_index[str(reaction.message.guild.id)] = queue_index
URL_shuffle = youtube_download(reaction.message, random_song[1])
if reaction.message.guild.voice_client.is_playing() != True:
pass
else:
voice.stop()
embed = nextcord.Embed(description=f"**Song: **{random_song[0]}\n**Queue Index: **{queue_index}".replace(" - YouTube", " "), color=color)
embed.set_author(name="Shuffle Play", icon_url=url_author_music)
embed.set_thumbnail(url=pytube.YouTube(url=random_song[1]).thumbnail_url)
embed.add_field(name="Uploader", value=pytube.YouTube(url=random_song[1]).author, inline=True)
embed.add_field(name="Duration", value=time_converter(pytube.YouTube(url=random_song[1]).length), inline=True)
embed.set_footer(text=f"Voice Channel Bitrate: {reaction.message.guild.voice_client.channel.bitrate/1000} kbps")
await reaction.message.edit(embed=embed)
voice.play(nextcord.FFmpegPCMAudio(URL_shuffle, **FFMPEG_OPTS))
else:
embed = nextcord.Embed(description=f"Connect to a voice channel first 🔊", color=color)
embed.set_author(name="Spider-Punk Radio™", icon_url=url_author_music)
await reaction.message.edit(embed=embed)
# ---------------------------------------------- STANDARD ----------------------------------------------------
@bot.command(aliases=["hello", "hi", "hey", "hey there", "salut", "kon'nichiwa", "hola", "aloha"])
async def greet_bot(ctx):
greetings = [f"Hey {ctx.author.name}!", f"Hi {ctx.author.name}!", f"How's it going {ctx.author.name}?", f"What can I do for you {ctx.author.name}?", f"What's up {ctx.author.name}?", f"Hello {ctx.author.name}!", f"So {ctx.author.name}, how's your day going?"]
await ctx.send(random.choice(greetings))
@bot.command(aliases=["img", "gif"])
async def sendCoolPhotos(ctx):
embed = nextcord.Embed(color=color)
embed.set_author(name="", icon_url=ctx.author.avatar.url)
embed.set_image(url=random.choice(hello_urls))
await ctx.send(embed=embed)
@bot.command(aliases=["help", "use"])
async def embed_help(ctx):
message = await ctx.send(embed=help_menu())
await message.add_reaction("⬅")
await message.add_reaction("🕸")
await message.add_reaction("➡")
@bot.command(aliases=["quips"])
async def get_quips(ctx):
try:
embed = nextcord.Embed(title=random.choice(titles), description=random.choice(dialogue_list), color=color)
embed.set_thumbnail(url=random.choice(url_thumbnails))
embed.set_footer(text=random.choice(footers), icon_url=bot.user.avatar.url)
await ctx.send(embed=embed)
print("Quip successfully sent!")
except Exception as e:
embed = nextcord.Embed(title="Error", description=str(e), color=color)
# ----------------------------------------------- INTERNET ---------------------------------------------
@bot.command(aliases=["imdb"])
async def IMDb_movies(ctx, *, movie_name=None):
if movie_name is None:
embed = nextcord.Embed(description=random.choice(imdb_responses), color=color)
embed.set_author(name="Ahem ahem", icon_url=url_imdb_author)
await ctx.send(embed=embed)
if movie_name is not None:
try:
db = imdb.IMDb()
movie = db.search_movie(movie_name)
title = movie[0]["title"]
movie_summary = (
db.get_movie(movie[0].getID()).summary()
.replace("=", "")
.replace("Title", "**Title**")
.replace("Movie", "")
.replace("Genres", "**Genres**")
.replace("Director", "**Director**")
.replace("Writer", "**Writer(s)**")
.replace("Cast", "**Cast**")
.replace("Country", "**Country**")
.replace("Language", "**Language**")
.replace("Rating", "**Rating**")
.replace("Plot", "**Plot**")
.replace("Runtime", "**Runtime (mins)**")
)
movie_cover = movie[0]["full-size cover url"]
embed = nextcord.Embed(title="🎬 {} 🍿".format(title), description=movie_summary, color=color)
embed.set_thumbnail(url=url_imdb_thumbnail) # 🎥 🎬 📽
embed.set_image(url=movie_cover)
await ctx.send(embed=embed)
except Exception:
embed = nextcord.Embed(description="I couldn't find `{}`.\nTry again and make sure you enter the correct movie name.".format(movie_name), color=color)
embed.set_author(name="Movie Not Found 💬", icon_url=url_imdb_author)
await ctx.send(embed=embed)
# @bot.command(aliases=["reddit", "rd"])
# async def reddit_memes(ctx, *, topic):
# sub = reddit.subreddit(topic).random()
# if str(ctx.guild.id) not in default_topic:
# default_topic[str(ctx.guild.id)] = str(topic)
# if str(ctx.guild.id) in default_topic:
# default_topic[str(ctx.guild.id)] = str(topic)
# try:
# embed = nextcord.Embed(description="**Caption:\n**{}".format(sub.title), color=color)
# embed.set_author(name="Post by: {}".format(sub.author), icon_url=url_reddit_author)
# # embed.set_thumbnail(url=url_reddit_thumbnail)
# embed.set_image(url=sub.url)
# embed.set_footer(text="🔺: {} 🔻: {} 💬: {}".format(sub.ups, sub.downs, sub.num_comments))
# message = await ctx.send(embed=embed)
# await message.add_reaction("🖱")
# except Exception:
# default_topic[str(ctx.guild.id)] = ""
# embed = nextcord.Embed(description="Looks like the subreddit is either banned or does not exist 🤔", color=color)
# embed.set_author(name="Subreddit Not Found", icon_url=url_reddit_author)
# await ctx.send(embed=embed)
@bot.command(aliases=["wiki", "w"])
async def wikipedia_results(ctx, *, thing_to_search):
try:
try:
title = wikipedia.page(thing_to_search)
embed = nextcord.Embed(description=wikipedia.summary(thing_to_search), color=color)
embed.set_author(name=title.title, icon_url=url_wiki)
embed.add_field(name="Search References", value=", ".join([x for x in wikipedia.search(thing_to_search)][:5]), inline=False)
embed.set_footer(text="Searched by: {}".format(ctx.author.name), icon_url=ctx.author.avatar.url)
await ctx.send(embed=embed)
print("Results for wikipedia search sent...")
except wikipedia.PageError as pe:
embed = nextcord.Embed(description=str(pe), color=color)
embed.set_author(name="Error", icon_url=url_wiki)
await ctx.send(embed=embed)
except wikipedia.DisambiguationError as de:
embed = nextcord.Embed(description=str(de), color=color)
embed.set_author(name="Hmm...", icon_url=url_wiki)
await ctx.send(embed=embed)
@bot.command(aliases=["google", "g"])
async def google_results(ctx, *, thing_to_search):
results = ""
for result in googlesearch.search(thing_to_search, 7, "en"):
results += result + "\n"
await ctx.send("Search results for: **{}**".format(thing_to_search))
await ctx.send(results)
print("Results for google search sent.")
# ------------------------------------------------- UTILITY -------------------------------------------------
@bot.command(aliases=["delete", "del"])
async def clear(ctx, num=10000000000000):
await ctx.channel.purge(limit=1)
await ctx.channel.purge(limit=num)
@bot.command(aliases=["[X]"])
async def stop_program(ctx):
voice_client = ctx.message.guild.voice_client
if ctx.author.id == 622497106657148939:
conn.commit()
try:
await voice_client.disconnect()
except:
pass
await ctx.send("Alright, see ya!")
exit()
else:
await ctx.send("Access Denied")
@bot.command(aliases=["say"])
async def replicate_user_text(ctx, *, text):
await ctx.channel.purge(limit=1)
await ctx.send(text)
@bot.command(aliases=["polls", "poll"])
async def conduct_poll(ctx, emojis=None, title=None, *, description=None):
poll_channel = None
for i in ctx.guild.channels:
for j in poll_channels:
if i.name == j:
send_to = i.name = j
poll_channel = nextcord.utils.get(ctx.guild.channels, name=send_to)
if title is not None:
if "_" in title:
title = title.replace("_", " ")
if emojis is not None and title is not None and description is not None:
embed = nextcord.Embed(title=f"Topic: {title}", description=description, color=color)
embed.set_footer(text=f"Conducted by: {ctx.author.name}", icon_url=ctx.author.avatar.url)
message = await poll_channel.send(embed=embed)
if emojis == "y/n" or emojis == "yes/no":
await message.add_reaction("✅")
await message.add_reaction("❌")
elif emojis == "t/t" or emojis == "this/that":
await message.add_reaction("👈🏻")
await message.add_reaction("👉🏻")
else:
emojis_list = list(emojis.split(","))
for emoji in emojis_list:
await message.add_reaction(emoji)
if ctx.channel.name != poll_channel:
await ctx.send(embed=nextcord.Embed(description="Poll Sent Successfully 👍🏻", color=color))
elif title is None and description is None and emojis is None:
embed = nextcord.Embed( title="Polls", description="Command: `_polls emojis title description`", color=color)
embed.add_field(name="Details", value="`emojis:` enter emojis for the poll and they will be added as reactions\n`title:` give a title to your poll.\n`description:` tell everyone what the poll is about.", inline=False)
embed.add_field(name="Notes", value="To add reactions to poll the multiple emojis should be separated by a `,`.\nIf you wish to use default emojis, `y/n` for yes or no and `t/t` for this or that.\nIf the title happens to be more than one word long, use `_` in place of spaces as demonstrated below.\nExample: `The_Ultimate_Choice` will be displayed in the title of poll as `The Ultimate Choice`.", inline=False)
embed.set_thumbnail(url=random.choice(url_thumbnails))
await ctx.send(embed=embed)
@bot.command(aliases=["req", "requests"])
async def total_requests(ctx):
operation = "SELECT MAX(number) FROM requests"
cursor.execute(operation)
total = cursor.fetchall()
embed = nextcord.Embed(description=f"""**Requests Made:\n**{str(total).replace("[(", " ").replace(",)]", " ")}""", color=color)
await ctx.send(embed=embed)
@bot.command(aliases=["web"])
async def snipe(ctx):
try:
message = deleted_messages[ctx.channel.id][-1]
if len(message) < 3:
embed = nextcord.Embed(title="Deleted Message", description=message[1], color=color)
embed.set_footer(text=f"Sent by: {bot.get_user(int(message[0]))}", icon_url=bot.get_user(int(message[0])).avatar.url,)
await ctx.send(embed=embed)
else:
embed = nextcord.Embed(description="Embed deleted 👇🏻", color=color)
embed.set_author(name=bot.get_user(int(message[0])), icon_url=bot.get_user(int(message[0])).avatar.url)
await ctx.send(embed=embed)
await ctx.send(embed=message[1])
except KeyError:
await ctx.send(embed=nextcord.Embed(description="There is nothing to web up 🕸", color=color))
@bot.command(aliases=["pfp"])
async def user_pfp(ctx, member: nextcord.Member = None):
if member is None:
embed = nextcord.Embed(title="Profile Picture : {}".format(ctx.author.name), color=color)
embed.set_image(url=ctx.author.avatar.url)
else:
embed = nextcord.Embed(title="Profile Picture : {}".format(member.name), color=color)
embed.set_image(url=member.avatar.url)
embed.set_footer(text=random.choice(compliments))
await ctx.send(embed=embed)
@bot.command(aliases=["ping"])
async def get_ping(ctx):
ping = round(bot.latency * 1000)
c1 = "🟢"
c2 = "🟡"
c3 = "🔴"
if ping >= 350:
embed = nextcord.Embed(description=f"{c3} {ping} ms", color=color)
await ctx.send(embed=embed)
elif ping <= 320:
embed = nextcord.Embed(description=f"{c1} {ping} ms", color=color)
await ctx.send(embed=embed)
elif ping > 320 and ping < 350:
embed = nextcord.Embed(description=f"{c2} {ping} ms", color=color)
await ctx.send(embed=embed)
@bot.command(aliases=["serverinfo", "si"])
async def server_information(ctx):
name = str(ctx.guild.name)
ID = str(ctx.guild.id)
description = str(ctx.guild.description)
owner = str(ctx.guild.owner)
region = str(ctx.guild.region)
num_mem = str(ctx.guild.member_count)
icon = str(ctx.guild.icon.url if ctx.guild.icon else None)
role_count = len(ctx.guild.roles)
embed = nextcord.Embed(title=f"📚 {name} 📚", color=color)
embed.add_field(name="Owner", value=f"`{owner}`", inline=True)
embed.add_field(name="Member Count", value=f"`{num_mem}`", inline=True)
embed.add_field(name="Role Count", value=f"`{role_count}`", inline=True)
embed.add_field(name="Region", value=f"`{region}`", inline=True)
embed.add_field(name="Server ID", value=f"`{ID}`", inline=False)
embed.add_field(name="Description", value=f"```{description}```", inline=False)
embed.set_footer(text=f"Created on {ctx.guild.created_at.__format__('%A, %B %d, %Y @ %H:%M:%S')}", icon_url=ctx.author.avatar.url)
embed.set_image(url=icon)
await ctx.send(embed=embed)
# --------------------------------------- ENCRYPER DECRYPTER ---------------------------------
@bot.command(aliases=["hush"])
async def encrypt_data(ctx, mode, *, message):
res = message.encode()
try:
if mode == "en":
await ctx.channel.purge(limit=1)
await ctx.send("**Message Encrypted 🔐**\n```{}```".format(str(cipher.encrypt(res).decode('utf-8'))))
if mode == "dec":
await ctx.channel.purge(limit=1)
await ctx.send("**Message Decrypted 🔓**\n```{}```".format(str(cipher.decrypt(res).decode('utf-8'))))
except Exception as error:
await ctx.send("**Error**\nSorry, I was not able to decode that. Perhaps its already decoded? 🤔\n{}".format(error))
# ------------------------------------- DATE TIME CALENDAR ---------------------------------------------
@bot.command(aliases=["dt"])
async def date_time_ist(ctx, timezone=None):
embed = nextcord.Embed(color=color)
if timezone is None:
tzinfo = pytz.timezone(default_tz)
embed.set_footer(text=f"Timezone: {default_tz}")
else:
tzinfo = pytz.timezone(timezone)
embed.set_footer(text=f"Timezone: {timezone}")
dateTime = datetime.datetime.now(tz=tzinfo)
embed.add_field(name="Date", value="%s/%s/%s" % (dateTime.day, dateTime.month, dateTime.year), inline=True)
embed.add_field(name="Time", value="%s:%s:%s" % (dateTime.hour, dateTime.minute, dateTime.second), inline=True)
await ctx.send(embed=embed)