From 12712d30fa742b642d625425dc5ae6fb3feb510b Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sun, 13 Mar 2022 18:25:27 +0530 Subject: [PATCH 01/60] Update music.py --- src/cogs/music.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index 5bf6b25e..421db1f9 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -1,4 +1,3 @@ -from turtle import color import discord import requests import json @@ -152,7 +151,7 @@ async def make_join(self, ctx): timestamp=datetime.datetime.utcnow() ) embed.set_footer(text="play request from " + ctx.author.name) - await ctx.send(mssg_) + await ctx.send(embed=embed) return True else: await ctx.voice_client.move_to(ctx.author.voice.channel) @@ -165,6 +164,7 @@ async def make_join(self, ctx): colour=0xFF0000, timestamp=datetime.datetime.utcnow() ) + embed.set_footer(text="play request from " + ctx.author.name) await ctx.send(embed=embed) return False From bf36d04bdfa45c357b21c3e590ed3293323d9df0 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sun, 13 Mar 2022 18:36:56 +0530 Subject: [PATCH 02/60] Update modset.py --- src/cogs/modset.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cogs/modset.py b/src/cogs/modset.py index d4da05f9..3adb631b 100644 --- a/src/cogs/modset.py +++ b/src/cogs/modset.py @@ -99,7 +99,7 @@ async def leave_this_server(self, ctx): await ctx.send(embed=embed) return else: - with ctx.typing(): + async with ctx.typing(): embed = discord.Embed(title="**GOOD BYE!**", description=f""" Had a great time in {ctx.guild.name}! Now it's time, I guess! @@ -112,7 +112,7 @@ async def leave_this_server(self, ctx): embed.set_footer(text="made by codechaser", icon_url="https://avatars.githubusercontent.com/u/63065397?v=4") embed.set_thumbnail(url=ctx.guild.icon_url) - await ctx.send(embed=embed) + await ctx.send(embed=embed) guild=ctx.guild await ctx.guild.leave() with open('./data/tag_messages.json', 'r') as tag_: @@ -130,7 +130,7 @@ async def leave_this_server(self, ctx): @command(name="madeby?", help="shows the creator of the bot") async def madeby(self, ctx): - with ctx.typing(): + async with ctx.typing(): embed = discord.Embed(title="Made by", description=""" **codechaser#0647** **[GitHub](https://github.com/code-chaser)** From c36aec98a7046893bac70486f59310306bf40090 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sun, 13 Mar 2022 19:07:25 +0530 Subject: [PATCH 03/60] Update music.py --- src/cogs/music.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/cogs/music.py b/src/cogs/music.py index 421db1f9..aa39f950 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -537,6 +537,8 @@ async def resume_command(self, ctx): @commands.command(name="leave", aliases=["disconnect, dc"], help="leaves if connected to any voice channel") async def leave_command(self, ctx): self.music_queue.clear() + self.currently_playing_music = None + self.currently_playing_player = None if ctx.voice_client is None: embed = discord.Embed( title="Error", @@ -617,6 +619,16 @@ async def lyrics_command(self, ctx, *args) -> None: if len(song_title)>0: song_title=song_title[:-3] else: + if self.currently_playing_player is None: + async with ctx.typing(): + embed=discord.Embed( + title="Error", + description="No song is currently playing", + color=0xff0000, + timestamp=datetime.datetime.utcnow(), + ) + await ctx.send(embed=embed) + return args=self.currently_playing_player.title.split() for arg in args: song_title+=arg+'%20' From f6ea8b9e258f3109c9450d25c5ebf4376fc35653 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sun, 13 Mar 2022 20:40:03 +0530 Subject: [PATCH 04/60] nothing much --- src/bot.py | 1 - src/cogs/__pycache__/modset.cpython-39.pyc | Bin 5312 -> 5352 bytes src/cogs/__pycache__/music.cpython-39.pyc | Bin 17662 -> 17810 bytes src/cogs/music.py | 1 - 4 files changed, 2 deletions(-) diff --git a/src/bot.py b/src/bot.py index 0098111e..daf8785b 100644 --- a/src/bot.py +++ b/src/bot.py @@ -33,7 +33,6 @@ def __init__(self, *args, **kwargs): async def get_prefix(self, message): with open('./data/prefixes.json', 'r') as pref: prefixes = json.load(pref) - print(prefixes[str(message.guild.id)]+"\n\n") return prefixes[str(message.guild.id)] + ' ' def run(self) -> None: diff --git a/src/cogs/__pycache__/modset.cpython-39.pyc b/src/cogs/__pycache__/modset.cpython-39.pyc index c7410405347557a2f24a88a8175cf2b1bccdffe9..054588722e975268852c27717c701b553f7cc7a0 100644 GIT binary patch delta 239 zcmX@0`9hO7k(ZZ?0SF@B=q7b+j3@HpA46`aGCvvA~ zgabJ&K-kO-5oTm4d}0VyQhdvRfe{QN874b&i%kB?ZO>>i*_20~F>P`vk3Hjz$y0eu z8P82V4HWq^`87~PZ?iV<9A-wL$tMJ4nXQ2I3xP^mxC^>~&ZuErz_5@3?h3!jWr8ju raJx(3c4uuqBKO3{zW@%wFM#iYgK_YnoeeXCP delta 202 zcmaE%c|emlk(ZZ?0SGeoXe2dks8`G1mY9 diff --git a/src/cogs/__pycache__/music.cpython-39.pyc b/src/cogs/__pycache__/music.cpython-39.pyc index a95dd27cb169df5f93f1a1463908a19ce1c147e9..890529981d6ebed7900d99ef5cf292b8d3986475 100644 GIT binary patch delta 5495 zcma)AYitzP6`nh@GduhA?%LqkrmzrVv2A&nM~DH31iKK@#3a~(vZ2|m_YTXhXLpu6 zvjMvc`van+L@0!-s0n?@PG8VUX{43fs*hAje>QE^v{I{)QuRkGl^<=YMygucgr0L} z?Ohfp!Isb5_dWN!-#PajfAB?e={XY3Mj}B8e$KqNe(ELrh3Jajr;LVf2XLn#I_L8?-X`o*tKb@2_*APs#b zln&7_jTA^aY$$UPBQ(E*q@(*J8l_$5B-&+2#jdkTItDE<8i$s+p%>%OlAsCNeNIYu zQ!*i?damIaUikO+kPp7h6MP5R779WAJ?vy!W0w4hXmKnj_>)S{;4&=6KwKqmAd|_N zS=-KJyxA)D^?(>`Tvi6jUAW{`nSBDA6DY(UVw48eP1xk;fAJ0L*qb7386Q+Pk(Kp?%WH`qy%2L=8 zY3iFZOmjhJp;F(%LM#HMweV-7g1VgW%Y;Q5C$)!V9Y>DuWlG~MJu7QMc^}^r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.py index aa39f950..6abf6b16 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -606,7 +606,6 @@ async def ping_command(self, ctx): def get_lyrics(self, song_title): LYRICS_API_URL = 'https://some-random-api.ml/lyrics?title=' - print('REQUESTING AT: ' + LYRICS_API_URL + song_title) response = requests.get(LYRICS_API_URL + song_title) response_json = json.loads(response.text) return response_json From 354be653f78571afbe5002621d5e8b8331c03306 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Mon, 14 Mar 2022 14:14:53 +0530 Subject: [PATCH 05/60] implemented aiohttp --- src/__pycache__/bot.cpython-39.pyc | Bin 5301 -> 5266 bytes src/cogs/__pycache__/fun.cpython-39.pyc | Bin 6900 -> 7360 bytes src/cogs/__pycache__/music.cpython-39.pyc | Bin 17810 -> 17903 bytes src/cogs/fun.py | 96 ++++++++++++---------- src/cogs/music.py | 11 +-- 5 files changed, 58 insertions(+), 49 deletions(-) diff --git a/src/__pycache__/bot.cpython-39.pyc b/src/__pycache__/bot.cpython-39.pyc index cfe6b28a2b1935da18c0769741acb294cffd02fd..10ffd17eba60316329aadbde8087e2cf124ec4c6 100644 GIT binary patch delta 287 zcmdn0IZ2Z*k(ZZ?0SGKP^^)F-ZR9)5!sNj)c^{{ldku35a}8q_OBQQ0qa;HLvp7RA zgC>jLFA+Wcl*E!m{eq&@w9JasV!f>5{JdL?MZXvoG}&&kY|iA|09PT;EsdhWm0Oq5c5^W|D-$=^46tsM z$<4eI7*!{W@R>4tZ}#HrVq#3(d{rQTiBWm7ny?~c^<)p>*^HW#p9m*1vQBmr$p-*g Ci%Km3 delta 321 zcmbQFxmA-dk(ZZ?0SE#cwUboDH}V~3VM<__Je$)}o4JIghB1pZi>;Yak|BjzoS~VK zk)Z}vltr8&m_d_uvOKGlQWX;y*Dpo|P4-(X`30$Yw^*`@^MPbeeqzck)`FtUypqWQ zte)H)Aln#u7&RCrCNE;`W7Pt3)hC;>#p@I)0hzbh((;RP6HAJ8fSe*JI3W#^BwhRu!Jjs5SYZ Ma3UkyWMz?j0BNpDbN~PV diff --git a/src/cogs/__pycache__/fun.cpython-39.pyc b/src/cogs/__pycache__/fun.cpython-39.pyc index 2eeb24c0331f398d5e4b840ca88a3a1f4655f8f8..6c4e2a4fb21808df62407f309063963648d5753a 100644 GIT binary patch delta 2836 zcmdT`TWk|Y6rI^!@2=O5<2X(nI}I^0A%sVOLMY);2t*<2L!|^rfdX>aZEzlTJiAE> zS{EeJk3P~OMgkP|!|6+)Rw`6&KdOEpp?>xuwW_L>=vRL#RVtPEp@PzT*Csf`Rn?zL z^~%SyGk3;2_nf(BZ?#|R2qY^iGyyKMtEmt76~PO0yl(0s}ReK>F(zUCzWo#v=T z@^qH0C%r@`J!Ix&POyc%VAEMT*S94n+G1XuEym;|Tk0nQ#7l6U5eqXZDc9FW))r@( zV_Vh`>Rtx``xi{lzB?B>QyQt0KGG_1CM0%WmK-IS${e?>F{fhZNXkfCeTHeKGHFK~ zG%QCNGBfE`4^v=oj?%fi_vpSoPdSQNjFFgOjvdsp;~C31ilO|bP#>zqY`FQN5)IKX z4e)w#lBPKq6CQVO{8RCjW`}0GFN>@Om-b8~N5&0DPNhduY546Nw~l9+Lz8?^T2dFo z5LHiFhLswH(Q)foIy1?t`8(2LIRS$#%%6=_^Ba;sT#J7m1R#P;Wvc!uivfODO3df# zGZ@!_DU0R>U6`e3XoLWBVqRLnoTm(P^1o-Un?ly-_;{(5k21`CJQsPXG*TzL-?L+f z;)tfj93f*mGO%Q%Czu~L#3~R12uQ)@0&NVF!Kx5K0FD>(nB4tfXrN%6f2SZL+J^!_8Gk;kzb~%z|ylAlv7$+_wYt+V;N1^F>O~X2x!fC7( zhn54hO0E#u3hYSm33c@%95dqpNVfo&dRLYtD%_I=Kj`kdx_UnG|NSA|SV~|Ss{i(o z@_O%b*#|pgYg~07@rFa2;P#=Tb=qsnc!pSn-}W}pE*{Z#b`>f}&TGqODI2rBx+hAy z$XR+goYQPgm!l*v%o1Bh92U$e=u_tRvHkp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FU|tASSIatCQB7Dh%@E2jjxk_h1j9&% z$rCI@fuj0`ob!3>&Ali%5Bt822{Vo%J>&nPJ=xW((7lbM=V5}aCGoSC0j zBnEWcEtag}{5(yz$sx8%9PGsqnaQQLj;unA5{yZcciYA?YD|{2dng8RdM#TDR}I?& z?u86xj1w4(942$w*E3F-+-2X&D+F`P1g2t+$ubW0jE6VRao}QPJT!T^V>sjC$^RV_ v7zH*bIPo*G9RgZibY^p@GY6y41t42fq(}uMv>Qb1o!sv-hw;K>9oIAfTwqkvEZ-mx}=i>OSix&Dh90$HtWv$YTLwXCN*%0um{VwM-=pDNHp?;tVy6 z;tb7OIC4y-YwRg{KS;vA{U^DChO!ywn~%F+B&cb zF!C|-Oct_>WmKA6VE0gQb1nf%6O4&(XBovvvB5~)wq diff --git a/src/cogs/fun.py b/src/cogs/fun.py index 3da74e2c..4170be28 100644 --- a/src/cogs/fun.py +++ b/src/cogs/fun.py @@ -1,57 +1,66 @@ import discord -import requests +import aiohttp import json import os import datetime import typing from discord.ext import commands + class Fun(commands.Cog): def __init__(self, bot): self.bot = bot + # ---------------------------------------------------------------------------------------------------------------------- - def get_iquote(self): - response = requests.get("https://zenquotes.io/api//random") - quote_json = json.loads(response.text) - quote = "\"" + quote_json[0]['q'] + "\" -" + quote_json[0]['a'] - return (quote_json) + async def get_iquote(self): + API_URL = "https://zenquotes.io/api//random" + async with aiohttp.ClientSession() as session: + async with session.get(API_URL) as resp: + quote_json = await resp.json() + return (quote_json) @commands.command(name="inspire", aliases=["iquote"], help="sends a random inspirational quote") async def send_iquote(self, ctx): embed = discord.Embed(title="Inspirational Quote", - colour=ctx.author.colour, - timestamp=datetime.datetime.utcnow()) - iquote = self.get_iquote() + colour=ctx.author.colour, + timestamp=datetime.datetime.utcnow()) + iquote = await self.get_iquote() embed.add_field(name="Quote", value=iquote[0]['q'], inline=False) embed.add_field(name="Author", value=iquote[0]['a'], inline=False) await ctx.send(embed=embed) + # ---------------------------------------------------------------------------------------------------------------------- - def get_nasa(self): - response = requests.get( - "https://api.nasa.gov/planetary/apod?api_key="+str(os.getenv('NASA_API_KEY'))) - response_json = json.loads(response.text) - return response_json + async def get_nasa(self): + API_URL = "https://api.nasa.gov/planetary/apod?api_key=" + \ + str(os.getenv('NASA_API_KEY')) + async with aiohttp.ClientSession() as session: + async with session.get(API_URL) as resp: + data_json = await resp.json() + return (data_json) @commands.command(name="apod", aliases=["napod", "astropic", "astropicotd"], help="sends astronomy pic of the day from NASA") async def send_nasa_pic_otd(self, ctx): embed = discord.Embed(title="NASA", - description="Picture of the day", - colour=0x0B3D91, - timestamp=datetime.datetime.utcnow()) + description="Picture of the day", + colour=0x0B3D91, + timestamp=datetime.datetime.utcnow()) embed.set_thumbnail( url="https://user-images.githubusercontent.com/63065397/156291255-4af80382-836c-4801-8b4f-47da33ea36c5.png") embed.set_footer(text="updated daily at 05:00:00 UTC [00:00:00 ET]") - nasa_api = self.get_nasa() + nasa_api = await self.get_nasa() embed.set_image(url=nasa_api["url"]) embed.add_field(name="Date", value=nasa_api["date"], inline=False) embed.add_field(name="Image Title", value=nasa_api["title"], inline=False) await ctx.send(embed=embed) + # ---------------------------------------------------------------------------------------------------------------------- - def get_covid19_details(self): - response = requests.get("https://api.covid19api.com/summary") - response_json = json.loads(response.text) - return response_json + async def get_covid19_details(self): + API_URL = "https://api.covid19api.com/summary" + async with aiohttp.ClientSession() as session: + async with session.get(API_URL) as resp: + data_json = await resp.json() + return (data_json) @commands.command(name="covid19", help="sends COVID-19 stats of the given country (global stats if country == null)") async def covid19_data(self, ctx, *args): @@ -62,7 +71,7 @@ async def covid19_data(self, ctx, *args): country = countr[:size - 1] original = country found = False - stats = self.get_covid19_details() + stats = await self.get_covid19_details() if country: for k in stats["Countries"]: if ((k["CountryCode"]).lower() == country.lower()) or ((k["Country"]).lower() == country.lower()): @@ -83,8 +92,6 @@ async def covid19_data(self, ctx, *args): ("Total Deaths", k["TotalDeaths"], True), ("Report Time (UTC)", "Date: " + k["Date"][0:10] + " & Time: " + k["Date"][11:19], True), - ("New Recovered", k["NewRecovered"], True), - ("Total Recovered", k["TotalRecovered"], True) ] for n, v, i in fields: embed.add_field(name=n, value=v, inline=i) @@ -106,8 +113,6 @@ async def covid19_data(self, ctx, *args): ("Total Confirmed Cases", k["TotalConfirmed"], True), ("New Deaths", k["NewDeaths"], True), ("Total Deaths", k["TotalDeaths"], True), - ("New Recovered", k["NewRecovered"], True), - ("Total Recovered", k["TotalRecovered"], True) ] for n, v, i in fields: embed.add_field(name=n, value=v, inline=i) @@ -122,18 +127,21 @@ async def covid19_data(self, ctx, *args): embed.add_field(name="Given Country Name", value=original, inline=True) await ctx.send(embed=embed) + # ---------------------------------------------------------------------------------------------------------------------- - def get_meme(self): - response = requests.get("https://meme-api.herokuapp.com/gimme") - response_json = json.loads(response.text) - return response_json + async def get_meme(self): + API_URL = "https://meme-api.herokuapp.com/gimme" + async with aiohttp.ClientSession() as session: + async with session.get(API_URL) as resp: + data_json = await resp.json() + return (data_json) @commands.command(name="meme", aliases=["hehe"], help="sends a random meme") async def send_meme(self, ctx): embed = discord.Embed(title="MEME", - colour=0xffee00, - timestamp=datetime.datetime.utcnow()) - meme = self.get_meme() + colour=0xffee00, + timestamp=datetime.datetime.utcnow()) + meme = await self.get_meme() embed.add_field(name="Post Link", value=meme["postLink"], inline=True) embed.add_field(name="Author", value=meme["author"], inline=True) embed.add_field(name="Header", value=meme["title"], inline=False) @@ -141,19 +149,18 @@ async def send_meme(self, ctx): embed.set_thumbnail( url="https://user-images.githubusercontent.com/63065397/156142184-0675cfee-2863-41d7-bef8-87f600a713b0.png") await ctx.send(embed=embed) + # ---------------------------------------------------------------------------------------------------------------------- - def get_subreddit(self, subreddit): - url = str("https://www.reddit.com/r/" + subreddit + ".json") - response = requests.get( - url, headers={'User-agent': 'github.com/code-chaser/dex'}) - print("requesting from : " + - str("https://www.reddit.com/r/" + subreddit + ".json") + "\n") - response_json = json.loads(response.text) - return response_json + async def get_subreddit(self, subreddit): + API_URL = str("https://www.reddit.com/r/" + subreddit + ".json") + async with aiohttp.ClientSession() as session: + async with session.get(API_URL) as resp: + data_json = await resp.json() + return (data_json) @commands.command(name="reddit", aliases=["subreddit"], help="shows top headlines of the given subreddit") async def send_subreddit(self, ctx, subreddit, number: typing.Optional[int]): - data = self.get_subreddit(subreddit) + data = await self.get_subreddit(subreddit) if ('message' in data.keys()): if data['message'] == "Not Found": embed = discord.Embed( @@ -185,7 +192,7 @@ async def send_subreddit(self, ctx, subreddit, number: typing.Optional[int]): await ctx.send(embed=embed) else: embed = discord.Embed(title=str("/r/"+subreddit), - colour=0xff5700, timestamp=datetime.datetime.utcnow()) + colour=0xff5700, timestamp=datetime.datetime.utcnow()) embed.set_thumbnail( url="https://user-images.githubusercontent.com/63065397/156344382-821872f3-b6e3-46e7-b925-b5f1a0821da8.png") i = 1 @@ -209,6 +216,7 @@ async def send_subreddit(self, ctx, subreddit, number: typing.Optional[int]): if number > 0: await ctx.send(embed=embed) return + # ---------------------------------------------------------------------------------------------------------------------- def setup(bot): diff --git a/src/cogs/music.py b/src/cogs/music.py index 6abf6b16..84025003 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -1,5 +1,5 @@ import discord -import requests +import aiohttp import json import youtube_dl import asyncio @@ -604,10 +604,11 @@ async def ping_command(self, ctx): ) await ctx.send(embed=embed) - def get_lyrics(self, song_title): + async def get_lyrics(self, song_title): LYRICS_API_URL = 'https://some-random-api.ml/lyrics?title=' - response = requests.get(LYRICS_API_URL + song_title) - response_json = json.loads(response.text) + async with aiohttp.ClientSession() as session: + async with session.get(LYRICS_API_URL + song_title) as response: + response_json = await response.json() return response_json @commands.command(name='lyrics', help='sends the lyrics of the song') @@ -633,7 +634,7 @@ async def lyrics_command(self, ctx, *args) -> None: song_title+=arg+'%20' song_title=song_title[:-3] - data = self.get_lyrics(song_title) + data = await self.get_lyrics(song_title) if not 'lyrics' in data.keys(): print('title: '+song_title) err_mssg=data['error'] From f5f552d3094dd3072b84d197f042f6677c6b6d13 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Mon, 14 Mar 2022 14:53:04 +0530 Subject: [PATCH 06/60] commit-1 --- src/cogs/__pycache__/fun.cpython-39.pyc | Bin 7360 -> 8109 bytes src/cogs/__pycache__/music.cpython-39.pyc | Bin 17903 -> 17916 bytes src/cogs/fun.py | 17 ++++++++++++++++- src/cogs/music.py | 8 ++++---- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/cogs/__pycache__/fun.cpython-39.pyc b/src/cogs/__pycache__/fun.cpython-39.pyc index 6c4e2a4fb21808df62407f309063963648d5753a..89ca66dfeda8e4b93977265293dd4238ed3ec9a5 100644 GIT binary patch delta 797 zcmZXS!D|yi6vpT6ZnkThrq!m_648}PHH}Rg5TvydMG-{_LQgJeNi)-JO0pZ@tVP3y zAok!v4`pv6lH7Vw4|?z_co0wC1D?DI{sX<}o21%;v+Qqn-+c4ln{W5i!rNl9JTekz zG=>i4SKnv1lRNNp`{UOcp4no~xQK0-e3oZj;ODsYLg#Zlx5b`)eP^Xw+$>;`+;Z0Vui(L${Y|6)rmBQ!dC^gC6A zASzCrZ0{8I^z!vQgZ_1w$Qf1FO3kzDLC}zk`MmV&Vh+n5_v>@zMm1NjTB%ztS{?NPnyzpr!haULBtX{s%`JzEl7J delta 95 zcmZ2$f54J2k(ZZ?0SNg2>Lq>9n8>$+@x;XKCs~3SG&MIbW9*P*_R|!e{6@BMa;d!V w)~1k%h{R5;l{UY;>`a)7)7W8vgNd27Z{0CO`NbN~PV diff --git a/src/cogs/__pycache__/music.cpython-39.pyc b/src/cogs/__pycache__/music.cpython-39.pyc index 19d2b5266352bf2d724f3e2acf77048e8d664e20..f3867c3b782d09e84f5158e1d602078e77bf68e8 100644 GIT binary patch delta 263 zcmaFg&G@IAkvEZ-mx}=iezEH(E!@bv(x!e5ke9+(!zj*B%T&U!fN>#%34yoMM~K8O7%l8RY3496$N2tu!ZZQEG8PeqM3v@18zj1r7Vo8|4EF)<$A w%;w0&$arY7pi?-Ilj&5z$aVloaGG3Vc!euRxyzeYNd9ABI02nGh@&Et; diff --git a/src/cogs/fun.py b/src/cogs/fun.py index 4170be28..ee302a4a 100644 --- a/src/cogs/fun.py +++ b/src/cogs/fun.py @@ -217,7 +217,22 @@ async def send_subreddit(self, ctx, subreddit, number: typing.Optional[int]): await ctx.send(embed=embed) return # ---------------------------------------------------------------------------------------------------------------------- - + + async def get_lyrics(self, song_title): + API_URL = "https://some-random-api.ml/lyrics?title=" + song_title + async with aiohttp.ClientSession() as session: + async with session.get(API_URL) as response: + data_json = await response.json() + return data_json + @commands.command(name="lyr", aliases=["lyrr"], help="sends lyrics of the given song") + async def lyrr_command(self, ctx, *args): + song='' + for arg in args: + song+=arg + song = song.replace(" ", "+") + await ctx.send("Searching for lyrics of "+song) + data=await self.get_lyrics(song) + await ctx.send(data['lyrics']) def setup(bot): bot.add_cog(Fun(bot)) diff --git a/src/cogs/music.py b/src/cogs/music.py index 84025003..5e6ae4c1 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -605,11 +605,11 @@ async def ping_command(self, ctx): await ctx.send(embed=embed) async def get_lyrics(self, song_title): - LYRICS_API_URL = 'https://some-random-api.ml/lyrics?title=' + API_URL = "https://some-random-api.ml/lyrics?title=" + song_title async with aiohttp.ClientSession() as session: - async with session.get(LYRICS_API_URL + song_title) as response: - response_json = await response.json() - return response_json + async with session.get(API_URL) as response: + data_json = await response.json() + return data_json @commands.command(name='lyrics', help='sends the lyrics of the song') async def lyrics_command(self, ctx, *args) -> None: From c5678afea1d3ff31de1b2d8e7b7db2a60a24e955 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Mon, 14 Mar 2022 15:00:45 +0530 Subject: [PATCH 07/60] lyrics-implemented --- src/cogs/fun.py | 16 ---------------- src/cogs/music.py | 1 - 2 files changed, 17 deletions(-) diff --git a/src/cogs/fun.py b/src/cogs/fun.py index ee302a4a..744e214e 100644 --- a/src/cogs/fun.py +++ b/src/cogs/fun.py @@ -217,22 +217,6 @@ async def send_subreddit(self, ctx, subreddit, number: typing.Optional[int]): await ctx.send(embed=embed) return # ---------------------------------------------------------------------------------------------------------------------- - - async def get_lyrics(self, song_title): - API_URL = "https://some-random-api.ml/lyrics?title=" + song_title - async with aiohttp.ClientSession() as session: - async with session.get(API_URL) as response: - data_json = await response.json() - return data_json - @commands.command(name="lyr", aliases=["lyrr"], help="sends lyrics of the given song") - async def lyrr_command(self, ctx, *args): - song='' - for arg in args: - song+=arg - song = song.replace(" ", "+") - await ctx.send("Searching for lyrics of "+song) - data=await self.get_lyrics(song) - await ctx.send(data['lyrics']) def setup(bot): bot.add_cog(Fun(bot)) diff --git a/src/cogs/music.py b/src/cogs/music.py index 5e6ae4c1..ed9833c0 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -636,7 +636,6 @@ async def lyrics_command(self, ctx, *args) -> None: data = await self.get_lyrics(song_title) if not 'lyrics' in data.keys(): - print('title: '+song_title) err_mssg=data['error'] embed = discord.Embed( title="Error", From d6c87fde8214f95825181f76c2a9367a79a5343b Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Mon, 14 Mar 2022 15:03:40 +0530 Subject: [PATCH 08/60] indentation and formatting --- main.py | 2 +- src/__init__.py | 2 +- src/bot.py | 6 +++--- src/cogs/fun.py | 1 + src/cogs/modset.py | 19 ++++++++-------- src/cogs/music.py | 54 +++++++++++++++++++++++++--------------------- 6 files changed, 45 insertions(+), 39 deletions(-) diff --git a/main.py b/main.py index 88db0b57..353377c5 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,4 @@ from src import Bot if __name__ == '__main__': - Bot().run() \ No newline at end of file + Bot().run() diff --git a/src/__init__.py b/src/__init__.py index b3cd2807..e34e5d92 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1 +1 @@ -from .bot import Bot \ No newline at end of file +from .bot import Bot diff --git a/src/bot.py b/src/bot.py index daf8785b..9268abb6 100644 --- a/src/bot.py +++ b/src/bot.py @@ -6,7 +6,7 @@ class Bot(commands.Bot): - + CC_LOGO_URL = 'https://avatars.githubusercontent.com/u/63065397?v=4' INTRO_IMG_URL = 'https://user-images.githubusercontent.com/63065397/156466208-ffb6db84-f0c0-4860-ab6d-48ad0f2cd5f7.png' EXHAUSTED_FACE = 'https://user-images.githubusercontent.com/63065397/156922064-95c73c2a-b6cb-402e-b24b-d79fe7bf520a.png' @@ -25,7 +25,7 @@ def __init__(self, *args, **kwargs): start=datetime.datetime(2022, 2, 24), ), ) - + for file in os.listdir('./src/cogs'): if file.endswith('.py'): self.load_extension(f'src.cogs.{file[:-3]}') @@ -93,7 +93,7 @@ async def on_message(self, message) -> None: embed.add_field(name='Author', value=target.mention, inline=True) embed.set_thumbnail(url=target.avatar_url) await message.channel.send(embed=embed) - + async def on_command_error(self, ctx, error) -> None: embed = discord.Embed( title='Status', diff --git a/src/cogs/fun.py b/src/cogs/fun.py index 744e214e..4170be28 100644 --- a/src/cogs/fun.py +++ b/src/cogs/fun.py @@ -218,5 +218,6 @@ async def send_subreddit(self, ctx, subreddit, number: typing.Optional[int]): return # ---------------------------------------------------------------------------------------------------------------------- + def setup(bot): bot.add_cog(Fun(bot)) diff --git a/src/cogs/modset.py b/src/cogs/modset.py index 3adb631b..1ff5b7b2 100644 --- a/src/cogs/modset.py +++ b/src/cogs/modset.py @@ -86,8 +86,7 @@ async def change_prefix(self, ctx, *args): embed.add_field( name="Error", value="Blank prefixes not allowed!", inline=True) await ctx.send(embed=embed) - - + @command(name="goodbyeForever!", aliases=["leaveThisServer"], help="makes the bot to leave the server (only for server owner)") async def leave_this_server(self, ctx): if ctx.author != ctx.guild.owner: @@ -110,10 +109,10 @@ async def leave_this_server(self, ctx): embed.set_author( name="dex", url="https://github.com/code-chaser/dex/issues/new", icon_url=self.bot.user.avatar_url) embed.set_footer(text="made by codechaser", - icon_url="https://avatars.githubusercontent.com/u/63065397?v=4") + icon_url="https://avatars.githubusercontent.com/u/63065397?v=4") embed.set_thumbnail(url=ctx.guild.icon_url) await ctx.send(embed=embed) - guild=ctx.guild + guild = ctx.guild await ctx.guild.leave() with open('./data/tag_messages.json', 'r') as tag_: tag_messages = json.load(tag_) @@ -127,7 +126,7 @@ async def leave_this_server(self, ctx): prefixes.pop(str(guild.id)) with open('./data/prefixes.json', 'w') as pref: json.dump(prefixes, pref, indent=4) - + @command(name="madeby?", help="shows the creator of the bot") async def madeby(self, ctx): async with ctx.typing(): @@ -135,12 +134,14 @@ async def madeby(self, ctx): **codechaser#0647** **[GitHub](https://github.com/code-chaser)** """, - color=0x8e38ce, timestamp=datetime.utcnow()) + color=0x8e38ce, timestamp=datetime.utcnow()) embed.set_author(name="dex", - url="https://github.com/code-chaser/dex/", icon_url=self.bot.user.avatar_url) - - embed.set_thumbnail(url="https://avatars.githubusercontent.com/u/63065397?v=4") + url="https://github.com/code-chaser/dex/", icon_url=self.bot.user.avatar_url) + + embed.set_thumbnail( + url="https://avatars.githubusercontent.com/u/63065397?v=4") await ctx.send(embed=embed) + def setup(bot): bot.add_cog(ModSet(bot)) diff --git a/src/cogs/music.py b/src/cogs/music.py index ed9833c0..0aacdc49 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -143,14 +143,15 @@ async def make_join(self, ctx): else: if (ctx.voice_client.is_playing() or ctx.voice_client.is_paused()) and (ctx.voice_client.channel != ctx.author.voice.channel): async with ctx.typing(): - mssg_="Can't move b/w channels while playing music!\n**NOTE: **You can still add music to the queue!" - embed=discord.Embed( + mssg_ = "Can't move b/w channels while playing music!\n**NOTE: **You can still add music to the queue!" + embed = discord.Embed( title="Error", description=mssg_, colour=0xff0000, timestamp=datetime.datetime.utcnow() ) - embed.set_footer(text="play request from " + ctx.author.name) + embed.set_footer( + text="play request from " + ctx.author.name) await ctx.send(embed=embed) return True else: @@ -234,7 +235,7 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): v = "Missing required arguements" embed.add_field(name=n, value=v, inline=False) await ctx.send(embed=embed) - + joined = await self.make_join(ctx) if joined == False: return @@ -259,7 +260,7 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): ) embed.set_thumbnail(url=self.MUSIC_ICON) embed.set_author(name=player.title, url=player.url, - icon_url=ctx.author.avatar_url) + icon_url=ctx.author.avatar_url) embed.add_field(name="Title", value=player.title, inline=False) embed.add_field(name="Queue Position", value=len( self.music_queue), inline=True) @@ -603,25 +604,25 @@ async def ping_command(self, ctx): timestamp=datetime.datetime.utcnow() ) await ctx.send(embed=embed) - + async def get_lyrics(self, song_title): API_URL = "https://some-random-api.ml/lyrics?title=" + song_title async with aiohttp.ClientSession() as session: async with session.get(API_URL) as response: data_json = await response.json() return data_json - + @commands.command(name='lyrics', help='sends the lyrics of the song') async def lyrics_command(self, ctx, *args) -> None: - song_title='' + song_title = '' for arg in args: - song_title+=arg+'%20' - if len(song_title)>0: - song_title=song_title[:-3] + song_title += arg+'%20' + if len(song_title) > 0: + song_title = song_title[:-3] else: if self.currently_playing_player is None: async with ctx.typing(): - embed=discord.Embed( + embed = discord.Embed( title="Error", description="No song is currently playing", color=0xff0000, @@ -629,30 +630,33 @@ async def lyrics_command(self, ctx, *args) -> None: ) await ctx.send(embed=embed) return - args=self.currently_playing_player.title.split() + args = self.currently_playing_player.title.split() for arg in args: - song_title+=arg+'%20' - song_title=song_title[:-3] - + song_title += arg+'%20' + song_title = song_title[:-3] + data = await self.get_lyrics(song_title) if not 'lyrics' in data.keys(): - err_mssg=data['error'] + err_mssg = data['error'] embed = discord.Embed( title="Error", - description=err_mssg+('\n'+'[see results from GoogleSearch](https://www.google.com/search?q='+song_title+'+lyrics)'), + description=err_mssg + + ('\n'+'[see results from GoogleSearch](https://www.google.com/search?q='+song_title+'+lyrics)'), colour=0xff0000, timestamp=datetime.datetime.utcnow(), ) await ctx.send(embed=embed) else: async with ctx.typing(): - lyrics=data['lyrics'] - extend_text='\n[see results from GoogleSearch](https://www.google.com/search?q='+song_title+'+lyrics)' - if len(lyrics)>3500: - lyrics=lyrics[:3500]+'... ' - extend_text='[read more](https://www.google.com/search?q='+song_title+'+lyrics)' - - embed=discord.Embed( + lyrics = data['lyrics'] + extend_text = '\n[see results from GoogleSearch](https://www.google.com/search?q=' + \ + song_title+'+lyrics)' + if len(lyrics) > 3500: + lyrics = lyrics[:3500]+'... ' + extend_text = '[read more](https://www.google.com/search?q=' + \ + song_title+'+lyrics)' + + embed = discord.Embed( title=data['title'], description=lyrics+extend_text, color=0x00ff00, From f0439579d962c008e17f2946b3ded4fbf13e503c Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Mon, 14 Mar 2022 16:53:02 +0530 Subject: [PATCH 09/60] :) --- data/prefixes.json | 3 ++- data/tag_messages.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/data/prefixes.json b/data/prefixes.json index 812efb61..165172de 100644 --- a/data/prefixes.json +++ b/data/prefixes.json @@ -5,5 +5,6 @@ "947421517317304361": "$dex", "802197877039956008": "$dex", "761902999207280690": "$dex", - "948280503952347166": "$dex" + "948280503952347166": "$dex", + "863493639685799936": "e" } \ No newline at end of file diff --git a/data/tag_messages.json b/data/tag_messages.json index d729d785..9df6f1b1 100644 --- a/data/tag_messages.json +++ b/data/tag_messages.json @@ -5,5 +5,6 @@ "947421517317304361": "on", "802197877039956008": "off", "761902999207280690": "off", - "948280503952347166": "off" + "948280503952347166": "off", + "863493639685799936": "on" } \ No newline at end of file From 777957b150885f3d9d9582335d42353d744b5a1d Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Mon, 14 Mar 2022 18:31:44 +0530 Subject: [PATCH 10/60] Update README.md --- README.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/README.md b/README.md index a103cbcc..1e3c0129 100644 --- a/README.md +++ b/README.md @@ -92,16 +92,6 @@ ___ ```python import asyncio ``` -- **requests**: - - version = `2.27.1` - - installation: - ```bash - pip install requests==2.27.1 - ``` - - import: - ```python - import requests - ``` ___
From 1273cc8de8d49ca002a3c8bcb9747789dec1dad0 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Mon, 14 Mar 2022 22:38:57 +0530 Subject: [PATCH 11/60] delete-pycache-files --- src/__pycache__/__init__.cpython-39.pyc | Bin 158 -> 0 bytes src/__pycache__/bot.cpython-39.pyc | Bin 5266 -> 0 bytes src/cogs/__pycache__/__init__.cpython-39.pyc | Bin 132 -> 0 bytes src/cogs/__pycache__/codeforces.cpython-39.pyc | Bin 1129 -> 0 bytes src/cogs/__pycache__/fun.cpython-39.pyc | Bin 8109 -> 0 bytes src/cogs/__pycache__/info.cpython-39.pyc | Bin 3963 -> 0 bytes src/cogs/__pycache__/modset.cpython-39.pyc | Bin 5352 -> 0 bytes src/cogs/__pycache__/music.cpython-39.pyc | Bin 17916 -> 0 bytes src/cogs/__pycache__/report.cpython-39.pyc | Bin 4684 -> 0 bytes 9 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/__pycache__/__init__.cpython-39.pyc delete mode 100644 src/__pycache__/bot.cpython-39.pyc delete mode 100644 src/cogs/__pycache__/__init__.cpython-39.pyc delete mode 100644 src/cogs/__pycache__/codeforces.cpython-39.pyc delete mode 100644 src/cogs/__pycache__/fun.cpython-39.pyc delete mode 100644 src/cogs/__pycache__/info.cpython-39.pyc delete mode 100644 src/cogs/__pycache__/modset.cpython-39.pyc delete mode 100644 src/cogs/__pycache__/music.cpython-39.pyc delete mode 100644 src/cogs/__pycache__/report.cpython-39.pyc diff --git a/src/__pycache__/__init__.cpython-39.pyc b/src/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index e2b4ffba59d666e17428e389e8eb52e025580a61..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 158 zcmYe~<>g`k0>d9#Ng_b{F^Gc(44TX@8G*u@ zjJKGb@=N?QnWC7J@=J<9dR8(NF#{^_nYbNH{IX+ z`n~ar#k_*w>D)x+pZgW%@6;Il8EAZf5}$`)3R4@3lU`Lvm2J(@ss={L!5Bi+=~M)0P%*yd z7)*CeW?(ea$$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LyeM>`Y`4m z>GwhOUR>lCVO!@=eilWRBquVk= z_1Te5Hvb85kesnQrK3kLU7MR*URbDc;e_7*m)b-~OBckcIys^`nSqPq!s7C^C3oTKCF8a7j?sEK@~J=?^D&;Acs^Phy$G&q$EUfSKPnm^h z@m9URRv68iV|qz1jh0HK{iVa4o-Ak5eX>!PIiuVld|6AsNKD{pmBb<+9+*#_FEpRX Wo=xBQJp{Q*ObKWfX+Ql7`hNje(E=y{ diff --git a/src/cogs/__pycache__/__init__.cpython-39.pyc b/src/cogs/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index 668fd1faa52037c45d82b3684900c530ba2d668a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 132 zcmYe~<>g`k0^L`dNg(<$h(HF6K#l_t7qb9~6oz01O-8?!3`HPe1o2DL$tuP@v&5q` u2}Y%)R>Tw+CC4P^rx(Y>$7kkcmc+;F6;$5hu*uC&Da}c>0~zrdh#3HzZXA;U diff --git a/src/cogs/__pycache__/codeforces.cpython-39.pyc b/src/cogs/__pycache__/codeforces.cpython-39.pyc deleted file mode 100644 index 3429d95df382cb0ae4251d58007ebb9ef285193f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1129 zcmZ8gOK;RL5VrH)bhj$B5)vSBLs|j5N2F4qqM&kG4&@XTS=rd#rpl|fBehjlJ+wch zJ?>xffeR}EmUi+U~g0EbaX$v)ve53UIhMDNOu z)_9MH*Cgt5dO(J2zac7_45#o3{f$zf8?6o@X~s5&si1^Mt~MZukJOTKh274v2<+CO5bJmw{-4m`^IV96Bn@8ctCl(UClWo&rzp_pQ5*@Mjo5sj;auB)GLa^EHL1)2`zBfPu`!dRs;o<6VA zVkWVZq>Z~iPgPP%E-{s8>s}i{X-4<|kCHCl#-}Xfqvw_QEdee6!OoJc5BM~-1p?j< MU%&h8jZ5?J($Z1askeqTdyivYaWcT!p z#@Il&WO`UEzIs)B#j5w-_g*<8BY6dX+1&K{FWyv?-_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vfu<{3 zRP0Yl)^bGCP|(|h^C(Pa>SlJ7<@2UF&hn#Xw#f4DNlJ;zlRq?#Q6~Ew2&Kpx(jFkM z5R9WB=n&#;^Z||?lXVl+j-$~m9p&K6Qw}1?zz&H;5+Npa!*1t4Pz~r~C`{Z(SuP|t zQ$j8}Z4gsbNDwSgL+U#@SDK=1viyqLYX3Dfz|d<3vyaWUlLh$^%|J?yPcZluweg=R G{C@z5pG=Mb diff --git a/src/cogs/__pycache__/info.cpython-39.pyc b/src/cogs/__pycache__/info.cpython-39.pyc deleted file mode 100644 index b2c392a057ff76d5e163e6d7d2915d15927038a5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3963 zcmbUkO>Z1YwX46U=fh)X;*V@#hXs?JfE;!u4p=6ejk6?Ph!?F55{=QQ-BljA_ncA5XIs|#F)Xm(` z)v%qC%nQBD5B;nb)-=sYgRCCbHS7Z12pbyq(q`5QTg13&P@mQw8nnjhM^-pP16qG* zgl$T;j9%j@?8w;c5#@g}l1Y(ADZ(_8OePuYS<3k++htU_w;7CFIXA~iN`c2(F9tAp zagk+FjugKFMT|1fJ`Nz)potymn1MQjzJ!{v4~yB<8W`061ECIeA6d*{?vg>h-x0lU z`-p@d@C3k92cAa7<5xUQ+IomQH97m?NN~Ir67uXdIf7P%<@#rnHXj$6#8I ztV3&R4IQAl)Otj~SZwJ{%_BJeJ&U?P_ca8xVNF9mK*6xC;TrM|8%N~03DR&y0CS=w57R@u^-L?ZRT_1_m*DY2HM>5IXVk#P~IHioiq43 zc^)Y9<^Be>Lwjo9Fn)Dm$2xQl-9ry_S(rLgck0p3Ba0Y!{{(t3PAz)=5!rxCzGa|0 zfN9KcPTD`ily34m#mv65wZ%xiuTyj4V-7UrsV6Tx3z3W9GB%@C(-ht~?&Owxp z;loLuf>79{gO)^lOUjMLa=+jl!wtWH9omR;$1=`~d#Wjz?92Uewwp&us)Fbs0#oXv zj+T&InF-a_uY6gI`W&_MGM3{xDHo0e)Z|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lZV< zba%qoXa>zBE@ckmQj&A3dHj^-LCK}KOXMDrBgyEf8VJLCVHrwd%#XnpegLAK6oL?J zGL(&)nQyHWLYB%-bD)+g-$34KAwcEW6!KU4pX({N&v$~-u|eBu+Vi!YH`9y|BJ7x*;EhkqXuaZr+^Br=I=>Va!DkrC>Qg|UZ`DB z6C}$|wuYu!Ds(_;2CzrSP8W5dpo^7cQEpL5WwxZglG!uz!2-mYo5}jVPLm1?AQ?Dv QPPudr5RfrOexs%T2b5s<5&!@I diff --git a/src/cogs/__pycache__/music.cpython-39.pyc b/src/cogs/__pycache__/music.cpython-39.pyc deleted file mode 100644 index f3867c3b782d09e84f5158e1d602078e77bf68e8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17916 zcmeHPTWlQHd7j%|xZGV{C6bbCuN_;_(h^14vLws0e9^_0V^Ok1+woe?dbwvv?rLv3 zGb@SPRRTmxZKP1D7A@K)PC=$=Y9&D$6nO~Jv=2#v0zv!GJQT$|6={J+c?gO&C<@kr z`u+cz8SXAA%XWf3Rm7Z~IhUDp`7hu9pZ}TaE3WTX8h)U+AIpUlI>b<8r=* zL})^p&PshU%T#ki=TNyK+c2kq| zyq2tPfA-+H=SuGL&AH%5*q6^avUsjoUvSPbvQ#wf&(T_GMQVif&zIom~&@C<*>?OK!!^I#XPnb!LxyR-x(ETe0aW z{>%1z(fPWp7TjE{-gMn+qmmnvc%v*8-T6|*t`(}blS|a2gqL`2_UMae`MdwduhahdshheNy;!d_ zt9H>)c^duF2kA0#Inzj7?W(q{xAnHUV(41iXlr?+Z7iEYU(s=I@x8(KAX6U9sBW)}}6x3$txq)Z`0z zHYYS;O`xoXva{OTntTPhkqNC9cgKaXktCjV)^|!So7>*kl;L%)M)GyU4^@7M^oJ+2#fcF)LV9G)Aw4gT)c@KVg zvO8vx22RT?V@O&Lbe(zBm&g(>AYasxECup zOSNLD?xnH5dHW)&=6UJ|WV43uH z+OQW+A36C9F+V+@JbmoB{HfEkCr-_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r?bA7x_#&O;~UE4=Z z10Rn-IgAg!rO)Ax{s_sM5DySgf_R2_>W6AHm8c$Jvsh!e=INAxY(OuQs(^kpz)(5R zSX7fpMf38!fM`eR^hYXS70nx>IHE`aD#}BkMI1608S#xT_sSzhpVcfjmL!jg$~K_MX2i~ z;7(BF%D_zkYC(Qj@~M6V_)4Z9m3*qNq^p$u$H1>tI}RL?x)a#$O+g()ixX0s-X;AR zK#i!Ggw~Vb&BwCkqzBlde~L~49-5w3uotXz<`adU%=-25=}m%m_7mj~nzV5WbY}lF zJq@GK<{6OB9FnWN3YxjphxTyK2>NvH*wugCYF_2P%5Hum|5f(OulK*5?-_{!*ceff z*~|4T%$&qbatVBlVBP>K`pwH(BGJ#;)p+cd6Ge90IgB;fFyu9x1X5GkIPyzCutdqO zKVxGcHm2UKU%hd?xx7+eyM5>GAx_kr-N0UmBjk$}77sU@ zc>c4~s2joImOY4-&UZEetVWx@%h^qA%X>0LSaJ0AF!V)flQ|u?+i6B_&~j?|w01xd zm1}3eK&x0E(mB_Vdl$)jNZvTObOY_Z6rNCfqun`fyHHvXi<3 zHABVLFHA!PeG&C)0qOwMjO>RJ)((|ifvRv&A5=K&p-MbACsgQxBapt-?_YWeXN*S= zP;utrYAuf+-H7R%O;KnzJ0b1*$QPTK31Ej@Dci<2 fT!9>Z-1^|lBaPQ(1h?`-#)9fC- Date: Mon, 14 Mar 2022 22:39:28 +0530 Subject: [PATCH 12/60] Create .gitignore --- .gitignore | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..b6e47617 --- /dev/null +++ b/.gitignore @@ -0,0 +1,129 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ From aafa54e793815ef63ba6d09c3602311dbb8fb882 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Tue, 15 Mar 2022 00:43:41 +0530 Subject: [PATCH 13/60] Update .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index b6e47617..fa8b2b69 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# vscode +.vscode + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] From 7bcfd6e28a251cb26a553790eeb8392e3144b149 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Wed, 16 Mar 2022 01:57:56 +0530 Subject: [PATCH 14/60] introduced postgreSQL --- requirements.txt | 5 ++++- src/bot.py | 42 ++++++++++++++++++++++++++++++++++++++---- src/cogs/modset.py | 8 ++++++-- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index c20f4616..e52984b2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,7 @@ youtube_dl==2021.12.17 requests==2.27.1 aiohttp==3.7.4 typing==3.7.4.3 -async-timeout==3.0.1 \ No newline at end of file +async-timeout==3.0.1 +psycopg2==2.9.3 +config==0.5.1 +configparser==5.2.0 \ No newline at end of file diff --git a/src/bot.py b/src/bot.py index 9268abb6..ce44bcd8 100644 --- a/src/bot.py +++ b/src/bot.py @@ -2,6 +2,9 @@ import json import os import datetime +import psycopg2 +from config import config +import configparser from discord.ext import commands @@ -12,8 +15,10 @@ class Bot(commands.Bot): EXHAUSTED_FACE = 'https://user-images.githubusercontent.com/63065397/156922064-95c73c2a-b6cb-402e-b24b-d79fe7bf520a.png' DEX_YELLOW = 0x8e38ce REPOSITORY_URL = 'https://github.com/code-chaser/dex/' + DB_CONNECTION = None def __init__(self, *args, **kwargs): + self.connect_to_db() super().__init__( command_prefix=self.get_prefix, intents=discord.Intents.all(), @@ -30,7 +35,23 @@ def __init__(self, *args, **kwargs): if file.endswith('.py'): self.load_extension(f'src.cogs.{file[:-3]}') + async def connect_to_db(self) -> None: + + self.DB_CONNECTION = psycopg2.connect( + host=os.getenv('DEX_DB_HOST'), + database=os.getenv('DEX_DB_NAME'), + user=os.getenv('DEX_DB_USER'), + password=os.getenv('DEX_DB_PASSWORD'), + ) + async def get_prefix(self, message): + cur = self.DB_CONNECTION.cursor() + cur.execute('SELECT prefix FROM guilds WHERE guild_id = %s;', (message.guild.id,)) + prefix = cur.fetchone() + print("ID: " + str(message.guild.id) + " prefix: " + prefix) + return prefix + + async def get_prefix_json(self, message): with open('./data/prefixes.json', 'r') as pref: prefixes = json.load(pref) return prefixes[str(message.guild.id)] + ' ' @@ -38,10 +59,17 @@ async def get_prefix(self, message): def run(self) -> None: super().run(os.getenv('BOT_TOKEN')) - async def on_ready(self) -> None: + async def on_ready(self): print('Logged in as {0.user}'.format(self)) + cur = self.DB_CONNECTION.cursor() + cur.execute('CREATE TYPE IF NOT EXISTS SWITCH AS ENUM (\'on\', \'off\');') + cur.execute('CREATE TABLE IF NOT EXISTS guilds (guild_id VARCHAR(27) NOT NULL, prefix VARCHAR(108) NOT NULL, tag_messages SWITCH NOT NULL, PRIMARY KEY (guild_id));') async def on_guild_join(self, guild) -> None: + cur = self.DB_CONNECTION.cursor() + cur.execute('INSERT INTO guilds (guild_id,prefix,tag_messages) VALUES (%s, %s, %s);', (str(guild.id), '$dex ', 'on')) + cur.close() + return with open('./data/prefixes.json', 'r') as pref: prefixes = json.load(pref) prefixes[str(guild.id)] = '$dex' @@ -59,6 +87,10 @@ async def on_guild_join(self, guild) -> None: await general.send(embed=self.intro_msg_embed(guild)) async def on_guild_remove(self, guild) -> None: + cur = self.DB_CONNECTION.cursor() + cur.execute('DELETE FROM guilds WHERE guild_id = %s;', (guild.id)) + cur.close() + return with open('./data/prefixes.json', 'r') as pref: prefixes = json.load(pref) if str(guild.id) in prefixes.keys(): @@ -74,9 +106,11 @@ async def on_guild_remove(self, guild) -> None: async def on_message(self, message) -> None: await self.process_commands(message) - with open('./data/tag_messages.json', 'r') as tag_: - tag_messages = json.load(tag_) - if tag_messages[str(message.guild.id)] == 'off': + cur = self.DB_CONNECTION.cursor() + cur.execute('SELECT tag_messages FROM guilds WHERE guild_id = %s', (message.guild.id,)) + tag_switch = cur.fetchone() + cur.close() + if tag_switch == 'off': return target = message.author if target == self.user or target.bot: diff --git a/src/cogs/modset.py b/src/cogs/modset.py index 1ff5b7b2..f747b7ca 100644 --- a/src/cogs/modset.py +++ b/src/cogs/modset.py @@ -1,4 +1,5 @@ import discord +import psycopg2 from typing import Optional from datetime import datetime from discord import Embed, Member @@ -67,7 +68,10 @@ async def change_prefix(self, ctx, *args): name="Error", value="Only server owner can change the prefix!", inline=True) await ctx.send(embed=embed) return - if (prefix != ""): + if (prefix != "") and (len(prefix) <= 27): + cur = self.bot.DB_CONNECTION.cursor() + cur.execute("UPDATE guilds SET prefix = %s WHERE id = %s;",(prefix, str(ctx.guild.id))) + cur.close() with open('./data/prefixes.json', 'r') as pref: prefixes = json.load(pref) prefixes[str(ctx.guild.id)] = prefix @@ -84,7 +88,7 @@ async def change_prefix(self, ctx, *args): colour=0xff0000, timestamp=datetime.utcnow()) embed.add_field( - name="Error", value="Blank prefixes not allowed!", inline=True) + name="Error", value="prefix length must be strictly between (0 - 28)", inline=True) await ctx.send(embed=embed) @command(name="goodbyeForever!", aliases=["leaveThisServer"], help="makes the bot to leave the server (only for server owner)") From eee4378a64f717f0cf3920f557b385d8325a8dc1 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Thu, 17 Mar 2022 11:01:58 +0530 Subject: [PATCH 15/60] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..4da91b93 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,27 @@ +--- +name: Bug report +about: Create a report to help us improve +title: "[BUG]" +labels: bug +assignees: code-chaser + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Additional context** +Add any other context about the problem here. From e2b5edb1a2783d07bddd97bc4b19dda97325d699 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Thu, 17 Mar 2022 11:07:51 +0530 Subject: [PATCH 16/60] added featureReq issue templates --- .github/ISSUE_TEMPLATE/feature_request.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..7f686984 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,21 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: "[FEATURE REQ]" +labels: featureReq +assignees: code-chaser + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. +_Example: I'm always frustrated when [...]_ + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. From d9cb8333d07e3ab93d31b79e57ac64d165e4678f Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Fri, 18 Mar 2022 09:53:40 +0530 Subject: [PATCH 17/60] Update README.md --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1e3c0129..02ff96eb 100644 --- a/README.md +++ b/README.md @@ -20,13 +20,15 @@

DESCRIPTION

It's DEX, a multi-purpose discord bot that can be used to play music, get user information, server (guild) information, get a random inspirational quote, random meme, covid-19 stats and much more, with options to set a custom prefix for each server. -
-
- -- Try it on your own server: [Invite Bot](https://discord.com/api/oauth2/authorize?client_id=946829157445296188&permissions=397590396532&scope=bot) +___ + +Default set prefix is `$dex `   (yes, mind that trailing space) + - Try it in our public Bot server: [Join Here](https://discord.gg/FUqqEyBBA3) -- See commands & features: [Here](https://github.com/code-chaser/dex/tree/main/docs/commandsAndFeatures.md) +- Try it on your own server: [Invite Bot](https://discord.com/api/oauth2/authorize?client_id=946829157445296188&permissions=397590396532&scope=bot) +Once the bot joins your server, you can get started with `$dex help` to get the complete list of available commands. +You can also check out commands & features [here](https://github.com/code-chaser/dex/tree/main/docs/commandsAndFeatures.md). ___

DEPENDENCIES

From 4310d56bbd488bcbf08fb85c83a6a3b2abf608ff Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sat, 19 Mar 2022 08:31:23 +0530 Subject: [PATCH 18/60] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 02ff96eb..00f50944 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -

From 43e50820a3734c42df5a882ab32b6eeb5f4257e9 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Wed, 23 Mar 2022 21:34:38 +0530 Subject: [PATCH 19/60] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 00f50944..b97404db 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ ___ ___ + > ***Beep boop. Boop beep! 🤖*** > ***Hope you, like it! 😛*** From eb416499ccb3f5f16275ed5ab06a1a1729bcb795 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sun, 10 Apr 2022 12:18:30 +0530 Subject: [PATCH 20/60] working fine ig --- data/prefixes.json | 10 -------- data/tag_messages.json | 10 -------- src/bot.py | 37 +++++++++++++---------------- src/cogs/modset.py | 54 ++++++++++++++++++------------------------ 4 files changed, 40 insertions(+), 71 deletions(-) delete mode 100644 data/prefixes.json delete mode 100644 data/tag_messages.json diff --git a/data/prefixes.json b/data/prefixes.json deleted file mode 100644 index 165172de..00000000 --- a/data/prefixes.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "805115382695854090": "$dex", - "946830767114309642": "$dex", - "785867687536230420": "$dex", - "947421517317304361": "$dex", - "802197877039956008": "$dex", - "761902999207280690": "$dex", - "948280503952347166": "$dex", - "863493639685799936": "e" -} \ No newline at end of file diff --git a/data/tag_messages.json b/data/tag_messages.json deleted file mode 100644 index 9df6f1b1..00000000 --- a/data/tag_messages.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "805115382695854090": "off", - "946830767114309642": "off", - "785867687536230420": "off", - "947421517317304361": "on", - "802197877039956008": "off", - "761902999207280690": "off", - "948280503952347166": "off", - "863493639685799936": "on" -} \ No newline at end of file diff --git a/src/bot.py b/src/bot.py index ce44bcd8..9c50aea6 100644 --- a/src/bot.py +++ b/src/bot.py @@ -3,7 +3,6 @@ import os import datetime import psycopg2 -from config import config import configparser from discord.ext import commands @@ -35,26 +34,21 @@ def __init__(self, *args, **kwargs): if file.endswith('.py'): self.load_extension(f'src.cogs.{file[:-3]}') - async def connect_to_db(self) -> None: + def connect_to_db(self) -> None: self.DB_CONNECTION = psycopg2.connect( host=os.getenv('DEX_DB_HOST'), database=os.getenv('DEX_DB_NAME'), user=os.getenv('DEX_DB_USER'), + port=os.getenv('DEX_DB_PORT'), password=os.getenv('DEX_DB_PASSWORD'), ) async def get_prefix(self, message): cur = self.DB_CONNECTION.cursor() - cur.execute('SELECT prefix FROM guilds WHERE guild_id = %s;', (message.guild.id,)) + cur.execute('SELECT prefix FROM guilds WHERE guild_id = \'' + str(message.guild.id) + '\';') prefix = cur.fetchone() - print("ID: " + str(message.guild.id) + " prefix: " + prefix) return prefix - - async def get_prefix_json(self, message): - with open('./data/prefixes.json', 'r') as pref: - prefixes = json.load(pref) - return prefixes[str(message.guild.id)] + ' ' def run(self) -> None: super().run(os.getenv('BOT_TOKEN')) @@ -62,13 +56,19 @@ def run(self) -> None: async def on_ready(self): print('Logged in as {0.user}'.format(self)) cur = self.DB_CONNECTION.cursor() - cur.execute('CREATE TYPE IF NOT EXISTS SWITCH AS ENUM (\'on\', \'off\');') cur.execute('CREATE TABLE IF NOT EXISTS guilds (guild_id VARCHAR(27) NOT NULL, prefix VARCHAR(108) NOT NULL, tag_messages SWITCH NOT NULL, PRIMARY KEY (guild_id));') + self.DB_CONNECTION.commit() async def on_guild_join(self, guild) -> None: cur = self.DB_CONNECTION.cursor() - cur.execute('INSERT INTO guilds (guild_id,prefix,tag_messages) VALUES (%s, %s, %s);', (str(guild.id), '$dex ', 'on')) + cur.execute('INSERT INTO guilds (guild_id,prefix,tag_messages) VALUES (\'' + str(guild.id)+'\', \'$dex \', \'on\');') + self.DB_CONNECTION.commit() cur.close() + for channel in guild.text_channels: + if channel.permissions_for(guild.me).send_messages: + general = channel + if general is not None: + await general.send(embed=self.intro_msg_embed(guild)) return with open('./data/prefixes.json', 'r') as pref: prefixes = json.load(pref) @@ -80,15 +80,11 @@ async def on_guild_join(self, guild) -> None: tag_messages[str(guild.id)] = 'on' with open('./data/tag_messages.json', 'w') as tag_: json.dump(tag_messages, tag_, indent=4) - for channel in guild.text_channels: - if channel.permissions_for(guild.me).send_messages: - general = channel - if general is not None: - await general.send(embed=self.intro_msg_embed(guild)) async def on_guild_remove(self, guild) -> None: cur = self.DB_CONNECTION.cursor() - cur.execute('DELETE FROM guilds WHERE guild_id = %s;', (guild.id)) + cur.execute('DELETE FROM guilds WHERE guild_id = \'' + str(guild.id) + '\';') + self.DB_CONNECTION.commit() cur.close() return with open('./data/prefixes.json', 'r') as pref: @@ -107,13 +103,14 @@ async def on_guild_remove(self, guild) -> None: async def on_message(self, message) -> None: await self.process_commands(message) cur = self.DB_CONNECTION.cursor() - cur.execute('SELECT tag_messages FROM guilds WHERE guild_id = %s', (message.guild.id,)) + cur.execute('SELECT tag_messages FROM guilds WHERE guild_id = \'' + str(message.guild.id) + '\';') tag_switch = cur.fetchone() cur.close() - if tag_switch == 'off': + print(tag_switch[0]) + if tag_switch[0] == 'off': return target = message.author - if target == self.user or target.bot: + if target == self.user: return embed = discord.Embed( title='Message Tagged', diff --git a/src/cogs/modset.py b/src/cogs/modset.py index f747b7ca..7c44d18a 100644 --- a/src/cogs/modset.py +++ b/src/cogs/modset.py @@ -19,17 +19,19 @@ async def modset(self, ctx, target: Optional[Member]): @command(name="tags", aliases=["tagging", "msgtag"], help="toggles message tags") async def message_tags(self, ctx, switch: Optional[str]): - with open('./data/tag_messages.json', 'r') as tag_: - tag_messages = json.load(tag_) + cur = self.bot.DB_CONNECTION.cursor() + cur.execute('SELECT tag_messages FROM guilds WHERE guild_id = \'' + str(ctx.guild.id) + '\';') + tag_messages = cur.fetchone() + tag_switch = tag_messages[0] if switch is None: - if tag_messages[str(ctx.guild.id)] == "off": - tag_messages[str(ctx.guild.id)] = "on" + if tag_switch == "off": + tag_switch = "on" else: - tag_messages[str(ctx.guild.id)] = "off" + tag_switch = "off" elif switch.lower() == "off" or switch == "0": - tag_messages[str(ctx.guild.id)] = "off" + tag_switch = "off" elif switch.lower() == "on" or switch == "1": - tag_messages[str(ctx.guild.id)] = "on" + tag_switch = "on" else: embed = Embed(title="Status", colour=0xff0000, @@ -39,19 +41,21 @@ async def message_tags(self, ctx, switch: Optional[str]): await ctx.send(embed=embed) return + cur = self.bot.DB_CONNECTION.cursor() + cur.execute('UPDATE guilds SET tag_messages = \'' + tag_switch + '\' WHERE guild_id = \'' + str(ctx.guild.id) + '\';') + self.bot.DB_CONNECTION.commit() + cur.close() embed = Embed(title="Status", colour=0x00ff00, timestamp=datetime.utcnow()) - - with open('./data/tag_messages.json', 'w') as tag_: - json.dump(tag_messages, tag_, indent=4) embed.add_field(name="Done", value="Message Tags are now " + - tag_messages[str(ctx.guild.id)], inline=True) + tag_switch, inline=True) await ctx.send(embed=embed) @command(name="changepref", aliases=["changeprefix"], help="changes the prefix to the appended string") async def change_prefix(self, ctx, *args): prefix = "".join(args) + prefix += ' ' if ctx.guild.id == int(os.environ['PUBLIC_BOT_SERVER']): embed = Embed(title="Status", colour=0xff0000, @@ -70,19 +74,15 @@ async def change_prefix(self, ctx, *args): return if (prefix != "") and (len(prefix) <= 27): cur = self.bot.DB_CONNECTION.cursor() - cur.execute("UPDATE guilds SET prefix = %s WHERE id = %s;",(prefix, str(ctx.guild.id))) + cur.execute("UPDATE guilds SET prefix = \'"+prefix+"\' WHERE guild_id = \'"+str(ctx.guild.id)+"\';") + self.bot.DB_CONNECTION.commit() cur.close() - with open('./data/prefixes.json', 'r') as pref: - prefixes = json.load(pref) - prefixes[str(ctx.guild.id)] = prefix embed = Embed(title="Status", colour=0x00ff00, timestamp=datetime.utcnow()) embed.add_field( name="Done", value="New Prefix is " + prefix, inline=True) await ctx.send(embed=embed) - with open('./data/prefixes.json', 'w') as pref: - json.dump(prefixes, pref, indent=4) else: embed = Embed(title="Status", colour=0xff0000, @@ -91,7 +91,7 @@ async def change_prefix(self, ctx, *args): name="Error", value="prefix length must be strictly between (0 - 28)", inline=True) await ctx.send(embed=embed) - @command(name="goodbyeForever!", aliases=["leaveThisServer"], help="makes the bot to leave the server (only for server owner)") + @command(name="goodbye!", aliases=["leaveThisServer"], help="makes the bot to leave the server (only for server owner)") async def leave_this_server(self, ctx): if ctx.author != ctx.guild.owner: embed = Embed(title="Status", @@ -100,7 +100,6 @@ async def leave_this_server(self, ctx): embed.add_field( name="Error", value="Only server owner can use this command!", inline=True) await ctx.send(embed=embed) - return else: async with ctx.typing(): embed = discord.Embed(title="**GOOD BYE!**", description=f""" @@ -118,18 +117,11 @@ async def leave_this_server(self, ctx): await ctx.send(embed=embed) guild = ctx.guild await ctx.guild.leave() - with open('./data/tag_messages.json', 'r') as tag_: - tag_messages = json.load(tag_) - if str(guild.id) in tag_messages.keys(): - tag_messages.pop(str(guild.id)) - with open('./data/tag_messages.json', 'w') as tag_: - json.dump(tag_messages, tag_, indent=4) - with open('./data/prefixes.json', 'r') as pref: - prefixes = json.load(pref) - if str(guild.id) in prefixes.keys(): - prefixes.pop(str(guild.id)) - with open('./data/prefixes.json', 'w') as pref: - json.dump(prefixes, pref, indent=4) + cur=self.bot.DB_CONNECTION.cursor() + cur.execute("DELETE FROM guilds WHERE guild_id = \'"+str(guild.id)+"\';") + self.bot.DB_CONNECTION.commit() + cur.close() + return @command(name="madeby?", help="shows the creator of the bot") async def madeby(self, ctx): From d224b90540ab0c64157632eb55e9a10bd7bbc797 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sun, 10 Apr 2022 12:22:19 +0530 Subject: [PATCH 21/60] shifted to using postgreSQL as DB --- src/bot.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/src/bot.py b/src/bot.py index 9c50aea6..091a7a28 100644 --- a/src/bot.py +++ b/src/bot.py @@ -70,16 +70,6 @@ async def on_guild_join(self, guild) -> None: if general is not None: await general.send(embed=self.intro_msg_embed(guild)) return - with open('./data/prefixes.json', 'r') as pref: - prefixes = json.load(pref) - prefixes[str(guild.id)] = '$dex' - with open('./data/prefixes.json', 'w') as pref: - json.dump(prefixes, pref, indent=4) - with open('./data/tag_messages.json', 'r') as tag_: - tag_messages = json.load(tag_) - tag_messages[str(guild.id)] = 'on' - with open('./data/tag_messages.json', 'w') as tag_: - json.dump(tag_messages, tag_, indent=4) async def on_guild_remove(self, guild) -> None: cur = self.DB_CONNECTION.cursor() @@ -87,18 +77,6 @@ async def on_guild_remove(self, guild) -> None: self.DB_CONNECTION.commit() cur.close() return - with open('./data/prefixes.json', 'r') as pref: - prefixes = json.load(pref) - if str(guild.id) in prefixes.keys(): - prefixes.pop(str(guild.id)) - with open('./data/prefixes.json', 'w') as pref: - json.dump(prefixes, pref, indent=4) - with open('./data/tag_messages.json', 'r') as tag_: - tag_messages = json.load(tag_) - if str(guild.id) in tag_messages.keys(): - tag_messages.pop(str(guild.id)) - with open('./data/tag_messages.json', 'w') as tag_: - json.dump(tag_messages, tag_, indent=4) async def on_message(self, message) -> None: await self.process_commands(message) From 279c3bdeb077728087f00768a0e576acf79c50ef Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sun, 10 Apr 2022 16:21:30 +0530 Subject: [PATCH 22/60] Update README.md --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index b97404db..6ec43939 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,16 @@ ___ ```python import asyncio ``` +- **psycopg2**: + - version = `2.9.3` + - installation: + ```bash + pip install psycopg2==2.9.3 + ``` + - import: + ```python + import psycopg2 + ``` ___
From fe4393cf5d1568673660415eeb3f167faf2cb43c Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sun, 10 Apr 2022 16:23:13 +0530 Subject: [PATCH 23/60] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6ec43939..a544c6ef 100644 --- a/README.md +++ b/README.md @@ -77,11 +77,11 @@ ___ - version = `3.7.4.3` - installation: ```bash - pip install aiohttp==3.7.4.3 + pip install typing==3.7.4.3 ``` - import: ```python - import aiohttp + import typing ``` - **asyncio**: - version = `3.4.3` From c0158a64f6ab5f6ad1c7bf210ffa2b91ac2409bc Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sun, 10 Apr 2022 19:10:57 +0530 Subject: [PATCH 24/60] cf handle info --- src/bot.py | 1 - src/cogs/codeforces.py | 249 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 src/cogs/codeforces.py diff --git a/src/bot.py b/src/bot.py index 091a7a28..db727a7e 100644 --- a/src/bot.py +++ b/src/bot.py @@ -84,7 +84,6 @@ async def on_message(self, message) -> None: cur.execute('SELECT tag_messages FROM guilds WHERE guild_id = \'' + str(message.guild.id) + '\';') tag_switch = cur.fetchone() cur.close() - print(tag_switch[0]) if tag_switch[0] == 'off': return target = message.author diff --git a/src/cogs/codeforces.py b/src/cogs/codeforces.py new file mode 100644 index 00000000..fc6e3dc7 --- /dev/null +++ b/src/cogs/codeforces.py @@ -0,0 +1,249 @@ +import discord +import aiohttp +import json +import os +import datetime +import typing +from discord.ext import commands +from psycopg2 import Timestamp + + +class Codeforces(commands.Cog): + cf_red = 0xff0000 # 2400+ + cf_orange = 0xff8c00 # 2200 - 2399 + cf_violet = 0xb200aa # 1900 - 2199 + cf_blue = 0x0000ff # 1600 - 1899 + cf_cyan = 0x03a89e # 1400 - 1599 + cf_green = 0x008000 # 1200 - 1399 + cf_gray = 0x808080 # 0 - 1199 + def __init__(self, bot): + self.bot = bot + # ---------------------------------------------------------------------------------------------------------------------- + + async def get_user(self, username): + API_URL = "https://codeforces.com/api/user.info?handles=" + username + ";" + async with aiohttp.ClientSession() as session: + async with session.get(API_URL) as resp: + user_json = await resp.json() + return (user_json) + + @commands.command(name="cf-handle", aliases=["cf-user"], help="shows details of the requested codeforces handle") + async def send_user(self, ctx, username): + handle=await self.get_user(username) + if handle["status"]=="FAILED": + async with ctx.typing(): + embed = discord.Embed(title="Error", + description=handle["comment"], + colour=0xff0000, + timestamp=datetime.datetime.utcnow()) + await ctx.send(embed=embed) + return + async with ctx.typing(): + embed = discord.Embed(title=username, + description=(handle["result"][0]["firstName"] if "firstName" in handle["result"][0] else "") + " " + (handle["result"][0]["lastName"] if "lastName" in handle["result"][0] else ""), + colour=self.cf_red if handle["result"][0]["maxRating"]>=2400 else self.cf_orange if handle["result"][0]["maxRating"]>=2200 else self.cf_violet if handle["result"][0]["maxRating"]>=1900 else self.cf_blue if handle["result"][0]["maxRating"]>=1600 else self.cf_cyan if handle["result"][0]["maxRating"]>=1400 else self.cf_green if handle["result"][0]["maxRating"]>=1200 else self.cf_gray, + timestamp=datetime.datetime.utcnow()) + embed.add_field(name="City", value=handle["result"][0]["city"] if "city" in handle["result"][0] else "Unknown", inline=True) + embed.add_field(name="Country", value=handle["result"][0]["country"] if "country" in handle["result"][0] else "Unknown", inline=True) + embed.add_field(name="Friend of", value=handle["result"][0]["friendOfCount"], inline=True) + embed.add_field(name="Max Rating", value=handle["result"][0]["maxRating"], inline=True) + embed.add_field(name="Max Rank", value=handle["result"][0]["maxRank"], inline=True) + embed.add_field(name="Organization", value=handle["result"][0]["organization"] if handle["result"][0]["organization"]!="" else "Unknown", inline=True) + embed.add_field(name="Rating", value=handle["result"][0]["rating"], inline=True) + embed.add_field(name="Rank", value=handle["result"][0]["rank"], inline=True) + embed.add_field(name="Last Online", value=datetime.datetime.utcfromtimestamp(handle["result"][0]["lastOnlineTimeSeconds"]).strftime('%Y-%m-%d %H:%M:%S'), inline=True) + embed.set_thumbnail(url=handle["result"][0]["avatar"]) + await ctx.send(embed=embed) + # ---------------------------------------------------------------------------------------------------------------------- + + # async def get_nasa(self): + # API_URL = "https://api.nasa.gov/planetary/apod?api_key=" + \ + # str(os.getenv('NASA_API_KEY')) + # async with aiohttp.ClientSession() as session: + # async with session.get(API_URL) as resp: + # data_json = await resp.json() + # return (data_json) + + # @commands.command(name="apod", aliases=["napod", "astropic", "astropicotd"], help="sends astronomy pic of the day from NASA") + # async def send_nasa_pic_otd(self, ctx): + # embed = discord.Embed(title="NASA", + # description="Picture of the day", + # colour=0x0B3D91, + # timestamp=datetime.datetime.utcnow()) + # embed.set_thumbnail( + # url="https://user-images.githubusercontent.com/63065397/156291255-4af80382-836c-4801-8b4f-47da33ea36c5.png") + # embed.set_footer(text="updated daily at 05:00:00 UTC [00:00:00 ET]") + # nasa_api = await self.get_nasa() + # embed.set_image(url=nasa_api["url"]) + # embed.add_field(name="Date", value=nasa_api["date"], inline=False) + # embed.add_field(name="Image Title", + # value=nasa_api["title"], inline=False) + # await ctx.send(embed=embed) + # # ---------------------------------------------------------------------------------------------------------------------- + + # async def get_covid19_details(self): + # API_URL = "https://api.covid19api.com/summary" + # async with aiohttp.ClientSession() as session: + # async with session.get(API_URL) as resp: + # data_json = await resp.json() + # return (data_json) + + # @commands.command(name="covid19", help="sends COVID-19 stats of the given country (global stats if country == null)") + # async def covid19_data(self, ctx, *args): + # countr = "" + # for arg in args: + # countr += arg + " " + # size = len(countr) + # country = countr[:size - 1] + # original = country + # found = False + # stats = await self.get_covid19_details() + # if country: + # for k in stats["Countries"]: + # if ((k["CountryCode"]).lower() == country.lower()) or ((k["Country"]).lower() == country.lower()): + # embed = discord.Embed( + # title=(k["Country"]).title(), + # description="COVID-19 Statistics", + # colour=0xff0000, + # timestamp=datetime.datetime.utcnow() + # ) + # flag_url = "https://flagcdn.com/w640/" + \ + # str(k["CountryCode"]).lower() + ".jpg" + # embed.set_thumbnail(url=flag_url) + # fields = [ + # ("New Confirmed Cases", k["NewConfirmed"], True), + # ("Total Confirmed Cases", k["TotalConfirmed"], True), + # ("Country Code", k["CountryCode"], True), + # ("New Deaths", k["NewDeaths"], True), + # ("Total Deaths", k["TotalDeaths"], True), + # ("Report Time (UTC)", "Date: " + + # k["Date"][0:10] + " & Time: " + k["Date"][11:19], True), + # ] + # for n, v, i in fields: + # embed.add_field(name=n, value=v, inline=i) + # await ctx.send(embed=embed) + # found = True + # else: + # k = stats["Global"] + # embed = discord.Embed( + # title="Global", + # description="COVID-19 Statistics", + # colour=0xff0000, + # timestamp=datetime.datetime.utcnow() + # ) + # embed.set_thumbnail( + # url="https://user-images.githubusercontent.com/63065397/156144079-6f90504d-ad48-4f2e-bec5-bae31cebd858.png" + # ) + # fields = [ + # ("New Confirmed Cases", k["NewConfirmed"], True), + # ("Total Confirmed Cases", k["TotalConfirmed"], True), + # ("New Deaths", k["NewDeaths"], True), + # ("Total Deaths", k["TotalDeaths"], True), + # ] + # for n, v, i in fields: + # embed.add_field(name=n, value=v, inline=i) + # await ctx.send(embed=embed) + # found = True + # if not found: + # embed = discord.Embed( + # title="Error", + # description="Country Not Found", + # colour=0xff0000 + # ) + # embed.add_field(name="Given Country Name", + # value=original, inline=True) + # await ctx.send(embed=embed) + # # ---------------------------------------------------------------------------------------------------------------------- + + # async def get_meme(self): + # API_URL = "https://meme-api.herokuapp.com/gimme" + # async with aiohttp.ClientSession() as session: + # async with session.get(API_URL) as resp: + # data_json = await resp.json() + # return (data_json) + + # @commands.command(name="meme", aliases=["hehe"], help="sends a random meme") + # async def send_meme(self, ctx): + # embed = discord.Embed(title="MEME", + # colour=0xffee00, + # timestamp=datetime.datetime.utcnow()) + # meme = await self.get_meme() + # embed.add_field(name="Post Link", value=meme["postLink"], inline=True) + # embed.add_field(name="Author", value=meme["author"], inline=True) + # embed.add_field(name="Header", value=meme["title"], inline=False) + # embed.set_image(url=meme["url"]) + # embed.set_thumbnail( + # url="https://user-images.githubusercontent.com/63065397/156142184-0675cfee-2863-41d7-bef8-87f600a713b0.png") + # await ctx.send(embed=embed) + # # ---------------------------------------------------------------------------------------------------------------------- + + # async def get_subreddit(self, subreddit): + # API_URL = str("https://www.reddit.com/r/" + subreddit + ".json") + # async with aiohttp.ClientSession() as session: + # async with session.get(API_URL) as resp: + # data_json = await resp.json() + # return (data_json) + + # @commands.command(name="reddit", aliases=["subreddit"], help="shows top headlines of the given subreddit") + # async def send_subreddit(self, ctx, subreddit, number: typing.Optional[int]): + # data = await self.get_subreddit(subreddit) + # if ('message' in data.keys()): + # if data['message'] == "Not Found": + # embed = discord.Embed( + # title="Status", + # colour=0xff0000, + # timestamp=datetime.datetime.utcnow() + # ) + # embed.add_field(name="Error", value="Not Found", inline=True) + # embed.set_footer(text="given subreddit: "+subreddit) + # await ctx.send(embed=embed) + # return + # embed = discord.Embed( + # title="Error", + # description="API Request Fail", + # colour=0xff0000, + # timestamp=datetime.datetime.utcnow() + # ) + # for key_i in data.keys(): + # if key_i != 'message' and key_i != 'error': + # new_key = key_i + # embed.add_field(name='Error Code', value=str( + # data['error']), inline=True) + # embed.add_field(name='Error Message', value=str( + # data['message']), inline=True) + # if new_key is not None: + # embed.add_field(name=new_key.title(), value=str( + # data[new_key]), inline=True) + # embed.set_footer(text="given subreddit: "+subreddit) + # await ctx.send(embed=embed) + # else: + # embed = discord.Embed(title=str("/r/"+subreddit), + # colour=0xff5700, timestamp=datetime.datetime.utcnow()) + # embed.set_thumbnail( + # url="https://user-images.githubusercontent.com/63065397/156344382-821872f3-b6e3-46e7-b925-b5f1a0821da8.png") + # i = 1 + # if number is None: + # number = 5 + # for head in (data['data']['children']): + # embed.add_field( + # name=str(i), + # value=head['data']['title'][0:127] + "...", + # inline=False + # ) + # i += 1 + # if i > number: + # break + # if i <= number: + # embed.add_field( + # name=str(i), + # value="No more data could be received...", + # inline=False + # ) + # if number > 0: + # await ctx.send(embed=embed) + # return + # ---------------------------------------------------------------------------------------------------------------------- + + +def setup(bot): + bot.add_cog(Codeforces(bot)) From 76654adeb5d15740046ed8c28b0c313734f4a248 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Mon, 23 May 2022 08:45:42 +0530 Subject: [PATCH 25/60] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a544c6ef..bfaa624b 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,11 @@
- dex discord bot + dex discord bot
- [![Invite: Bot](https://img.shields.io/static/v1?label=%20Invite&message=dex&color=5865F2&style=for-the-badge&logo=discord)](https://discord.com/api/oauth2/authorize?client_id=946829157445296188&permissions=397590396532&scope=bot) 🌟 [![Join: Server](https://img.shields.io/static/v1?label=%20Join&message=here&color=5865F2&style=for-the-badge&logo=discord)](https://discord.gg/FUqqEyBBA3) + [![Invite: Dex](https://img.shields.io/static/v1?label=%20Invite&message=dex&color=5865F2&style=for-the-badge&logo=discord)](https://discord.com/api/oauth2/authorize?client_id=946829157445296188&permissions=283974528116&scope=bot) 🌟 [![Join: Server](https://img.shields.io/static/v1?label=%20Join&message=here&color=5865F2&style=for-the-badge&logo=discord)](https://discord.gg/FUqqEyBBA3) [![License: MIT](https://img.shields.io/static/v1?label=License&message=MIT&color=red&style=for-the-badge&logo=giphy)](https://github.com/code-chaser/dex/blob/main/LICENSE) [![Made in: Python](https://img.shields.io/static/v1?label=Made%20in&message=Python&color=yellow&style=for-the-badge&logo=python&logoColor=yellow)](https://github.com/code-chaser/dex/) [![Fork: Count](https://img.shields.io/github/forks/code-chaser/dex?color=blue&label=Forks&style=for-the-badge&logo=gitextensions)](https://github.com/code-chaser/dex/network/members) [![Star: Count](https://img.shields.io/github/stars/code-chaser/dex?color=brightgreen&label=Stars&style=for-the-badge&logo=icinga)](https://github.com/code-chaser/dex/stargazers) [![Follower: Count](https://img.shields.io/github/followers/code-chaser?color=cb5786&label=Followers&style=for-the-badge&logo=github)](https://github.com/code-chaser/) @@ -24,7 +24,7 @@ ___ Default set prefix is `$dex `   (yes, mind that trailing space) - Try it in our public Bot server: [Join Here](https://discord.gg/FUqqEyBBA3) -- Try it on your own server: [Invite Bot](https://discord.com/api/oauth2/authorize?client_id=946829157445296188&permissions=397590396532&scope=bot) +- Try it on your own server: [Invite Bot](https://discord.com/api/oauth2/authorize?client_id=946829157445296188&permissions=283974528116&scope=bot) Once the bot joins your server, you can get started with `$dex help` to get the complete list of available commands. You can also check out commands & features [here](https://github.com/code-chaser/dex/tree/main/docs/commandsAndFeatures.md). From aac242f1e51d19595e2e01afaa34041735b499ad Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Tue, 7 Jun 2022 12:09:13 +0530 Subject: [PATCH 26/60] Update commandsAndFeatures.md --- docs/commandsAndFeatures.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/commandsAndFeatures.md b/docs/commandsAndFeatures.md index 5dc39e6d..f6199f9b 100644 --- a/docs/commandsAndFeatures.md +++ b/docs/commandsAndFeatures.md @@ -195,7 +195,7 @@ ___ | ✔️ | Shows Server Information | | | Plays Music | --> - + ___ From c528c670a5f9e281aa92ad1ba7b190be755c8c62 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sat, 11 Jun 2022 20:58:26 +0530 Subject: [PATCH 27/60] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bfaa624b..42e3ab84 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@

+


From 2b8df8bbef3b7302d2cb80bec2b3c5ff8c4dcf7d Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Mon, 20 Jun 2022 01:39:19 +0530 Subject: [PATCH 28/60] [FIXED]: guild join embed bug --- README.md | 6 +-- src/bot.py | 13 +++--- src/cogs/modset.py | 2 +- src/cogs/music.py | 22 --------- src/cogs/other.py | 113 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 123 insertions(+), 33 deletions(-) create mode 100644 src/cogs/other.py diff --git a/README.md b/README.md index 42e3ab84..d2e3c9a0 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@
- dex discord bot + dex discord bot
- [![Invite: Dex](https://img.shields.io/static/v1?label=%20Invite&message=dex&color=5865F2&style=for-the-badge&logo=discord)](https://discord.com/api/oauth2/authorize?client_id=946829157445296188&permissions=283974528116&scope=bot) 🌟 [![Join: Server](https://img.shields.io/static/v1?label=%20Join&message=here&color=5865F2&style=for-the-badge&logo=discord)](https://discord.gg/FUqqEyBBA3) + [![Invite: Dex](https://img.shields.io/static/v1?label=%20Invite&message=dex&color=5865F2&style=for-the-badge&logo=discord)](https://discord.com/api/oauth2/authorize?client_id=946829157445296188&permissions=335514139760&scope=bot) 🌟 [![Join: Server](https://img.shields.io/static/v1?label=%20Join&message=here&color=5865F2&style=for-the-badge&logo=discord)](https://discord.gg/FUqqEyBBA3) [![License: MIT](https://img.shields.io/static/v1?label=License&message=MIT&color=red&style=for-the-badge&logo=giphy)](https://github.com/code-chaser/dex/blob/main/LICENSE) [![Made in: Python](https://img.shields.io/static/v1?label=Made%20in&message=Python&color=yellow&style=for-the-badge&logo=python&logoColor=yellow)](https://github.com/code-chaser/dex/) [![Fork: Count](https://img.shields.io/github/forks/code-chaser/dex?color=blue&label=Forks&style=for-the-badge&logo=gitextensions)](https://github.com/code-chaser/dex/network/members) [![Star: Count](https://img.shields.io/github/stars/code-chaser/dex?color=brightgreen&label=Stars&style=for-the-badge&logo=icinga)](https://github.com/code-chaser/dex/stargazers) [![Follower: Count](https://img.shields.io/github/followers/code-chaser?color=cb5786&label=Followers&style=for-the-badge&logo=github)](https://github.com/code-chaser/) @@ -25,7 +25,7 @@ ___ Default set prefix is `$dex `   (yes, mind that trailing space) - Try it in our public Bot server: [Join Here](https://discord.gg/FUqqEyBBA3) -- Try it on your own server: [Invite Bot](https://discord.com/api/oauth2/authorize?client_id=946829157445296188&permissions=283974528116&scope=bot) +- Try it on your own server: [Invite Bot](https://discord.com/api/oauth2/authorize?client_id=946829157445296188&permissions=335514139760&scope=bot) Once the bot joins your server, you can get started with `$dex help` to get the complete list of available commands. You can also check out commands & features [here](https://github.com/code-chaser/dex/tree/main/docs/commandsAndFeatures.md). diff --git a/src/bot.py b/src/bot.py index 091a7a28..5d9c7fc1 100644 --- a/src/bot.py +++ b/src/bot.py @@ -23,7 +23,7 @@ def __init__(self, *args, **kwargs): intents=discord.Intents.all(), activity=discord.Activity( type=discord.ActivityType.listening, - name="Stop WW3!", + name="$dex help", large_image_url=self.EXHAUSTED_FACE, small_image_url=self.EXHAUSTED_FACE, start=datetime.datetime(2022, 2, 24), @@ -130,12 +130,11 @@ async def on_command_error(self, ctx, error) -> None: await ctx.send(embed=embed) def intro_msg_embed(self, guild): - description = '' - description = description.join( - '\nThanks for adding me to ' + guild.name + '!') - description = description.join('\nUse `$dex help` to get started!') - description = description.join( - '\nVisit: '.join(self.REPOSITORY_URL)) + description = ('\nThanks for adding me to ' + guild.name + '!') + description += ('\nUse `$dex help` to get started!') + description += ('\nSource Code: [Link](') + description += (self.REPOSITORY_URL) + description += (')') embed = discord.Embed( title='**GREETINGS!**', description=description, diff --git a/src/cogs/modset.py b/src/cogs/modset.py index 7c44d18a..d2f782f5 100644 --- a/src/cogs/modset.py +++ b/src/cogs/modset.py @@ -105,7 +105,7 @@ async def leave_this_server(self, ctx): embed = discord.Embed(title="**GOOD BYE!**", description=f""" Had a great time in {ctx.guild.name}! Now it's time, I guess! - To report any issues: https://github.com/code-chaser/dex/issues/new + Report any issues: [Here](https://github.com/code-chaser/dex/issues/new) """, color=0x8e38ce, timestamp=datetime.utcnow()) embed.set_image( url="https://user-images.githubusercontent.com/63065397/156924332-3638cd0d-9cf9-4e08-b4de-6f20cedd921a.png") diff --git a/src/cogs/music.py b/src/cogs/music.py index 0aacdc49..ec76b824 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -583,28 +583,6 @@ async def skip_command(self, ctx): await ctx.send(embed=embed) ctx.voice_client.stop() - @commands.command(name="ping", aliases=["latency"], help="shows the latency of the bot") - async def ping_command(self, ctx): - async with ctx.typing(): - ping = round(self.bot.latency * 1000, 1) - high = 400 - low = 30 - red = min((ping)/high, 1) - green = 1-red - if ping >= high: - red = 1 - green = 0 - if ping <= low: - red = 0 - green = 1 - embed = discord.Embed( - title="Ping", - description="**"+str(ping)+"ms**", - colour=discord.Color.from_rgb(int(red*255), int(green*255), 0), - timestamp=datetime.datetime.utcnow() - ) - await ctx.send(embed=embed) - async def get_lyrics(self, song_title): API_URL = "https://some-random-api.ml/lyrics?title=" + song_title async with aiohttp.ClientSession() as session: diff --git a/src/cogs/other.py b/src/cogs/other.py new file mode 100644 index 00000000..273fa03a --- /dev/null +++ b/src/cogs/other.py @@ -0,0 +1,113 @@ +import discord +import aiohttp +import json +import os +import datetime +import typing +from discord.ext import commands + + +class Other(commands.Cog): + def __init__(self, bot): + self.bot = bot + # ---------------------------------------------------------------------------------------------------------------------- + + async def get_covid19_details(self): + API_URL = "https://api.covid19api.com/summary" + async with aiohttp.ClientSession() as session: + async with session.get(API_URL) as resp: + data_json = await resp.json() + return (data_json) + + @commands.command(name="covid19", help="sends COVID-19 stats of the given country (global stats if country == null)") + async def covid19_data(self, ctx, *args): + countr = "" + for arg in args: + countr += arg + " " + size = len(countr) + country = countr[:size - 1] + original = country + found = False + stats = await self.get_covid19_details() + if country: + for k in stats["Countries"]: + if ((k["CountryCode"]).lower() == country.lower()) or ((k["Country"]).lower() == country.lower()): + embed = discord.Embed( + title=(k["Country"]).title(), + description="COVID-19 Statistics", + colour=0xff0000, + timestamp=datetime.datetime.utcnow() + ) + flag_url = "https://flagcdn.com/w640/" + \ + str(k["CountryCode"]).lower() + ".jpg" + embed.set_thumbnail(url=flag_url) + fields = [ + ("New Confirmed Cases", k["NewConfirmed"], True), + ("Total Confirmed Cases", k["TotalConfirmed"], True), + ("Country Code", k["CountryCode"], True), + ("New Deaths", k["NewDeaths"], True), + ("Total Deaths", k["TotalDeaths"], True), + ("Report Time (UTC)", "Date: " + + k["Date"][0:10] + " & Time: " + k["Date"][11:19], True), + ] + for n, v, i in fields: + embed.add_field(name=n, value=v, inline=i) + await ctx.send(embed=embed) + found = True + else: + k = stats["Global"] + embed = discord.Embed( + title="Global", + description="COVID-19 Statistics", + colour=0xff0000, + timestamp=datetime.datetime.utcnow() + ) + embed.set_thumbnail( + url="https://user-images.githubusercontent.com/63065397/156144079-6f90504d-ad48-4f2e-bec5-bae31cebd858.png" + ) + fields = [ + ("New Confirmed Cases", k["NewConfirmed"], True), + ("Total Confirmed Cases", k["TotalConfirmed"], True), + ("New Deaths", k["NewDeaths"], True), + ("Total Deaths", k["TotalDeaths"], True), + ] + for n, v, i in fields: + embed.add_field(name=n, value=v, inline=i) + await ctx.send(embed=embed) + found = True + if not found: + embed = discord.Embed( + title="Error", + description="Country Not Found", + colour=0xff0000 + ) + embed.add_field(name="Given Country Name", + value=original, inline=True) + await ctx.send(embed=embed) + # ---------------------------------------------------------------------------------------------------------------------- + + @commands.command(name="ping", aliases=["latency"], help="shows the latency of the bot") + async def ping_command(self, ctx): + async with ctx.typing(): + ping = round(self.bot.latency * 1000, 1) + high = 400 + low = 30 + red = min((ping)/high, 1) + green = 1-red + if ping >= high: + red = 1 + green = 0 + if ping <= low: + red = 0 + green = 1 + embed = discord.Embed( + title="Ping", + description="**"+str(ping)+"ms**", + colour=discord.Color.from_rgb(int(red*255), int(green*255), 0), + timestamp=datetime.datetime.utcnow() + ) + await ctx.send(embed=embed) + # ---------------------------------------------------------------------------------------------------------------------- + +def setup(bot): + bot.add_cog(Other(bot)) From 9be2e13c65fc1166a4262a6977b5d488c07e4dc4 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Mon, 20 Jun 2022 01:59:34 +0530 Subject: [PATCH 29/60] new section `other` --- src/cogs/fun.py | 74 ------------------------------ src/cogs/music.py | 22 --------- src/cogs/other.py | 113 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 96 deletions(-) create mode 100644 src/cogs/other.py diff --git a/src/cogs/fun.py b/src/cogs/fun.py index 4170be28..0c0463fe 100644 --- a/src/cogs/fun.py +++ b/src/cogs/fun.py @@ -55,80 +55,6 @@ async def send_nasa_pic_otd(self, ctx): await ctx.send(embed=embed) # ---------------------------------------------------------------------------------------------------------------------- - async def get_covid19_details(self): - API_URL = "https://api.covid19api.com/summary" - async with aiohttp.ClientSession() as session: - async with session.get(API_URL) as resp: - data_json = await resp.json() - return (data_json) - - @commands.command(name="covid19", help="sends COVID-19 stats of the given country (global stats if country == null)") - async def covid19_data(self, ctx, *args): - countr = "" - for arg in args: - countr += arg + " " - size = len(countr) - country = countr[:size - 1] - original = country - found = False - stats = await self.get_covid19_details() - if country: - for k in stats["Countries"]: - if ((k["CountryCode"]).lower() == country.lower()) or ((k["Country"]).lower() == country.lower()): - embed = discord.Embed( - title=(k["Country"]).title(), - description="COVID-19 Statistics", - colour=0xff0000, - timestamp=datetime.datetime.utcnow() - ) - flag_url = "https://flagcdn.com/w640/" + \ - str(k["CountryCode"]).lower() + ".jpg" - embed.set_thumbnail(url=flag_url) - fields = [ - ("New Confirmed Cases", k["NewConfirmed"], True), - ("Total Confirmed Cases", k["TotalConfirmed"], True), - ("Country Code", k["CountryCode"], True), - ("New Deaths", k["NewDeaths"], True), - ("Total Deaths", k["TotalDeaths"], True), - ("Report Time (UTC)", "Date: " + - k["Date"][0:10] + " & Time: " + k["Date"][11:19], True), - ] - for n, v, i in fields: - embed.add_field(name=n, value=v, inline=i) - await ctx.send(embed=embed) - found = True - else: - k = stats["Global"] - embed = discord.Embed( - title="Global", - description="COVID-19 Statistics", - colour=0xff0000, - timestamp=datetime.datetime.utcnow() - ) - embed.set_thumbnail( - url="https://user-images.githubusercontent.com/63065397/156144079-6f90504d-ad48-4f2e-bec5-bae31cebd858.png" - ) - fields = [ - ("New Confirmed Cases", k["NewConfirmed"], True), - ("Total Confirmed Cases", k["TotalConfirmed"], True), - ("New Deaths", k["NewDeaths"], True), - ("Total Deaths", k["TotalDeaths"], True), - ] - for n, v, i in fields: - embed.add_field(name=n, value=v, inline=i) - await ctx.send(embed=embed) - found = True - if not found: - embed = discord.Embed( - title="Error", - description="Country Not Found", - colour=0xff0000 - ) - embed.add_field(name="Given Country Name", - value=original, inline=True) - await ctx.send(embed=embed) - # ---------------------------------------------------------------------------------------------------------------------- - async def get_meme(self): API_URL = "https://meme-api.herokuapp.com/gimme" async with aiohttp.ClientSession() as session: diff --git a/src/cogs/music.py b/src/cogs/music.py index 0aacdc49..ec76b824 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -583,28 +583,6 @@ async def skip_command(self, ctx): await ctx.send(embed=embed) ctx.voice_client.stop() - @commands.command(name="ping", aliases=["latency"], help="shows the latency of the bot") - async def ping_command(self, ctx): - async with ctx.typing(): - ping = round(self.bot.latency * 1000, 1) - high = 400 - low = 30 - red = min((ping)/high, 1) - green = 1-red - if ping >= high: - red = 1 - green = 0 - if ping <= low: - red = 0 - green = 1 - embed = discord.Embed( - title="Ping", - description="**"+str(ping)+"ms**", - colour=discord.Color.from_rgb(int(red*255), int(green*255), 0), - timestamp=datetime.datetime.utcnow() - ) - await ctx.send(embed=embed) - async def get_lyrics(self, song_title): API_URL = "https://some-random-api.ml/lyrics?title=" + song_title async with aiohttp.ClientSession() as session: diff --git a/src/cogs/other.py b/src/cogs/other.py new file mode 100644 index 00000000..273fa03a --- /dev/null +++ b/src/cogs/other.py @@ -0,0 +1,113 @@ +import discord +import aiohttp +import json +import os +import datetime +import typing +from discord.ext import commands + + +class Other(commands.Cog): + def __init__(self, bot): + self.bot = bot + # ---------------------------------------------------------------------------------------------------------------------- + + async def get_covid19_details(self): + API_URL = "https://api.covid19api.com/summary" + async with aiohttp.ClientSession() as session: + async with session.get(API_URL) as resp: + data_json = await resp.json() + return (data_json) + + @commands.command(name="covid19", help="sends COVID-19 stats of the given country (global stats if country == null)") + async def covid19_data(self, ctx, *args): + countr = "" + for arg in args: + countr += arg + " " + size = len(countr) + country = countr[:size - 1] + original = country + found = False + stats = await self.get_covid19_details() + if country: + for k in stats["Countries"]: + if ((k["CountryCode"]).lower() == country.lower()) or ((k["Country"]).lower() == country.lower()): + embed = discord.Embed( + title=(k["Country"]).title(), + description="COVID-19 Statistics", + colour=0xff0000, + timestamp=datetime.datetime.utcnow() + ) + flag_url = "https://flagcdn.com/w640/" + \ + str(k["CountryCode"]).lower() + ".jpg" + embed.set_thumbnail(url=flag_url) + fields = [ + ("New Confirmed Cases", k["NewConfirmed"], True), + ("Total Confirmed Cases", k["TotalConfirmed"], True), + ("Country Code", k["CountryCode"], True), + ("New Deaths", k["NewDeaths"], True), + ("Total Deaths", k["TotalDeaths"], True), + ("Report Time (UTC)", "Date: " + + k["Date"][0:10] + " & Time: " + k["Date"][11:19], True), + ] + for n, v, i in fields: + embed.add_field(name=n, value=v, inline=i) + await ctx.send(embed=embed) + found = True + else: + k = stats["Global"] + embed = discord.Embed( + title="Global", + description="COVID-19 Statistics", + colour=0xff0000, + timestamp=datetime.datetime.utcnow() + ) + embed.set_thumbnail( + url="https://user-images.githubusercontent.com/63065397/156144079-6f90504d-ad48-4f2e-bec5-bae31cebd858.png" + ) + fields = [ + ("New Confirmed Cases", k["NewConfirmed"], True), + ("Total Confirmed Cases", k["TotalConfirmed"], True), + ("New Deaths", k["NewDeaths"], True), + ("Total Deaths", k["TotalDeaths"], True), + ] + for n, v, i in fields: + embed.add_field(name=n, value=v, inline=i) + await ctx.send(embed=embed) + found = True + if not found: + embed = discord.Embed( + title="Error", + description="Country Not Found", + colour=0xff0000 + ) + embed.add_field(name="Given Country Name", + value=original, inline=True) + await ctx.send(embed=embed) + # ---------------------------------------------------------------------------------------------------------------------- + + @commands.command(name="ping", aliases=["latency"], help="shows the latency of the bot") + async def ping_command(self, ctx): + async with ctx.typing(): + ping = round(self.bot.latency * 1000, 1) + high = 400 + low = 30 + red = min((ping)/high, 1) + green = 1-red + if ping >= high: + red = 1 + green = 0 + if ping <= low: + red = 0 + green = 1 + embed = discord.Embed( + title="Ping", + description="**"+str(ping)+"ms**", + colour=discord.Color.from_rgb(int(red*255), int(green*255), 0), + timestamp=datetime.datetime.utcnow() + ) + await ctx.send(embed=embed) + # ---------------------------------------------------------------------------------------------------------------------- + +def setup(bot): + bot.add_cog(Other(bot)) From 3ca87cf3ecf5c56b667a543e02592046cc067304 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Mon, 20 Jun 2022 02:00:02 +0530 Subject: [PATCH 30/60] update bot.py --- README.md | 7 ++++--- docs/commandsAndFeatures.md | 3 ++- src/bot.py | 13 ++++++------- src/cogs/modset.py | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index a544c6ef..d2e3c9a0 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,16 @@

+


- dex discord bot + dex discord bot
- [![Invite: Bot](https://img.shields.io/static/v1?label=%20Invite&message=dex&color=5865F2&style=for-the-badge&logo=discord)](https://discord.com/api/oauth2/authorize?client_id=946829157445296188&permissions=397590396532&scope=bot) 🌟 [![Join: Server](https://img.shields.io/static/v1?label=%20Join&message=here&color=5865F2&style=for-the-badge&logo=discord)](https://discord.gg/FUqqEyBBA3) + [![Invite: Dex](https://img.shields.io/static/v1?label=%20Invite&message=dex&color=5865F2&style=for-the-badge&logo=discord)](https://discord.com/api/oauth2/authorize?client_id=946829157445296188&permissions=335514139760&scope=bot) 🌟 [![Join: Server](https://img.shields.io/static/v1?label=%20Join&message=here&color=5865F2&style=for-the-badge&logo=discord)](https://discord.gg/FUqqEyBBA3) [![License: MIT](https://img.shields.io/static/v1?label=License&message=MIT&color=red&style=for-the-badge&logo=giphy)](https://github.com/code-chaser/dex/blob/main/LICENSE) [![Made in: Python](https://img.shields.io/static/v1?label=Made%20in&message=Python&color=yellow&style=for-the-badge&logo=python&logoColor=yellow)](https://github.com/code-chaser/dex/) [![Fork: Count](https://img.shields.io/github/forks/code-chaser/dex?color=blue&label=Forks&style=for-the-badge&logo=gitextensions)](https://github.com/code-chaser/dex/network/members) [![Star: Count](https://img.shields.io/github/stars/code-chaser/dex?color=brightgreen&label=Stars&style=for-the-badge&logo=icinga)](https://github.com/code-chaser/dex/stargazers) [![Follower: Count](https://img.shields.io/github/followers/code-chaser?color=cb5786&label=Followers&style=for-the-badge&logo=github)](https://github.com/code-chaser/) @@ -24,7 +25,7 @@ ___ Default set prefix is `$dex `   (yes, mind that trailing space) - Try it in our public Bot server: [Join Here](https://discord.gg/FUqqEyBBA3) -- Try it on your own server: [Invite Bot](https://discord.com/api/oauth2/authorize?client_id=946829157445296188&permissions=397590396532&scope=bot) +- Try it on your own server: [Invite Bot](https://discord.com/api/oauth2/authorize?client_id=946829157445296188&permissions=335514139760&scope=bot) Once the bot joins your server, you can get started with `$dex help` to get the complete list of available commands. You can also check out commands & features [here](https://github.com/code-chaser/dex/tree/main/docs/commandsAndFeatures.md). diff --git a/docs/commandsAndFeatures.md b/docs/commandsAndFeatures.md index 5dc39e6d..f6199f9b 100644 --- a/docs/commandsAndFeatures.md +++ b/docs/commandsAndFeatures.md @@ -195,7 +195,7 @@ ___ | ✔️ | Shows Server Information | | | Plays Music | --> - + ___ diff --git a/src/bot.py b/src/bot.py index db727a7e..3e0f643d 100644 --- a/src/bot.py +++ b/src/bot.py @@ -23,7 +23,7 @@ def __init__(self, *args, **kwargs): intents=discord.Intents.all(), activity=discord.Activity( type=discord.ActivityType.listening, - name="Stop WW3!", + name="$dex help", large_image_url=self.EXHAUSTED_FACE, small_image_url=self.EXHAUSTED_FACE, start=datetime.datetime(2022, 2, 24), @@ -129,12 +129,11 @@ async def on_command_error(self, ctx, error) -> None: await ctx.send(embed=embed) def intro_msg_embed(self, guild): - description = '' - description = description.join( - '\nThanks for adding me to ' + guild.name + '!') - description = description.join('\nUse `$dex help` to get started!') - description = description.join( - '\nVisit: '.join(self.REPOSITORY_URL)) + description = ('\nThanks for adding me to ' + guild.name + '!') + description += ('\nUse `$dex help` to get started!') + description += ('\nSource Code: [Link](') + description += (self.REPOSITORY_URL) + description += (')') embed = discord.Embed( title='**GREETINGS!**', description=description, diff --git a/src/cogs/modset.py b/src/cogs/modset.py index 7c44d18a..d2f782f5 100644 --- a/src/cogs/modset.py +++ b/src/cogs/modset.py @@ -105,7 +105,7 @@ async def leave_this_server(self, ctx): embed = discord.Embed(title="**GOOD BYE!**", description=f""" Had a great time in {ctx.guild.name}! Now it's time, I guess! - To report any issues: https://github.com/code-chaser/dex/issues/new + Report any issues: [Here](https://github.com/code-chaser/dex/issues/new) """, color=0x8e38ce, timestamp=datetime.utcnow()) embed.set_image( url="https://user-images.githubusercontent.com/63065397/156924332-3638cd0d-9cf9-4e08-b4de-6f20cedd921a.png") From 748cb23de70c61326ea33bbd5fa62cd3dd31826a Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Mon, 20 Jun 2022 15:53:47 +0530 Subject: [PATCH 31/60] Update music.py --- src/cogs/music.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index ec76b824..1973de4c 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -456,13 +456,13 @@ async def jump_command(self, ctx, pos): icon_url=ctx.author.avatar_url) embed.add_field(name="Title", value=player.title, inline=False) embed.add_field(name="Remaining in queue", value=str( - len(self.music_queue)), inline=True) + len(self.music_queue)-pos), inline=True) await ctx.send(embed=embed) counter = 0 while counter < int(pos) - 1: self.music_queue.pop(0) counter += 1 - await self.skip_song(ctx) + await self.skip_command(ctx) @commands.command(name="volume", aliases=["vol"], help="changes the volume of the music player") async def volume_command(self, ctx, volume: int): From df1aea0198e5cd03a67e5803aa14a045d62d19cb Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Tue, 21 Jun 2022 13:41:10 +0530 Subject: [PATCH 32/60] nothing much --- src/bot.py | 16 ++- src/cogs/codeforces.py | 248 ++++++----------------------------------- src/cogs/modset.py | 18 +-- src/cogs/music.py | 84 +++----------- src/cogs/other.py | 3 +- 5 files changed, 77 insertions(+), 292 deletions(-) diff --git a/src/bot.py b/src/bot.py index 3e0f643d..186cb6a3 100644 --- a/src/bot.py +++ b/src/bot.py @@ -35,7 +35,7 @@ def __init__(self, *args, **kwargs): self.load_extension(f'src.cogs.{file[:-3]}') def connect_to_db(self) -> None: - + self.DB_CONNECTION = psycopg2.connect( host=os.getenv('DEX_DB_HOST'), database=os.getenv('DEX_DB_NAME'), @@ -43,10 +43,11 @@ def connect_to_db(self) -> None: port=os.getenv('DEX_DB_PORT'), password=os.getenv('DEX_DB_PASSWORD'), ) - + async def get_prefix(self, message): cur = self.DB_CONNECTION.cursor() - cur.execute('SELECT prefix FROM guilds WHERE guild_id = \'' + str(message.guild.id) + '\';') + cur.execute('SELECT prefix FROM guilds WHERE guild_id = \'' + + str(message.guild.id) + '\';') prefix = cur.fetchone() return prefix @@ -61,7 +62,8 @@ async def on_ready(self): async def on_guild_join(self, guild) -> None: cur = self.DB_CONNECTION.cursor() - cur.execute('INSERT INTO guilds (guild_id,prefix,tag_messages) VALUES (\'' + str(guild.id)+'\', \'$dex \', \'on\');') + cur.execute('INSERT INTO guilds (guild_id,prefix,tag_messages) VALUES (\'' + + str(guild.id)+'\', \'$dex \', \'on\');') self.DB_CONNECTION.commit() cur.close() for channel in guild.text_channels: @@ -73,7 +75,8 @@ async def on_guild_join(self, guild) -> None: async def on_guild_remove(self, guild) -> None: cur = self.DB_CONNECTION.cursor() - cur.execute('DELETE FROM guilds WHERE guild_id = \'' + str(guild.id) + '\';') + cur.execute('DELETE FROM guilds WHERE guild_id = \'' + + str(guild.id) + '\';') self.DB_CONNECTION.commit() cur.close() return @@ -81,7 +84,8 @@ async def on_guild_remove(self, guild) -> None: async def on_message(self, message) -> None: await self.process_commands(message) cur = self.DB_CONNECTION.cursor() - cur.execute('SELECT tag_messages FROM guilds WHERE guild_id = \'' + str(message.guild.id) + '\';') + cur.execute('SELECT tag_messages FROM guilds WHERE guild_id = \'' + + str(message.guild.id) + '\';') tag_switch = cur.fetchone() cur.close() if tag_switch[0] == 'off': diff --git a/src/cogs/codeforces.py b/src/cogs/codeforces.py index fc6e3dc7..f45f4775 100644 --- a/src/cogs/codeforces.py +++ b/src/cogs/codeforces.py @@ -9,13 +9,14 @@ class Codeforces(commands.Cog): - cf_red = 0xff0000 # 2400+ - cf_orange = 0xff8c00 # 2200 - 2399 - cf_violet = 0xb200aa # 1900 - 2199 - cf_blue = 0x0000ff # 1600 - 1899 - cf_cyan = 0x03a89e # 1400 - 1599 - cf_green = 0x008000 # 1200 - 1399 - cf_gray = 0x808080 # 0 - 1199 + cf_red = 0xff0000 # 2400+ + cf_orange = 0xff8c00 # 2200 - 2399 + cf_violet = 0xb200aa # 1900 - 2199 + cf_blue = 0x0000ff # 1600 - 1899 + cf_cyan = 0x03a89e # 1400 - 1599 + cf_green = 0x008000 # 1200 - 1399 + cf_gray = 0x808080 # 0 - 1199 + def __init__(self, bot): self.bot = bot # ---------------------------------------------------------------------------------------------------------------------- @@ -29,220 +30,43 @@ async def get_user(self, username): @commands.command(name="cf-handle", aliases=["cf-user"], help="shows details of the requested codeforces handle") async def send_user(self, ctx, username): - handle=await self.get_user(username) - if handle["status"]=="FAILED": + handle = await self.get_user(username) + if handle["status"] == "FAILED": async with ctx.typing(): embed = discord.Embed(title="Error", - description=handle["comment"], - colour=0xff0000, - timestamp=datetime.datetime.utcnow()) + description=handle["comment"], + colour=0xff0000, + timestamp=datetime.datetime.utcnow()) await ctx.send(embed=embed) return async with ctx.typing(): embed = discord.Embed(title=username, - description=(handle["result"][0]["firstName"] if "firstName" in handle["result"][0] else "") + " " + (handle["result"][0]["lastName"] if "lastName" in handle["result"][0] else ""), - colour=self.cf_red if handle["result"][0]["maxRating"]>=2400 else self.cf_orange if handle["result"][0]["maxRating"]>=2200 else self.cf_violet if handle["result"][0]["maxRating"]>=1900 else self.cf_blue if handle["result"][0]["maxRating"]>=1600 else self.cf_cyan if handle["result"][0]["maxRating"]>=1400 else self.cf_green if handle["result"][0]["maxRating"]>=1200 else self.cf_gray, - timestamp=datetime.datetime.utcnow()) - embed.add_field(name="City", value=handle["result"][0]["city"] if "city" in handle["result"][0] else "Unknown", inline=True) - embed.add_field(name="Country", value=handle["result"][0]["country"] if "country" in handle["result"][0] else "Unknown", inline=True) - embed.add_field(name="Friend of", value=handle["result"][0]["friendOfCount"], inline=True) - embed.add_field(name="Max Rating", value=handle["result"][0]["maxRating"], inline=True) - embed.add_field(name="Max Rank", value=handle["result"][0]["maxRank"], inline=True) - embed.add_field(name="Organization", value=handle["result"][0]["organization"] if handle["result"][0]["organization"]!="" else "Unknown", inline=True) - embed.add_field(name="Rating", value=handle["result"][0]["rating"], inline=True) - embed.add_field(name="Rank", value=handle["result"][0]["rank"], inline=True) - embed.add_field(name="Last Online", value=datetime.datetime.utcfromtimestamp(handle["result"][0]["lastOnlineTimeSeconds"]).strftime('%Y-%m-%d %H:%M:%S'), inline=True) + description=(handle["result"][0]["firstName"] if "firstName" in handle["result"][0] else "") + " " + ( + handle["result"][0]["lastName"] if "lastName" in handle["result"][0] else ""), + colour=self.cf_red if handle["result"][0]["maxRating"] >= 2400 else self.cf_orange if handle["result"][0]["maxRating"] >= 2200 else self.cf_violet if handle["result"][0]["maxRating"] >= 1900 else self.cf_blue if handle[ + "result"][0]["maxRating"] >= 1600 else self.cf_cyan if handle["result"][0]["maxRating"] >= 1400 else self.cf_green if handle["result"][0]["maxRating"] >= 1200 else self.cf_gray, + timestamp=datetime.datetime.utcnow()) + embed.add_field(name="City", value=handle["result"][0]["city"] + if "city" in handle["result"][0] else "Unknown", inline=True) + embed.add_field(name="Country", value=handle["result"][0]["country"] + if "country" in handle["result"][0] else "Unknown", inline=True) + embed.add_field( + name="Friend of", value=handle["result"][0]["friendOfCount"], inline=True) + embed.add_field(name="Max Rating", + value=handle["result"][0]["maxRating"], inline=True) + embed.add_field(name="Max Rank", + value=handle["result"][0]["maxRank"], inline=True) + embed.add_field(name="Organization", value=handle["result"][0]["organization"] + if handle["result"][0]["organization"] != "" else "Unknown", inline=True) + embed.add_field( + name="Rating", value=handle["result"][0]["rating"], inline=True) + embed.add_field( + name="Rank", value=handle["result"][0]["rank"], inline=True) + embed.add_field(name="Last Online", value=datetime.datetime.utcfromtimestamp( + handle["result"][0]["lastOnlineTimeSeconds"]).strftime('%Y-%m-%d %H:%M:%S'), inline=True) embed.set_thumbnail(url=handle["result"][0]["avatar"]) await ctx.send(embed=embed) # ---------------------------------------------------------------------------------------------------------------------- - - # async def get_nasa(self): - # API_URL = "https://api.nasa.gov/planetary/apod?api_key=" + \ - # str(os.getenv('NASA_API_KEY')) - # async with aiohttp.ClientSession() as session: - # async with session.get(API_URL) as resp: - # data_json = await resp.json() - # return (data_json) - - # @commands.command(name="apod", aliases=["napod", "astropic", "astropicotd"], help="sends astronomy pic of the day from NASA") - # async def send_nasa_pic_otd(self, ctx): - # embed = discord.Embed(title="NASA", - # description="Picture of the day", - # colour=0x0B3D91, - # timestamp=datetime.datetime.utcnow()) - # embed.set_thumbnail( - # url="https://user-images.githubusercontent.com/63065397/156291255-4af80382-836c-4801-8b4f-47da33ea36c5.png") - # embed.set_footer(text="updated daily at 05:00:00 UTC [00:00:00 ET]") - # nasa_api = await self.get_nasa() - # embed.set_image(url=nasa_api["url"]) - # embed.add_field(name="Date", value=nasa_api["date"], inline=False) - # embed.add_field(name="Image Title", - # value=nasa_api["title"], inline=False) - # await ctx.send(embed=embed) - # # ---------------------------------------------------------------------------------------------------------------------- - - # async def get_covid19_details(self): - # API_URL = "https://api.covid19api.com/summary" - # async with aiohttp.ClientSession() as session: - # async with session.get(API_URL) as resp: - # data_json = await resp.json() - # return (data_json) - - # @commands.command(name="covid19", help="sends COVID-19 stats of the given country (global stats if country == null)") - # async def covid19_data(self, ctx, *args): - # countr = "" - # for arg in args: - # countr += arg + " " - # size = len(countr) - # country = countr[:size - 1] - # original = country - # found = False - # stats = await self.get_covid19_details() - # if country: - # for k in stats["Countries"]: - # if ((k["CountryCode"]).lower() == country.lower()) or ((k["Country"]).lower() == country.lower()): - # embed = discord.Embed( - # title=(k["Country"]).title(), - # description="COVID-19 Statistics", - # colour=0xff0000, - # timestamp=datetime.datetime.utcnow() - # ) - # flag_url = "https://flagcdn.com/w640/" + \ - # str(k["CountryCode"]).lower() + ".jpg" - # embed.set_thumbnail(url=flag_url) - # fields = [ - # ("New Confirmed Cases", k["NewConfirmed"], True), - # ("Total Confirmed Cases", k["TotalConfirmed"], True), - # ("Country Code", k["CountryCode"], True), - # ("New Deaths", k["NewDeaths"], True), - # ("Total Deaths", k["TotalDeaths"], True), - # ("Report Time (UTC)", "Date: " + - # k["Date"][0:10] + " & Time: " + k["Date"][11:19], True), - # ] - # for n, v, i in fields: - # embed.add_field(name=n, value=v, inline=i) - # await ctx.send(embed=embed) - # found = True - # else: - # k = stats["Global"] - # embed = discord.Embed( - # title="Global", - # description="COVID-19 Statistics", - # colour=0xff0000, - # timestamp=datetime.datetime.utcnow() - # ) - # embed.set_thumbnail( - # url="https://user-images.githubusercontent.com/63065397/156144079-6f90504d-ad48-4f2e-bec5-bae31cebd858.png" - # ) - # fields = [ - # ("New Confirmed Cases", k["NewConfirmed"], True), - # ("Total Confirmed Cases", k["TotalConfirmed"], True), - # ("New Deaths", k["NewDeaths"], True), - # ("Total Deaths", k["TotalDeaths"], True), - # ] - # for n, v, i in fields: - # embed.add_field(name=n, value=v, inline=i) - # await ctx.send(embed=embed) - # found = True - # if not found: - # embed = discord.Embed( - # title="Error", - # description="Country Not Found", - # colour=0xff0000 - # ) - # embed.add_field(name="Given Country Name", - # value=original, inline=True) - # await ctx.send(embed=embed) - # # ---------------------------------------------------------------------------------------------------------------------- - - # async def get_meme(self): - # API_URL = "https://meme-api.herokuapp.com/gimme" - # async with aiohttp.ClientSession() as session: - # async with session.get(API_URL) as resp: - # data_json = await resp.json() - # return (data_json) - - # @commands.command(name="meme", aliases=["hehe"], help="sends a random meme") - # async def send_meme(self, ctx): - # embed = discord.Embed(title="MEME", - # colour=0xffee00, - # timestamp=datetime.datetime.utcnow()) - # meme = await self.get_meme() - # embed.add_field(name="Post Link", value=meme["postLink"], inline=True) - # embed.add_field(name="Author", value=meme["author"], inline=True) - # embed.add_field(name="Header", value=meme["title"], inline=False) - # embed.set_image(url=meme["url"]) - # embed.set_thumbnail( - # url="https://user-images.githubusercontent.com/63065397/156142184-0675cfee-2863-41d7-bef8-87f600a713b0.png") - # await ctx.send(embed=embed) - # # ---------------------------------------------------------------------------------------------------------------------- - - # async def get_subreddit(self, subreddit): - # API_URL = str("https://www.reddit.com/r/" + subreddit + ".json") - # async with aiohttp.ClientSession() as session: - # async with session.get(API_URL) as resp: - # data_json = await resp.json() - # return (data_json) - - # @commands.command(name="reddit", aliases=["subreddit"], help="shows top headlines of the given subreddit") - # async def send_subreddit(self, ctx, subreddit, number: typing.Optional[int]): - # data = await self.get_subreddit(subreddit) - # if ('message' in data.keys()): - # if data['message'] == "Not Found": - # embed = discord.Embed( - # title="Status", - # colour=0xff0000, - # timestamp=datetime.datetime.utcnow() - # ) - # embed.add_field(name="Error", value="Not Found", inline=True) - # embed.set_footer(text="given subreddit: "+subreddit) - # await ctx.send(embed=embed) - # return - # embed = discord.Embed( - # title="Error", - # description="API Request Fail", - # colour=0xff0000, - # timestamp=datetime.datetime.utcnow() - # ) - # for key_i in data.keys(): - # if key_i != 'message' and key_i != 'error': - # new_key = key_i - # embed.add_field(name='Error Code', value=str( - # data['error']), inline=True) - # embed.add_field(name='Error Message', value=str( - # data['message']), inline=True) - # if new_key is not None: - # embed.add_field(name=new_key.title(), value=str( - # data[new_key]), inline=True) - # embed.set_footer(text="given subreddit: "+subreddit) - # await ctx.send(embed=embed) - # else: - # embed = discord.Embed(title=str("/r/"+subreddit), - # colour=0xff5700, timestamp=datetime.datetime.utcnow()) - # embed.set_thumbnail( - # url="https://user-images.githubusercontent.com/63065397/156344382-821872f3-b6e3-46e7-b925-b5f1a0821da8.png") - # i = 1 - # if number is None: - # number = 5 - # for head in (data['data']['children']): - # embed.add_field( - # name=str(i), - # value=head['data']['title'][0:127] + "...", - # inline=False - # ) - # i += 1 - # if i > number: - # break - # if i <= number: - # embed.add_field( - # name=str(i), - # value="No more data could be received...", - # inline=False - # ) - # if number > 0: - # await ctx.send(embed=embed) - # return - # ---------------------------------------------------------------------------------------------------------------------- def setup(bot): diff --git a/src/cogs/modset.py b/src/cogs/modset.py index d2f782f5..873343f9 100644 --- a/src/cogs/modset.py +++ b/src/cogs/modset.py @@ -20,7 +20,8 @@ async def modset(self, ctx, target: Optional[Member]): @command(name="tags", aliases=["tagging", "msgtag"], help="toggles message tags") async def message_tags(self, ctx, switch: Optional[str]): cur = self.bot.DB_CONNECTION.cursor() - cur.execute('SELECT tag_messages FROM guilds WHERE guild_id = \'' + str(ctx.guild.id) + '\';') + cur.execute( + 'SELECT tag_messages FROM guilds WHERE guild_id = \'' + str(ctx.guild.id) + '\';') tag_messages = cur.fetchone() tag_switch = tag_messages[0] if switch is None: @@ -42,7 +43,8 @@ async def message_tags(self, ctx, switch: Optional[str]): return cur = self.bot.DB_CONNECTION.cursor() - cur.execute('UPDATE guilds SET tag_messages = \'' + tag_switch + '\' WHERE guild_id = \'' + str(ctx.guild.id) + '\';') + cur.execute('UPDATE guilds SET tag_messages = \'' + tag_switch + + '\' WHERE guild_id = \'' + str(ctx.guild.id) + '\';') self.bot.DB_CONNECTION.commit() cur.close() embed = Embed(title="Status", @@ -55,7 +57,6 @@ async def message_tags(self, ctx, switch: Optional[str]): @command(name="changepref", aliases=["changeprefix"], help="changes the prefix to the appended string") async def change_prefix(self, ctx, *args): prefix = "".join(args) - prefix += ' ' if ctx.guild.id == int(os.environ['PUBLIC_BOT_SERVER']): embed = Embed(title="Status", colour=0xff0000, @@ -73,8 +74,10 @@ async def change_prefix(self, ctx, *args): await ctx.send(embed=embed) return if (prefix != "") and (len(prefix) <= 27): + prefix += " " cur = self.bot.DB_CONNECTION.cursor() - cur.execute("UPDATE guilds SET prefix = \'"+prefix+"\' WHERE guild_id = \'"+str(ctx.guild.id)+"\';") + cur.execute("UPDATE guilds SET prefix = \'"+prefix + + "\' WHERE guild_id = \'"+str(ctx.guild.id)+"\';") self.bot.DB_CONNECTION.commit() cur.close() embed = Embed(title="Status", @@ -88,7 +91,7 @@ async def change_prefix(self, ctx, *args): colour=0xff0000, timestamp=datetime.utcnow()) embed.add_field( - name="Error", value="prefix length must be strictly between (0 - 28)", inline=True) + name="Error", value="prefix length must be between (1 - 27)", inline=True) await ctx.send(embed=embed) @command(name="goodbye!", aliases=["leaveThisServer"], help="makes the bot to leave the server (only for server owner)") @@ -117,8 +120,9 @@ async def leave_this_server(self, ctx): await ctx.send(embed=embed) guild = ctx.guild await ctx.guild.leave() - cur=self.bot.DB_CONNECTION.cursor() - cur.execute("DELETE FROM guilds WHERE guild_id = \'"+str(guild.id)+"\';") + cur = self.bot.DB_CONNECTION.cursor() + cur.execute("DELETE FROM guilds WHERE guild_id = \'" + + str(guild.id)+"\';") self.bot.DB_CONNECTION.commit() cur.close() return diff --git a/src/cogs/music.py b/src/cogs/music.py index 1973de4c..cd7850c6 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -81,6 +81,14 @@ class Music(commands.Cog): "\n**To avoid any further unexpected errors, make the bot rejoin the voice channel using ` leave` and then ` join`**\n")) bad_request_error_message += (''.join("**SORRY FOR THE INCONVENIENCE!**")) + embed_error_no_vc_dex = discord.Embed( + title="Error", + description=''.join( + "Dex is not in any voice channel\n**Use ` join` to make it connect to one and then use music commands**"), + colour=0xff0000, + timestamp=datetime.datetime.utcnow() + ) + MUSIC_ICON = "https://user-images.githubusercontent.com/63065397/156855077-ce6e0896-cc81-4d4d-98b8-3e7b70050afe.png" def __init__(self, bot): @@ -304,12 +312,7 @@ async def dplay_command(self, ctx, *, url): # async def loop(self, ctx): # if ctx.voice_client is None: # async with ctx.typing(): - # embed=discord.Embed( - # title="Error", - # description=''.join("Dex is not in any voice channel\n**Use ` join` to make it connect to one and then use music commands**"), - # colour=0xff0000, - # timestamp=datetime.datetime.utcnow() - # ) + # embed=self.embed_error_no_vc_dex # await ctx.send(embed=embed) # return # if (not ctx.voice_client.is_playing()) and (not ctx.voice_client.is_paused()): @@ -333,13 +336,7 @@ async def queue_command(self, ctx, *args): return if ctx.voice_client is None: async with ctx.typing(): - embed = discord.Embed( - title="Error", - description=''.join( - "Dex is not in any voice channel\n**Use ` join` to make it connect to one and then use music commands**"), - colour=0xff0000, - timestamp=datetime.datetime.utcnow() - ) + embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) return if len(self.music_queue) == 0: @@ -380,13 +377,7 @@ async def remove_command(self, ctx, pos): pos = int(pos) if ctx.voice_client is None: async with ctx.typing(): - embed = discord.Embed( - title="Error", - description=''.join( - "Dex is not in any voice channel\n**Use ` join` to make it connect to one and then use music commands**"), - colour=0xff0000, - timestamp=datetime.datetime.utcnow() - ) + embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) return if len(self.music_queue) < int(pos): @@ -423,13 +414,7 @@ async def jump_command(self, ctx, pos): pos = int(pos) if ctx.voice_client is None: async with ctx.typing(): - embed = discord.Embed( - title="Error", - description=''.join( - "Dex is not in any voice channel\n**Use ` join` to make it connect to one and then use music commands**"), - colour=0xff0000, - timestamp=datetime.datetime.utcnow() - ) + embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) return if len(self.music_queue) < int(pos): @@ -468,13 +453,7 @@ async def jump_command(self, ctx, pos): async def volume_command(self, ctx, volume: int): if ctx.voice_client is None: async with ctx.typing(): - embed = discord.Embed( - title="Error", - description=''.join( - "Dex is not in any voice channel\n**Use ` join` to make it connect to one and then use music commands**"), - colour=0xff0000, - timestamp=datetime.datetime.utcnow() - ) + embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) return ctx.voice_client.source.volume = volume / 100 @@ -492,13 +471,7 @@ async def volume_command(self, ctx, volume: int): async def stop_command(self, ctx): if ctx.voice_client is None: async with ctx.typing(): - embed = discord.Embed( - title="Error", - description=''.join( - "Dex is not in any voice channel\n**Use ` join` to make it connect to one and then use music commands**"), - colour=0xff0000, - timestamp=datetime.datetime.utcnow() - ) + embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) return if ctx.voice_client.is_playing() or ctx.voice_client.is_paused(): @@ -509,12 +482,7 @@ async def stop_command(self, ctx): @commands.command(name="pause", help="pauses the music player") async def pause_command(self, ctx): if ctx.voice_client is None: - embed = discord.Embed( - title="Error", - description=''.join( - "Dex is not in any voice channel\n**Use ` join` to make it connect to one**"), - colour=0xff0000, - timestamp=datetime.datetime.utcnow()) + embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) elif ctx.voice_client.is_playing(): ctx.voice_client.pause() @@ -522,12 +490,7 @@ async def pause_command(self, ctx): @commands.command(name="resume", help="resumes the music player") async def resume_command(self, ctx): if ctx.voice_client is None: - embed = discord.Embed( - title="Error", - description=''.join( - "Dex is not in any voice channel\n**Use ` join` to make it connect to one**"), - colour=0xff0000, - timestamp=datetime.datetime.utcnow()) + embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) elif ctx.voice_client.is_paused(): ctx.voice_client.resume() @@ -541,12 +504,7 @@ async def leave_command(self, ctx): self.currently_playing_music = None self.currently_playing_player = None if ctx.voice_client is None: - embed = discord.Embed( - title="Error", - description=''.join( - "Dex is not in any voice channel\n**Use ` join` to make it connect to one**"), - colour=0xff0000, - timestamp=datetime.datetime.utcnow()) + embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) else: await ctx.voice_client.disconnect() @@ -555,13 +513,7 @@ async def leave_command(self, ctx): async def skip_command(self, ctx): if ctx.voice_client is None: async with ctx.typing(): - embed = discord.Embed( - title="Error", - description=''.join( - "Dex is not in any voice channel\n**Use ` join` to make it connect to one**"), - colour=0xff0000, - timestamp=datetime.datetime.utcnow(), - ) + embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) else: if ctx.voice_client.is_playing() or ctx.voice_client.is_paused(): diff --git a/src/cogs/other.py b/src/cogs/other.py index 273fa03a..32ab80eb 100644 --- a/src/cogs/other.py +++ b/src/cogs/other.py @@ -85,7 +85,7 @@ async def covid19_data(self, ctx, *args): value=original, inline=True) await ctx.send(embed=embed) # ---------------------------------------------------------------------------------------------------------------------- - + @commands.command(name="ping", aliases=["latency"], help="shows the latency of the bot") async def ping_command(self, ctx): async with ctx.typing(): @@ -109,5 +109,6 @@ async def ping_command(self, ctx): await ctx.send(embed=embed) # ---------------------------------------------------------------------------------------------------------------------- + def setup(bot): bot.add_cog(Other(bot)) From 41cf551f4bdf1c0eb235c07be0187aa7470bdfa6 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Tue, 21 Jun 2022 13:53:20 +0530 Subject: [PATCH 33/60] Update music.py --- src/cogs/music.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index cd7850c6..91158975 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -63,6 +63,7 @@ class Music(commands.Cog): # queue format: # query/url(str) | download(bool) | ctx(ctx) music_queue = [] + popped = 0 currently_playing_music = () currently_playing_player = None is_playing = False @@ -198,8 +199,6 @@ async def play_music_from_player(self, ctx, *, player): f'Player error: {e}') if e else None) await ctx.send(embed=embed) - _random_int = 0 - async def keep_playing(self, ctx): while len(self.music_queue) > 0: if (not ctx.voice_client.is_playing()) and (not ctx.voice_client.is_paused()): @@ -308,7 +307,7 @@ async def dplay_command(self, ctx, *, url): await ctx.send(embed=embed) await self.keep_playing(ctx) - # @commands.command(name="loop", help="loops the currently playing song") + # @commands.command(name="repeat", help="loops the currently playing song") # async def loop(self, ctx): # if ctx.voice_client is None: # async with ctx.typing(): From 751185ba2b69db1604360864a88ce260c09c1660 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Thu, 23 Jun 2022 08:20:23 +0530 Subject: [PATCH 34/60] bugs-to-be-fixed --- music2.py | 605 ++++++++++++++++++++++++++++++++++++++++++++++ src/bot.py | 6 +- src/cogs/music.py | 286 +++++++++++++--------- 3 files changed, 778 insertions(+), 119 deletions(-) create mode 100644 music2.py diff --git a/music2.py b/music2.py new file mode 100644 index 00000000..3a4a4e2e --- /dev/null +++ b/music2.py @@ -0,0 +1,605 @@ +import discord +import aiohttp +import json +import youtube_dl +import asyncio +import typing +import datetime +from discord.ext import commands + +# Suppress noise about console usage from errors +youtube_dl.utils.bug_reports_message = lambda: '' + + +YTDL_FORMAT_OPTIONS = { + 'format': 'bestaudio/best', + 'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s', + 'restrictfilenames': True, + 'noplaylist': True, + 'nocheckcertificate': True, + 'ignoreerrors': False, + 'logtostderr': False, + 'quiet': True, + 'no_warnings': True, + 'default_search': 'auto', + # binds to ipv4 since ipv6 addresses cause issues sometimes + 'source_address': '0.0.0.0' +} + +FFMPEG_OPTIONS = { + 'options': '-vn' +} + +ytdl = youtube_dl.YoutubeDL(YTDL_FORMAT_OPTIONS) + + +class YTDLSource(discord.PCMVolumeTransformer): + + def __init__(self, source, *, data, volume=0.5): + super().__init__(source, volume) + + self.data = data + self.title = data.get('title') + self.url = data.get('url') + + @classmethod + async def from_url(cls, url, *, loop=None, stream=False): + loop = loop or asyncio.get_event_loop() + data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=not stream)) + + if data is not None: + if 'entries' in data: + # take first item from a playlist + data = data['entries'][0] + else: + return None + + filename = data['url'] if stream else ytdl.prepare_filename(data) + return cls(discord.FFmpegPCMAudio(filename, **FFMPEG_OPTIONS), data=data) + + +class Music2(commands.Cog): + + # queue format: + # query/url(str) | download(bool) | ctx(ctx) + music_queue = [] + popped = 0 + currently_playing_music = () + currently_playing_player = None + is_playing = False + + bad_request_error_message = '' + bad_request_error_message += ( + ''.join("Bad response while searching for the music\n\n")) + bad_request_error_message += (''.join("**Possible causes include:**\n")) + bad_request_error_message += ( + ''.join("*1. bad network on the bot's end;\n")) + bad_request_error_message += ( + ''.join("2. the given search query couldn't find matching results;*\n")) + bad_request_error_message += (''.join( + "***3. too many queuing requests made, without letting the bot to respond to them;***\n")) + bad_request_error_message += (''.join( + "\n**To avoid any further unexpected errors, make the bot rejoin the voice channel using ` leave` and then ` join`**\n")) + bad_request_error_message += (''.join("**SORRY FOR THE INCONVENIENCE!**")) + + embed_error_no_vc_dex = discord.Embed( + title="Error", + description=''.join( + "Dex is not in any voice channel\n**Use ` join` to make it connect to one and then use music commands**"), + colour=0xff0000, + timestamp=datetime.datetime.utcnow() + ) + + MUSIC_ICON = "https://user-images.githubusercontent.com/63065397/156855077-ce6e0896-cc81-4d4d-98b8-3e7b70050afe.png" + + def __init__(self, bot): + self.bot = bot + self.is_playing = False + self.MUSIC_ICON = "https://user-images.githubusercontent.com/63065397/156855077-ce6e0896-cc81-4d4d-98b8-3e7b70050afe.png" + self.currently_playing_music = () + self.currently_playing_player = None + self.music_queue = [] + + @commands.command(name="join", aliases=["connect"], help="joins the voice channel of the author") + async def join_command(self, ctx): + if ctx.voice_client is None: + if ctx.author.voice is not None: + await ctx.author.voice.channel.connect() + return + else: + embed = discord.Embed( + title="Error", + description=ctx.author.mention + ", you are not connected to a voice channel", + colour=0xFF0000, + timestamp=datetime.datetime.utcnow() + ) + embed.set_footer(text="join request from " + ctx.author.name) + await ctx.send(embed=embed) + return + else: + if ctx.voice_client.is_playing() or ctx.voice_client.is_paused(): + pass + else: + if ctx.author.voice is not None: + await ctx.voice_client.move_to(ctx.author.voice.channel) + return + else: + embed = discord.Embed( + title="Error", + description=ctx.author.mention + ", you are not connected to a voice channel", + colour=0xFF0000, + timestamp=datetime.datetime.utcnow() + ) + embed.set_footer( + text="join request from " + ctx.author.name) + await ctx.send(embed=embed) + return + embed = discord.Embed( + title="Error", + description=''.join( + "Can't move b/w channels while playing music!\n**NOTE: **You can still add music to the queue!"), + colour=0xff0000, + timestamp=datetime.datetime.utcnow() + ) + embed.set_footer(text="join request from " + ctx.author.name) + await ctx.send(embed=embed) + + async def make_join(self, ctx): + if ctx.author.voice: + if ctx.voice_client is None: + await ctx.author.voice.channel.connect() + return True + else: + if (ctx.voice_client.is_playing() or ctx.voice_client.is_paused()) and (ctx.voice_client.channel != ctx.author.voice.channel): + async with ctx.typing(): + mssg_ = "Can't move b/w channels while playing music!\n**NOTE: **You can still add music to the queue!" + embed = discord.Embed( + title="Error", + description=mssg_, + colour=0xff0000, + timestamp=datetime.datetime.utcnow() + ) + embed.set_footer( + text="play request from " + ctx.author.name) + await ctx.send(embed=embed) + return True + else: + await ctx.voice_client.move_to(ctx.author.voice.channel) + return True + else: + async with ctx.typing(): + embed = discord.Embed( + title="Error", + description=ctx.author.mention + ", you are not connected to a voice channel", + colour=0xFF0000, + timestamp=datetime.datetime.utcnow() + ) + embed.set_footer(text="play request from " + ctx.author.name) + await ctx.send(embed=embed) + return False + + async def play_music_from_player(self, ctx, *, player): + if player is None: + return + self.currently_playing_player = player + embed = discord.Embed( + title="Now Playing", + description="- requested by " + + self.music_queue[0][1].author.mention, + colour=0x00ff00, + timestamp=datetime.datetime.utcnow() + ) + embed.set_thumbnail(url=self.MUSIC_ICON) + embed.set_author(name=player.title, url=player.url, + icon_url=ctx.author.avatar_url) + embed.add_field(name="Title", value=player.title, inline=False) + embed.add_field(name="Remaining in queue", + value=len(self.music_queue)-1, inline=False) + ctx.voice_client.play(player, after=lambda e: print( + f'Player error: {e}') if e else None) + await ctx.send(embed=embed) + + async def keep_playing(self, ctx): + while len(self.music_queue) > 0: + if (not ctx.voice_client.is_playing()) and (not ctx.voice_client.is_paused()): + self.is_playing = True + await self.play_music_from_player(self.music_queue[0][1], player=self.music_queue[0][0]) + self.music_queue.pop(0) + await asyncio.sleep(0.5) + + @commands.command(name="play", aliases=["stream", "p", "add"], help="streams a song directly from youtube") + async def play_command(self, ctx, *, url: typing.Optional[str]): + if (url is None) and (ctx.message.content[(len(ctx.message.content)-3):(len(ctx.message.content))] != "add"): + if ctx.voice_client is None: + await self.make_join(ctx) + if ctx.voice_client is None: + return + if ctx.voice_client.is_playing(): + return + if ctx.voice_client.is_paused(): + ctx.voice_client.resume() + elif len(self.music_queue) > 0: + if not ctx.voice_client.is_playing(): + await self.keep_playing(ctx) + else: + embed = discord.Embed( + title="Error", + description=''.join( + "Queue is empty, nothing to play\nUse ` play ` to add to queue"), + colour=0xff0000, + timestamp=datetime.datetime.utcnow() + ) + await ctx.send(embed=embed) + return + elif url is None: + async with ctx.typing(): + embed = discord.Embed( + title="Status", + colour=0xff0000, + timestamp=datetime.datetime.utcnow() + ) + n = "Error" + v = "Missing required arguements" + embed.add_field(name=n, value=v, inline=False) + await ctx.send(embed=embed) + + joined = await self.make_join(ctx) + if joined == False: + return + player = await YTDLSource.from_url(url, loop=self.bot.loop, stream=True) + if player is None: + async with ctx.typing(): + embed = discord.Embed( + title="Error", + description=''.join(self.bad_request_error_message), + colour=0xff0000, + timestamp=datetime.datetime.utcnow(), + ) + await ctx.send(embed=embed) + return + self.music_queue.append([player, ctx]) + async with ctx.typing(): + embed = discord.Embed( + title="Added to queue", + description="\"" + url + "\" requested by " + ctx.author.mention, + colour=0x00ff00, + timestamp=datetime.datetime.utcnow(), + ) + embed.set_thumbnail(url=self.MUSIC_ICON) + embed.set_author(name=player.title, url=player.url, + icon_url=ctx.author.avatar_url) + embed.add_field(name="Title", value=player.title, inline=False) + embed.add_field(name="Queue Position", value=len( + self.music_queue), inline=True) + await ctx.send(embed=embed) + await self.keep_playing(ctx) + + @commands.command(name='dplay', help="downloads a song and then plays it to reduce any possible lags") + async def dplay_command(self, ctx, *, url): + await self.make_join(ctx) + if ctx.voice_client is None: + return + player = await YTDLSource.from_url(url, loop=self.bot.loop) + if player is None: + async with ctx.typing(): + embed = discord.Embed( + title="Error", + description=''.join(self.bad_request_error_message), + colour=0xff0000, + timestamp=datetime.datetime.utcnow() + ) + await ctx.send(embed=embed) + return + self.music_queue.append([player, ctx]) + async with ctx.typing(): + embed = discord.Embed( + title="Downloaded & Added to queue", + description="\"" + url + "\" requested by " + ctx.author.mention, + colour=0x00ff00, + timestamp=datetime.datetime.utcnow(), + ) + embed.set_thumbnail(url=self.MUSIC_ICON) + embed.set_author(name=player.title, url=player.url, + icon_url=ctx.author.avatar_url) + embed.add_field(name="Title", value=player.title, inline=False) + embed.add_field(name="Queue Position", value=len( + self.music_queue), inline=True) + await ctx.send(embed=embed) + await self.keep_playing(ctx) + + # @commands.command(name="repeat", help="loops the currently playing song") + # async def loop(self, ctx): + # if ctx.voice_client is None: + # async with ctx.typing(): + # embed=self.embed_error_no_vc_dex + # await ctx.send(embed=embed) + # return + # if (not ctx.voice_client.is_playing()) and (not ctx.voice_client.is_paused()): + # async with ctx.typing(): + # embed=discord.Embed( + # title="Error", + # description=''.join("Queue is empty, nothing to loop through\nUse ` play ` to add to queue"), + # colour=0xff0000, + # timestamp=datetime.datetime.utcnow() + # ) + # await ctx.send(embed=embed) + # return + # while True: + + @commands.command(name="queue", aliases=["view"], help="displays the current queue") + async def queue_command(self, ctx, *args): + if (ctx.message.content[(len(ctx.message.content)-5):(len(ctx.message.content))] == "queue"): + url = "".join(args) + if url != "": + await self.play_command(ctx, url) + return + if ctx.voice_client is None: + async with ctx.typing(): + embed = self.embed_error_no_vc_dex + await ctx.send(embed=embed) + return + if len(self.music_queue) == 0: + async with ctx.typing(): + embed = discord.Embed( + title="Queue", + description=''.join( + "Queue is empty, nothing to play\nUse ` play ` to add to queue"), + colour=0xff0000, + timestamp=datetime.datetime.utcnow() + ) + await ctx.send(embed=embed) + return + embed = discord.Embed( + title="Queue", + colour=0x0000ff, + timestamp=datetime.datetime.utcnow() + ) + embed.set_thumbnail(url=self.MUSIC_ICON) + embed.set_author(name="Dex", icon_url=self.bot.user.avatar_url) + size = len(self.music_queue) + for i in range(0, size, 25): + if i + 25 > size: + for j in range(i, size): + embed.add_field( + name=str(j + 1), value=self.music_queue[j][0].title, inline=False) + else: + for j in range(i, i + 25): + embed.add_field( + name=str(j + 1), value=self.music_queue[j][0].title, inline=False) + async with ctx.typing(): + embed.set_footer( + text="Page " + str(int(i / 25) + 1) + " of " + str(int(size / 25) + 1)) + await ctx.send(embed=embed) + + @commands.command(name="remove", help="removes a song from the queue, takes song position as argument") + async def remove_command(self, ctx, pos): + pos = int(pos) + if ctx.voice_client is None: + async with ctx.typing(): + embed = self.embed_error_no_vc_dex + await ctx.send(embed=embed) + return + if len(self.music_queue) < int(pos): + async with ctx.typing(): + embed = discord.Embed( + title="Error", + description=''.join("There are only " + str(len(self.music_queue)) + + " songs in the queue\nNo song at position "+str(pos)+"\n**Use ` queue` to view the queue**"), + colour=0xff0000, + timestamp=datetime.datetime.utcnow() + ) + await ctx.send(embed=embed) + return + async with ctx.typing(): + embed = discord.Embed( + title="Removed from queue", + description="track requested by " + + self.music_queue[int(pos)-1][1].author.mention, + colour=0x00ff00, + timestamp=datetime.datetime.utcnow() + ) + player = self.music_queue[int(pos)-1][0] + embed.set_thumbnail(url=self.MUSIC_ICON) + embed.set_author(name=player.title, url=player.url, + icon_url=ctx.author.avatar_url) + embed.add_field(name="Title", value=player.title, inline=False) + embed.add_field(name="Remove request by", + value=ctx.author.mention, inline=True) + self.music_queue.pop(int(pos)-1) + await ctx.send(embed=embed) + + @commands.command(name="jump", help="jumps to a song in the queue, takes song position as argument") + async def jump_command(self, ctx, pos): + pos = int(pos) + if ctx.voice_client is None: + async with ctx.typing(): + embed = self.embed_error_no_vc_dex + await ctx.send(embed=embed) + return + if len(self.music_queue) < int(pos): + async with ctx.typing(): + embed = discord.Embed( + title="Error", + description=''.join("There are only " + str(len(self.music_queue)) + + " songs in the queue\nNo song at position "+str(pos)+"\n**Use ` queue` to view the queue**"), + colour=0xff0000, + timestamp=datetime.datetime.utcnow() + ) + await ctx.send(embed=embed) + return + async with ctx.typing(): + embed = discord.Embed( + title="Jumping to " + str(pos), + description="- requested by " + ctx.author.mention, + colour=0x00ff00, + timestamp=datetime.datetime.utcnow() + ) + player = self.music_queue[int(pos)-1][0] + embed.set_thumbnail(url=self.MUSIC_ICON) + embed.set_author(name=player.title, url=player.url, + icon_url=ctx.author.avatar_url) + embed.add_field(name="Title", value=player.title, inline=False) + embed.add_field(name="Remaining in queue", value=str( + len(self.music_queue)-pos), inline=True) + await ctx.send(embed=embed) + counter = 0 + while counter < int(pos) - 1: + self.music_queue.pop(0) + counter += 1 + await self.skip_command(ctx) + + @commands.command(name="volume", aliases=["vol"], help="changes the volume of the music player") + async def volume_command(self, ctx, volume: int): + if ctx.voice_client is None: + async with ctx.typing(): + embed = self.embed_error_no_vc_dex + await ctx.send(embed=embed) + return + ctx.voice_client.source.volume = volume / 100 + async with ctx.typing(): + embed = discord.Embed( + title=str(volume) + "%", + colour=0x00ff00, + timestamp=datetime.datetime.utcnow() + ) + embed.set_author(name="Volume set to", + icon_url=ctx.author.avatar_url) + await ctx.send(embed=embed) + + @commands.command(name="stop", aliases=["stfu", "shut"], help="stops the music player and clears the queue") + async def stop_command(self, ctx): + if ctx.voice_client is None: + async with ctx.typing(): + embed = self.embed_error_no_vc_dex + await ctx.send(embed=embed) + return + if ctx.voice_client.is_playing() or ctx.voice_client.is_paused(): + self.music_queue.clear() + ctx.voice_client.stop() + return + + @commands.command(name="pause", help="pauses the music player") + async def pause_command(self, ctx): + if ctx.voice_client is None: + embed = self.embed_error_no_vc_dex + await ctx.send(embed=embed) + elif ctx.voice_client.is_playing(): + ctx.voice_client.pause() + + @commands.command(name="resume", help="resumes the music player") + async def resume_command(self, ctx): + if ctx.voice_client is None: + embed = self.embed_error_no_vc_dex + await ctx.send(embed=embed) + elif ctx.voice_client.is_paused(): + ctx.voice_client.resume() + elif len(self.music_queue) > 0: + if not ctx.voice_client.is_playing(): + await self.keep_playing(ctx) + + @commands.command(name="leave", aliases=["disconnect, dc"], help="leaves if connected to any voice channel") + async def leave_command(self, ctx): + self.music_queue.clear() + self.currently_playing_music = None + self.currently_playing_player = None + if ctx.voice_client is None: + embed = self.embed_error_no_vc_dex + await ctx.send(embed=embed) + else: + await ctx.voice_client.disconnect() + + @commands.command(name="skip", aliases=["next"], help="skips the currently playing song") + async def skip_command(self, ctx): + if ctx.voice_client is None: + async with ctx.typing(): + embed = self.embed_error_no_vc_dex + await ctx.send(embed=embed) + else: + if ctx.voice_client.is_playing() or ctx.voice_client.is_paused(): + async with ctx.typing(): + embed = discord.Embed( + title="Skipping", + colour=0x00ff00, + timestamp=datetime.datetime.utcnow() + ) + player = self.currently_playing_player + embed.set_thumbnail(url=self.MUSIC_ICON) + embed.set_author( + name=player.title, url=player.url, icon_url=ctx.author.avatar_url) + embed.add_field( + name="Title", value=player.title, inline=False) + embed.add_field(name="Requested by", + value=ctx.author.mention, inline=False) + embed.set_footer(text="skip requested by "+ctx.author.name) + await ctx.send(embed=embed) + ctx.voice_client.stop() + + async def get_lyrics(self, song_title): + API_URL = "https://some-random-api.ml/lyrics?title=" + song_title + async with aiohttp.ClientSession() as session: + async with session.get(API_URL) as response: + data_json = await response.json() + return data_json + + @commands.command(name='lyrics', help='sends the lyrics of the song') + async def lyrics_command(self, ctx, *args) -> None: + song_title = '' + for arg in args: + song_title += arg+'%20' + if len(song_title) > 0: + song_title = song_title[:-3] + else: + if self.currently_playing_player is None: + async with ctx.typing(): + embed = discord.Embed( + title="Error", + description="No song is currently playing", + color=0xff0000, + timestamp=datetime.datetime.utcnow(), + ) + await ctx.send(embed=embed) + return + args = self.currently_playing_player.title.split() + for arg in args: + song_title += arg+'%20' + song_title = song_title[:-3] + + data = await self.get_lyrics(song_title) + if not 'lyrics' in data.keys(): + err_mssg = data['error'] + embed = discord.Embed( + title="Error", + description=err_mssg + + ('\n'+'[see results from GoogleSearch](https://www.google.com/search?q='+song_title+'+lyrics)'), + colour=0xff0000, + timestamp=datetime.datetime.utcnow(), + ) + await ctx.send(embed=embed) + else: + async with ctx.typing(): + lyrics = data['lyrics'] + extend_text = '\n[see results from GoogleSearch](https://www.google.com/search?q=' + \ + song_title+'+lyrics)' + if len(lyrics) > 3500: + lyrics = lyrics[:3500]+'... ' + extend_text = '[read more](https://www.google.com/search?q=' + \ + song_title+'+lyrics)' + + embed = discord.Embed( + title=data['title'], + description=lyrics+extend_text, + color=0x00ff00, + timestamp=datetime.datetime.utcnow(), + ) + embed.set_author( + name=data['author'], + ) + embed.set_thumbnail(url=data['thumbnail']['genius']) + embed.set_footer( + icon_url=ctx.author.avatar_url, + ) + await ctx.send(embed=embed) + + +# def setup(bot): +# bot.add_cog(Music(bot)) diff --git a/src/bot.py b/src/bot.py index 186cb6a3..5d0aec1a 100644 --- a/src/bot.py +++ b/src/bot.py @@ -88,11 +88,13 @@ async def on_message(self, message) -> None: str(message.guild.id) + '\';') tag_switch = cur.fetchone() cur.close() - if tag_switch[0] == 'off': - return target = message.author if target == self.user: return + print("\n\n-----------------------\n-----------------------\n\n" + + str(message.content) + "\n-----------------------\n") + if tag_switch[0] == 'off': + return embed = discord.Embed( title='Message Tagged', colour=target.colour, diff --git a/src/cogs/music.py b/src/cogs/music.py index 91158975..86b7abce 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -1,3 +1,4 @@ +from turtle import title import discord import aiohttp import json @@ -49,13 +50,16 @@ async def from_url(cls, url, *, loop=None, stream=False): if data is not None: if 'entries' in data: - # take first item from a playlist data = data['entries'][0] else: return None filename = data['url'] if stream else ytdl.prepare_filename(data) return cls(discord.FFmpegPCMAudio(filename, **FFMPEG_OPTIONS), data=data) + # ---------------------------------------------------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------------------------------------------------- +# ---------------------------------------------------------------------------------------------------------------------- class Music(commands.Cog): @@ -64,6 +68,10 @@ class Music(commands.Cog): # query/url(str) | download(bool) | ctx(ctx) music_queue = [] popped = 0 + current = -1 + queued = 0 + loop_queue = True + repeat_song = False currently_playing_music = () currently_playing_player = None is_playing = False @@ -91,6 +99,7 @@ class Music(commands.Cog): ) MUSIC_ICON = "https://user-images.githubusercontent.com/63065397/156855077-ce6e0896-cc81-4d4d-98b8-3e7b70050afe.png" + # ---------------------------------------------------------------------------------------------------------------------- def __init__(self, bot): self.bot = bot @@ -99,14 +108,12 @@ def __init__(self, bot): self.currently_playing_music = () self.currently_playing_player = None self.music_queue = [] + # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="join", aliases=["connect"], help="joins the voice channel of the author") async def join_command(self, ctx): - if ctx.voice_client is None: - if ctx.author.voice is not None: - await ctx.author.voice.channel.connect() - return - else: + if ctx.author.voice is None: + async with ctx.typing(): embed = discord.Embed( title="Error", description=ctx.author.mention + ", you are not connected to a voice channel", @@ -114,69 +121,46 @@ async def join_command(self, ctx): timestamp=datetime.datetime.utcnow() ) embed.set_footer(text="join request from " + ctx.author.name) - await ctx.send(embed=embed) - return + await ctx.send(embed=embed) + return False + + if ctx.voice_client is None: + await ctx.author.voice.channel.connect() + return True else: - if ctx.voice_client.is_playing() or ctx.voice_client.is_paused(): - pass - else: - if ctx.author.voice is not None: - await ctx.voice_client.move_to(ctx.author.voice.channel) - return - else: + if (ctx.voice_client.is_playing() or ctx.voice_client.is_paused()) and (ctx.voice_client.channel != ctx.author.voice.channel): + async with ctx.typing(): embed = discord.Embed( title="Error", - description=ctx.author.mention + ", you are not connected to a voice channel", - colour=0xFF0000, + description=''.join( + "Can't move b/w channels while playing music!\n**NOTE: **You can still add music to the queue!"), + colour=0xff0000, timestamp=datetime.datetime.utcnow() ) embed.set_footer( text="join request from " + ctx.author.name) - await ctx.send(embed=embed) - return - embed = discord.Embed( - title="Error", - description=''.join( - "Can't move b/w channels while playing music!\n**NOTE: **You can still add music to the queue!"), - colour=0xff0000, - timestamp=datetime.datetime.utcnow() - ) - embed.set_footer(text="join request from " + ctx.author.name) - await ctx.send(embed=embed) - - async def make_join(self, ctx): - if ctx.author.voice: - if ctx.voice_client is None: - await ctx.author.voice.channel.connect() + await ctx.send(embed=embed) return True else: - if (ctx.voice_client.is_playing() or ctx.voice_client.is_paused()) and (ctx.voice_client.channel != ctx.author.voice.channel): - async with ctx.typing(): - mssg_ = "Can't move b/w channels while playing music!\n**NOTE: **You can still add music to the queue!" - embed = discord.Embed( - title="Error", - description=mssg_, - colour=0xff0000, - timestamp=datetime.datetime.utcnow() - ) - embed.set_footer( - text="play request from " + ctx.author.name) - await ctx.send(embed=embed) - return True - else: - await ctx.voice_client.move_to(ctx.author.voice.channel) - return True - else: - async with ctx.typing(): - embed = discord.Embed( - title="Error", - description=ctx.author.mention + ", you are not connected to a voice channel", - colour=0xFF0000, - timestamp=datetime.datetime.utcnow() - ) - embed.set_footer(text="play request from " + ctx.author.name) + await ctx.voice_client.move_to(ctx.author.voice.channel) + return True + + # ---------------------------------------------------------------------------------------------------------------------- + + @commands.command(name="leave", aliases=["disconnect, dc"], help="leaves if connected to any voice channel") + async def leave_command(self, ctx): + self.music_queue.clear() + self.currently_playing_music = None + self.current = -1 + self.popped = 0 + self.queued = 0 + self.currently_playing_player = None + if ctx.voice_client is None: + embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) - return False + else: + await ctx.voice_client.disconnect() + # ---------------------------------------------------------------------------------------------------------------------- async def play_music_from_player(self, ctx, *, player): if player is None: @@ -185,7 +169,7 @@ async def play_music_from_player(self, ctx, *, player): embed = discord.Embed( title="Now Playing", description="- requested by " + - self.music_queue[0][1].author.mention, + self.music_queue[self.current][1].author.mention, colour=0x00ff00, timestamp=datetime.datetime.utcnow() ) @@ -193,25 +177,37 @@ async def play_music_from_player(self, ctx, *, player): embed.set_author(name=player.title, url=player.url, icon_url=ctx.author.avatar_url) embed.add_field(name="Title", value=player.title, inline=False) - embed.add_field(name="Remaining in queue", - value=len(self.music_queue)-1, inline=False) + embed.add_field(name="Position in queue", + value=self.current+1, inline=False) ctx.voice_client.play(player, after=lambda e: print( f'Player error: {e}') if e else None) await ctx.send(embed=embed) + # ---------------------------------------------------------------------------------------------------------------------- async def keep_playing(self, ctx): - while len(self.music_queue) > 0: - if (not ctx.voice_client.is_playing()) and (not ctx.voice_client.is_paused()): + while ((len(self.music_queue) - self.popped > 0) or (self.loop_queue is True)) and (len(self.music_queue) > 0): + if ((not ctx.voice_client.is_playing()) and (not ctx.voice_client.is_paused())): self.is_playing = True - await self.play_music_from_player(self.music_queue[0][1], player=self.music_queue[0][0]) - self.music_queue.pop(0) + if (not self.repeat_song) or (self.current == -1): + self.current += 1 + if self.popped == len(self.music_queue): + self.popped = 0 + if self.current == len(self.music_queue): + self.current = 0 + player = await YTDLSource.from_url(self.music_queue[self.current][2], loop=self.bot.loop, stream=self.music_queue[self.current][3]) + self.music_queue[self.current][0] = player + await self.play_music_from_player(self.music_queue[self.current][1], player=player) + if not self.repeat_song: + self.popped += 1 await asyncio.sleep(0.5) + return + # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="play", aliases=["stream", "p", "add"], help="streams a song directly from youtube") async def play_command(self, ctx, *, url: typing.Optional[str]): if (url is None) and (ctx.message.content[(len(ctx.message.content)-3):(len(ctx.message.content))] != "add"): if ctx.voice_client is None: - await self.make_join(ctx) + await self.join_command(ctx) if ctx.voice_client is None: return if ctx.voice_client.is_playing(): @@ -220,7 +216,7 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): ctx.voice_client.resume() elif len(self.music_queue) > 0: if not ctx.voice_client.is_playing(): - await self.keep_playing(ctx) + self.keep_playing(ctx) else: embed = discord.Embed( title="Error", @@ -243,7 +239,7 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): embed.add_field(name=n, value=v, inline=False) await ctx.send(embed=embed) - joined = await self.make_join(ctx) + joined = await self.join_command(ctx) if joined == False: return player = await YTDLSource.from_url(url, loop=self.bot.loop, stream=True) @@ -257,7 +253,8 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): ) await ctx.send(embed=embed) return - self.music_queue.append([player, ctx]) + self.music_queue.append([player, ctx, url, True]) + self.queued += 1 async with ctx.typing(): embed = discord.Embed( title="Added to queue", @@ -272,11 +269,23 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): embed.add_field(name="Queue Position", value=len( self.music_queue), inline=True) await ctx.send(embed=embed) - await self.keep_playing(ctx) + self.keep_playing(ctx) + return + # ---------------------------------------------------------------------------------------------------------------------- + + @commands.command(name="playm", aliases=["streamm", "pm", "addm"], help="plays multiple songs (seperated by semicolons ';')") + async def playm_command(self, ctx, *, args): + urls = args.split(';') + for url in urls: + print("\n*****calling play_command with url: " + url) + await self.play_command(ctx, url=url) + print("\n*****returning from playm_command") + return + # ---------------------------------------------------------------------------------------------------------------------- - @commands.command(name='dplay', help="downloads a song and then plays it to reduce any possible lags") + @commands.command(name='dplay', help="downloads a song and then queues it to reduce any possible lags") async def dplay_command(self, ctx, *, url): - await self.make_join(ctx) + await self.join_command(ctx) if ctx.voice_client is None: return player = await YTDLSource.from_url(url, loop=self.bot.loop) @@ -290,7 +299,8 @@ async def dplay_command(self, ctx, *, url): ) await ctx.send(embed=embed) return - self.music_queue.append([player, ctx]) + self.music_queue.append([player, ctx, url, False]) + self.queued += 1 async with ctx.typing(): embed = discord.Embed( title="Downloaded & Added to queue", @@ -305,7 +315,18 @@ async def dplay_command(self, ctx, *, url): embed.add_field(name="Queue Position", value=len( self.music_queue), inline=True) await ctx.send(embed=embed) - await self.keep_playing(ctx) + self.keep_playing(ctx) + # ---------------------------------------------------------------------------------------------------------------------- + + @commands.command(name='dplaym', help="dplays multiple songs (seperated by semicolons ';')") + async def dplaym_command(self, ctx, *, args): + urls = args.split(';') + for url in urls: + print("\n*****calling dplay_command with url: " + url) + await self.dplay_command(ctx, url=url) + print("\n*****returning from dplaym_command") + return + # ---------------------------------------------------------------------------------------------------------------------- # @commands.command(name="repeat", help="loops the currently playing song") # async def loop(self, ctx): @@ -325,13 +346,13 @@ async def dplay_command(self, ctx, *, url): # await ctx.send(embed=embed) # return # while True: + # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="queue", aliases=["view"], help="displays the current queue") - async def queue_command(self, ctx, *args): - if (ctx.message.content[(len(ctx.message.content)-5):(len(ctx.message.content))] == "queue"): - url = "".join(args) + async def queue_command(self, ctx, *, url: typing.Optional[str]): + if url is not None: if url != "": - await self.play_command(ctx, url) + await self.play_command(ctx, url=url) return if ctx.voice_client is None: async with ctx.typing(): @@ -358,55 +379,70 @@ async def queue_command(self, ctx, *args): embed.set_author(name="Dex", icon_url=self.bot.user.avatar_url) size = len(self.music_queue) for i in range(0, size, 25): - if i + 25 > size: - for j in range(i, size): - embed.add_field( - name=str(j + 1), value=self.music_queue[j][0].title, inline=False) - else: - for j in range(i, i + 25): - embed.add_field( - name=str(j + 1), value=self.music_queue[j][0].title, inline=False) + for j in range(i, min(size, i + 25)): + k = "**" if j == self.current else "" + embed.add_field( + name=str(j + 1) + (" ***(Currently Playing)***" if j == self.current else ""), value=k+str(self.music_queue[j][0].title)+k, inline=False) async with ctx.typing(): embed.set_footer( text="Page " + str(int(i / 25) + 1) + " of " + str(int(size / 25) + 1)) await ctx.send(embed=embed) + # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="remove", help="removes a song from the queue, takes song position as argument") async def remove_command(self, ctx, pos): - pos = int(pos) if ctx.voice_client is None: async with ctx.typing(): embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) return - if len(self.music_queue) < int(pos): + if (pos is None): async with ctx.typing(): embed = discord.Embed( title="Error", - description=''.join("There are only " + str(len(self.music_queue)) + - " songs in the queue\nNo song at position "+str(pos)+"\n**Use ` queue` to view the queue**"), + description=''.join( + "Missing required argument: ``"), colour=0xff0000, timestamp=datetime.datetime.utcnow() ) await ctx.send(embed=embed) return + if (1 > int(pos)) or (len(self.music_queue) < int(pos)): + async with ctx.typing(): + embed = discord.Embed( + title="Error", + description=str( + "Queue Position must be between (1 & "+str(len(self.music_queue))+")"), + colour=0xff0000, + timestamp=datetime.datetime.utcnow() + ) + await ctx.send(embed=embed) + return + pos = int(pos) - 1 async with ctx.typing(): embed = discord.Embed( title="Removed from queue", description="track requested by " + - self.music_queue[int(pos)-1][1].author.mention, + self.music_queue[int(pos)][1].author.mention, colour=0x00ff00, timestamp=datetime.datetime.utcnow() ) - player = self.music_queue[int(pos)-1][0] + player = self.music_queue[int(pos)][0] embed.set_thumbnail(url=self.MUSIC_ICON) embed.set_author(name=player.title, url=player.url, icon_url=ctx.author.avatar_url) embed.add_field(name="Title", value=player.title, inline=False) embed.add_field(name="Remove request by", value=ctx.author.mention, inline=True) - self.music_queue.pop(int(pos)-1) + self.music_queue.pop(int(pos)) + if self.current > pos: + self.current -= 1 + self.popped -= 1 + elif self.current == pos: + self.current -= 1 + ctx.voice_client.stop() await ctx.send(embed=embed) + # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="jump", help="jumps to a song in the queue, takes song position as argument") async def jump_command(self, ctx, pos): @@ -416,37 +452,48 @@ async def jump_command(self, ctx, pos): embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) return - if len(self.music_queue) < int(pos): + if (pos is None): + async with ctx.typing(): + embed = discord.Embed( + title="Error", + description=''.join( + "Missing required argument: ``"), + colour=0xff0000, + timestamp=datetime.datetime.utcnow() + ) + await ctx.send(embed=embed) + return + if (1 > int(pos)) or (len(self.music_queue) < int(pos)): async with ctx.typing(): embed = discord.Embed( title="Error", - description=''.join("There are only " + str(len(self.music_queue)) + - " songs in the queue\nNo song at position "+str(pos)+"\n**Use ` queue` to view the queue**"), + description=str( + "Queue Position must be between (1 & "+str(len(self.music_queue))+")"), colour=0xff0000, timestamp=datetime.datetime.utcnow() ) await ctx.send(embed=embed) return + pos = int(pos) - 1 async with ctx.typing(): embed = discord.Embed( - title="Jumping to " + str(pos), + title="Jumping to " + str(pos + 1), description="- requested by " + ctx.author.mention, colour=0x00ff00, timestamp=datetime.datetime.utcnow() ) - player = self.music_queue[int(pos)-1][0] + player = self.music_queue[int(pos)][0] embed.set_thumbnail(url=self.MUSIC_ICON) embed.set_author(name=player.title, url=player.url, icon_url=ctx.author.avatar_url) embed.add_field(name="Title", value=player.title, inline=False) - embed.add_field(name="Remaining in queue", value=str( - len(self.music_queue)-pos), inline=True) + embed.add_field( + name="Queue Looping", value="On" if self.loop_queue else "Off", inline=True) await ctx.send(embed=embed) - counter = 0 - while counter < int(pos) - 1: - self.music_queue.pop(0) - counter += 1 - await self.skip_command(ctx) + self.popped = pos + self.current = pos - 1 + ctx.voice_client.stop() + # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="volume", aliases=["vol"], help="changes the volume of the music player") async def volume_command(self, ctx, volume: int): @@ -465,9 +512,15 @@ async def volume_command(self, ctx, volume: int): embed.set_author(name="Volume set to", icon_url=ctx.author.avatar_url) await ctx.send(embed=embed) + # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="stop", aliases=["stfu", "shut"], help="stops the music player and clears the queue") async def stop_command(self, ctx): + self.current = -1 + self.popped = 0 + self.queued = 0 + self.currently_playing_music = None + self.currently_playing_player = None if ctx.voice_client is None: async with ctx.typing(): embed = self.embed_error_no_vc_dex @@ -477,6 +530,7 @@ async def stop_command(self, ctx): self.music_queue.clear() ctx.voice_client.stop() return + # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="pause", help="pauses the music player") async def pause_command(self, ctx): @@ -485,6 +539,8 @@ async def pause_command(self, ctx): await ctx.send(embed=embed) elif ctx.voice_client.is_playing(): ctx.voice_client.pause() + return + # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="resume", help="resumes the music player") async def resume_command(self, ctx): @@ -496,17 +552,8 @@ async def resume_command(self, ctx): elif len(self.music_queue) > 0: if not ctx.voice_client.is_playing(): await self.keep_playing(ctx) - - @commands.command(name="leave", aliases=["disconnect, dc"], help="leaves if connected to any voice channel") - async def leave_command(self, ctx): - self.music_queue.clear() - self.currently_playing_music = None - self.currently_playing_player = None - if ctx.voice_client is None: - embed = self.embed_error_no_vc_dex - await ctx.send(embed=embed) - else: - await ctx.voice_client.disconnect() + return + # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="skip", aliases=["next"], help="skips the currently playing song") async def skip_command(self, ctx): @@ -532,7 +579,10 @@ async def skip_command(self, ctx): value=ctx.author.mention, inline=False) embed.set_footer(text="skip requested by "+ctx.author.name) await ctx.send(embed=embed) + self.popped += 1 ctx.voice_client.stop() + return + # ---------------------------------------------------------------------------------------------------------------------- async def get_lyrics(self, song_title): API_URL = "https://some-random-api.ml/lyrics?title=" + song_title @@ -540,6 +590,7 @@ async def get_lyrics(self, song_title): async with session.get(API_URL) as response: data_json = await response.json() return data_json + # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name='lyrics', help='sends the lyrics of the song') async def lyrics_command(self, ctx, *args) -> None: @@ -599,6 +650,7 @@ async def lyrics_command(self, ctx, *args) -> None: icon_url=ctx.author.avatar_url, ) await ctx.send(embed=embed) + # ---------------------------------------------------------------------------------------------------------------------- def setup(bot): From d8ccd01b1a8e092044d16ab8050262332e36c856 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Thu, 23 Jun 2022 21:16:07 +0530 Subject: [PATCH 35/60] env_var changed --- src/bot.py | 18 +++++++++--------- src/cogs/fun.py | 2 +- src/cogs/modset.py | 2 +- src/cogs/music.py | 5 ++--- src/cogs/report.py | 6 +++--- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/bot.py b/src/bot.py index 5d0aec1a..511169a3 100644 --- a/src/bot.py +++ b/src/bot.py @@ -35,14 +35,14 @@ def __init__(self, *args, **kwargs): self.load_extension(f'src.cogs.{file[:-3]}') def connect_to_db(self) -> None: - - self.DB_CONNECTION = psycopg2.connect( - host=os.getenv('DEX_DB_HOST'), - database=os.getenv('DEX_DB_NAME'), - user=os.getenv('DEX_DB_USER'), - port=os.getenv('DEX_DB_PORT'), - password=os.getenv('DEX_DB_PASSWORD'), - ) + print(os.environ['DEX_USAGE_HISTORY_CHANNEL_ID']) + # self.DB_CONNECTION = psycopg2.connect( + # host=os.getenv('DEX_DB_HOST'), + # database=os.getenv('DEX_DB_NAME'), + # user=os.getenv('DEX_DB_USER'), + # port=os.getenv('DEX_DB_PORT'), + # password=os.getenv('DEX_DB_PASSWORD'), + # ) async def get_prefix(self, message): cur = self.DB_CONNECTION.cursor() @@ -52,7 +52,7 @@ async def get_prefix(self, message): return prefix def run(self) -> None: - super().run(os.getenv('BOT_TOKEN')) + super().run(os.getenv('DEX_BOT_TOKEN')) async def on_ready(self): print('Logged in as {0.user}'.format(self)) diff --git a/src/cogs/fun.py b/src/cogs/fun.py index 0c0463fe..7837de5b 100644 --- a/src/cogs/fun.py +++ b/src/cogs/fun.py @@ -32,7 +32,7 @@ async def send_iquote(self, ctx): async def get_nasa(self): API_URL = "https://api.nasa.gov/planetary/apod?api_key=" + \ - str(os.getenv('NASA_API_KEY')) + str(os.getenv('DEX_NASA_API_KEY')) async with aiohttp.ClientSession() as session: async with session.get(API_URL) as resp: data_json = await resp.json() diff --git a/src/cogs/modset.py b/src/cogs/modset.py index 873343f9..d193bc72 100644 --- a/src/cogs/modset.py +++ b/src/cogs/modset.py @@ -57,7 +57,7 @@ async def message_tags(self, ctx, switch: Optional[str]): @command(name="changepref", aliases=["changeprefix"], help="changes the prefix to the appended string") async def change_prefix(self, ctx, *args): prefix = "".join(args) - if ctx.guild.id == int(os.environ['PUBLIC_BOT_SERVER']): + if ctx.guild.id == int(os.environ['DEX_PUBLIC_BOT_SERVER']): embed = Embed(title="Status", colour=0xff0000, timestamp=datetime.utcnow()) diff --git a/src/cogs/music.py b/src/cogs/music.py index 86b7abce..432e21de 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -144,7 +144,6 @@ async def join_command(self, ctx): else: await ctx.voice_client.move_to(ctx.author.voice.channel) return True - # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="leave", aliases=["disconnect, dc"], help="leaves if connected to any voice channel") @@ -272,7 +271,7 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): self.keep_playing(ctx) return # ---------------------------------------------------------------------------------------------------------------------- - + @commands.command(name="playm", aliases=["streamm", "pm", "addm"], help="plays multiple songs (seperated by semicolons ';')") async def playm_command(self, ctx, *, args): urls = args.split(';') @@ -317,7 +316,7 @@ async def dplay_command(self, ctx, *, url): await ctx.send(embed=embed) self.keep_playing(ctx) # ---------------------------------------------------------------------------------------------------------------------- - + @commands.command(name='dplaym', help="dplays multiple songs (seperated by semicolons ';')") async def dplaym_command(self, ctx, *, args): urls = args.split(';') diff --git a/src/cogs/report.py b/src/cogs/report.py index f018d4c9..d04bb057 100644 --- a/src/cogs/report.py +++ b/src/cogs/report.py @@ -20,7 +20,7 @@ async def on_ready(self): if m.bot: bot_count += 1 - channel = self.bot.get_channel(int(os.getenv('CONSOLE_CHANNEL_ID'))) + channel = self.bot.get_channel(int(os.getenv('DEX_CONSOLE_CHANNEL_ID'))) embed = discord.Embed(title='Status', colour=0x0023dd, timestamp=datetime.utcnow()) fields = [ @@ -68,7 +68,7 @@ async def on_ready(self): for n, v, i in fields: embed.add_field(name=n, value=v, inline=i) channel = self.bot.get_channel( - int(os.getenv('CONSOLE_CHANNEL_ID')) + int(os.getenv('DEX_CONSOLE_CHANNEL_ID')) ) await channel.send(embed=embed) @@ -84,7 +84,7 @@ async def on_message(self, message): embed.set_author(name=str(target), icon_url=target.avatar_url) embed.add_field(name='Message', value=message.content, inline=False) channel = self.bot.get_channel( - int(os.getenv('USAGE_HISTORY_CHANNEL_ID')) + int(os.getenv('DEX_USAGE_HISTORY_CHANNEL_ID')) ) await channel.send(embed=embed) From ba4ce455d278da8322026969b600ccb8dd229c9c Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Fri, 24 Jun 2022 00:20:15 +0530 Subject: [PATCH 36/60] working weird ffmpeg errors on local system; rest seems fine; --- src/bot.py | 15 ++-- src/cogs/modset.py | 65 +++++++++------ src/cogs/music.py | 200 ++++++++++++++++++++++++++++++++++++++------- src/cogs/report.py | 3 +- 4 files changed, 220 insertions(+), 63 deletions(-) diff --git a/src/bot.py b/src/bot.py index 511169a3..d779dc0f 100644 --- a/src/bot.py +++ b/src/bot.py @@ -35,14 +35,13 @@ def __init__(self, *args, **kwargs): self.load_extension(f'src.cogs.{file[:-3]}') def connect_to_db(self) -> None: - print(os.environ['DEX_USAGE_HISTORY_CHANNEL_ID']) - # self.DB_CONNECTION = psycopg2.connect( - # host=os.getenv('DEX_DB_HOST'), - # database=os.getenv('DEX_DB_NAME'), - # user=os.getenv('DEX_DB_USER'), - # port=os.getenv('DEX_DB_PORT'), - # password=os.getenv('DEX_DB_PASSWORD'), - # ) + self.DB_CONNECTION = psycopg2.connect( + host=os.getenv('DEX_DB_HOST'), + database=os.getenv('DEX_DB_NAME'), + user=os.getenv('DEX_DB_USER'), + port=os.getenv('DEX_DB_PORT'), + password=os.getenv('DEX_DB_PASSWORD'), + ) async def get_prefix(self, message): cur = self.DB_CONNECTION.cursor() diff --git a/src/cogs/modset.py b/src/cogs/modset.py index d193bc72..6c1bfb46 100644 --- a/src/cogs/modset.py +++ b/src/cogs/modset.py @@ -2,7 +2,6 @@ import psycopg2 from typing import Optional from datetime import datetime -from discord import Embed, Member from discord.ext.commands import Cog from discord.ext.commands import command import os @@ -14,7 +13,7 @@ def __init__(self, bot): self.bot = bot @command(name="modset", aliases=["mset", "modsettings"]) - async def modset(self, ctx, target: Optional[Member]): + async def modset(self, ctx, target: Optional[discord.Member]): pass @command(name="tags", aliases=["tagging", "msgtag"], help="toggles message tags") @@ -23,6 +22,7 @@ async def message_tags(self, ctx, switch: Optional[str]): cur.execute( 'SELECT tag_messages FROM guilds WHERE guild_id = \'' + str(ctx.guild.id) + '\';') tag_messages = cur.fetchone() + cur.close() tag_switch = tag_messages[0] if switch is None: if tag_switch == "off": @@ -35,10 +35,17 @@ async def message_tags(self, ctx, switch: Optional[str]): tag_switch = "on" else: - embed = Embed(title="Status", colour=0xff0000, - timestamp=datetime.utcnow()) - embed.add_field( - name="Error", value="Invalid value provided", inline=True) + async with ctx.typing(): + embed = discord.Embed( + title="Status", + colour=0xff0000, + timestamp=datetime.utcnow() + ) + embed.add_field( + name="Error", + value="Invalid value provided", + inline=True + ) await ctx.send(embed=embed) return @@ -47,28 +54,34 @@ async def message_tags(self, ctx, switch: Optional[str]): '\' WHERE guild_id = \'' + str(ctx.guild.id) + '\';') self.bot.DB_CONNECTION.commit() cur.close() - embed = Embed(title="Status", - colour=0x00ff00, - timestamp=datetime.utcnow()) - embed.add_field(name="Done", value="Message Tags are now " + - tag_switch, inline=True) + async with ctx.typing(): + embed = discord.Embed( + title="Status", + colour=0x00ff00, + timestamp=datetime.utcnow() + ) + embed.add_field( + name="Done", + value="Message Tags are now " + tag_switch, + inline=True + ) await ctx.send(embed=embed) @command(name="changepref", aliases=["changeprefix"], help="changes the prefix to the appended string") async def change_prefix(self, ctx, *args): prefix = "".join(args) if ctx.guild.id == int(os.environ['DEX_PUBLIC_BOT_SERVER']): - embed = Embed(title="Status", - colour=0xff0000, - timestamp=datetime.utcnow()) + embed = discord.Embed(title="Status", + colour=0xff0000, + timestamp=datetime.utcnow()) embed.add_field( name="Error", value="Prefix changes are not allowed on this server!", inline=True) await ctx.send(embed=embed) else: if ctx.author != ctx.guild.owner: - embed = Embed(title="Status", - colour=0xff0000, - timestamp=datetime.utcnow()) + embed = discord.Embed(title="Status", + colour=0xff0000, + timestamp=datetime.utcnow()) embed.add_field( name="Error", value="Only server owner can change the prefix!", inline=True) await ctx.send(embed=embed) @@ -80,16 +93,16 @@ async def change_prefix(self, ctx, *args): "\' WHERE guild_id = \'"+str(ctx.guild.id)+"\';") self.bot.DB_CONNECTION.commit() cur.close() - embed = Embed(title="Status", - colour=0x00ff00, - timestamp=datetime.utcnow()) + embed = discord.Embed(title="Status", + colour=0x00ff00, + timestamp=datetime.utcnow()) embed.add_field( name="Done", value="New Prefix is " + prefix, inline=True) await ctx.send(embed=embed) else: - embed = Embed(title="Status", - colour=0xff0000, - timestamp=datetime.utcnow()) + embed = discord.Embed(title="Status", + colour=0xff0000, + timestamp=datetime.utcnow()) embed.add_field( name="Error", value="prefix length must be between (1 - 27)", inline=True) await ctx.send(embed=embed) @@ -97,9 +110,9 @@ async def change_prefix(self, ctx, *args): @command(name="goodbye!", aliases=["leaveThisServer"], help="makes the bot to leave the server (only for server owner)") async def leave_this_server(self, ctx): if ctx.author != ctx.guild.owner: - embed = Embed(title="Status", - colour=0xff0000, - timestamp=datetime.utcnow()) + embed = discord.Embed(title="Status", + colour=0xff0000, + timestamp=datetime.utcnow()) embed.add_field( name="Error", value="Only server owner can use this command!", inline=True) await ctx.send(embed=embed) diff --git a/src/cogs/music.py b/src/cogs/music.py index 432e21de..c2814725 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -1,3 +1,4 @@ +from ast import alias from turtle import title import discord import aiohttp @@ -70,7 +71,7 @@ class Music(commands.Cog): popped = 0 current = -1 queued = 0 - loop_queue = True + loop_queue = False repeat_song = False currently_playing_music = () currently_playing_player = None @@ -153,6 +154,8 @@ async def leave_command(self, ctx): self.current = -1 self.popped = 0 self.queued = 0 + self.loop_queue = False + self.repeat_song = False self.currently_playing_player = None if ctx.voice_client is None: embed = self.embed_error_no_vc_dex @@ -237,6 +240,7 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): v = "Missing required arguements" embed.add_field(name=n, value=v, inline=False) await ctx.send(embed=embed) + return joined = await self.join_command(ctx) if joined == False: @@ -275,17 +279,45 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): @commands.command(name="playm", aliases=["streamm", "pm", "addm"], help="plays multiple songs (seperated by semicolons ';')") async def playm_command(self, ctx, *, args): urls = args.split(';') + joined = await self.join_command(ctx) + if joined == False: + return for url in urls: - print("\n*****calling play_command with url: " + url) - await self.play_command(ctx, url=url) - print("\n*****returning from playm_command") + player = await YTDLSource.from_url(url, loop=self.bot.loop, stream=True) + if player is None: + async with ctx.typing(): + embed = discord.Embed( + title="Error", + description=''.join(self.bad_request_error_message), + colour=0xff0000, + timestamp=datetime.datetime.utcnow(), + ) + await ctx.send(embed=embed) + continue + self.music_queue.append([player, ctx, url, True]) + self.queued += 1 + async with ctx.typing(): + embed = discord.Embed( + title="Added to queue", + description="\"" + url + "\" requested by " + ctx.author.mention, + colour=0x00ff00, + timestamp=datetime.datetime.utcnow(), + ) + embed.set_thumbnail(url=self.MUSIC_ICON) + embed.set_author(name=player.title, url=player.url, + icon_url=ctx.author.avatar_url) + embed.add_field(name="Title", value=player.title, inline=False) + embed.add_field(name="Queue Position", value=len( + self.music_queue), inline=True) + await ctx.send(embed=embed) + self.keep_playing(ctx) return # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name='dplay', help="downloads a song and then queues it to reduce any possible lags") async def dplay_command(self, ctx, *, url): - await self.join_command(ctx) - if ctx.voice_client is None: + joined = await self.join_command(ctx) + if joined == False: return player = await YTDLSource.from_url(url, loop=self.bot.loop) if player is None: @@ -315,36 +347,141 @@ async def dplay_command(self, ctx, *, url): self.music_queue), inline=True) await ctx.send(embed=embed) self.keep_playing(ctx) + return # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name='dplaym', help="dplays multiple songs (seperated by semicolons ';')") async def dplaym_command(self, ctx, *, args): urls = args.split(';') + joined = await self.join_command(ctx) + if joined == False: + return for url in urls: - print("\n*****calling dplay_command with url: " + url) - await self.dplay_command(ctx, url=url) - print("\n*****returning from dplaym_command") + player = await YTDLSource.from_url(url, loop=self.bot.loop) + if player is None: + async with ctx.typing(): + embed = discord.Embed( + title="Error", + description=''.join(self.bad_request_error_message), + colour=0xff0000, + timestamp=datetime.datetime.utcnow() + ) + await ctx.send(embed=embed) + continue + self.music_queue.append([player, ctx, url, False]) + self.queued += 1 + async with ctx.typing(): + embed = discord.Embed( + title="Downloaded & Added to queue", + description="\"" + url + "\" requested by " + ctx.author.mention, + colour=0x00ff00, + timestamp=datetime.datetime.utcnow(), + ) + embed.set_thumbnail(url=self.MUSIC_ICON) + embed.set_author(name=player.title, url=player.url, + icon_url=ctx.author.avatar_url) + embed.add_field(name="Title", value=player.title, inline=False) + embed.add_field(name="Queue Position", value=len( + self.music_queue), inline=True) + await ctx.send(embed=embed) + self.keep_playing(ctx) return # ---------------------------------------------------------------------------------------------------------------------- - # @commands.command(name="repeat", help="loops the currently playing song") - # async def loop(self, ctx): - # if ctx.voice_client is None: - # async with ctx.typing(): - # embed=self.embed_error_no_vc_dex - # await ctx.send(embed=embed) - # return - # if (not ctx.voice_client.is_playing()) and (not ctx.voice_client.is_paused()): - # async with ctx.typing(): - # embed=discord.Embed( - # title="Error", - # description=''.join("Queue is empty, nothing to loop through\nUse ` play ` to add to queue"), - # colour=0xff0000, - # timestamp=datetime.datetime.utcnow() - # ) - # await ctx.send(embed=embed) - # return - # while True: + @commands.command(name='loop', help="toggles looping of the queue") + async def loop_command(self, ctx, loop_switch: typing.Optional[str]): + + if ctx.voice_client is None: + async with ctx.typing(): + embed = self.embed_error_no_vc_dex + await ctx.send(embed=embed) + return + + if loop_switch is None: + self.loop_queue = not self.loop_queue + if self.loop_queue: + loop_switch = "on" + else: + loop_switch = "off" + elif loop_switch.lower() == "on": + self.loop_queue = True + elif loop_switch.lower() == "off": + self.loop_queue = False + else: + async with ctx.typing(): + embed = discord.Embed( + title="Status", + colour=0xff0000, + timestamp=datetime.utcnow() + ) + embed.add_field( + name="Error", + value="Invalid value provided", + inline=True + ) + await ctx.send(embed=embed) + return + async with ctx.typing(): + embed = discord.Embed( + title="Status", + colour=0x00ff00, + timestamp=datetime.utcnow() + ) + embed.add_field( + name="Done", + value="Queue looping is now " + loop_switch.lower(), + inline=True + ) + await ctx.send(embed=embed) + return + # ---------------------------------------------------------------------------------------------------------------------- + + @commands.command(name='repeat', help="toggles repeating of the currently playing song") + async def repeat_command(self, ctx, repeat_switch: typing.Optional[str]): + + if ctx.voice_client is None: + async with ctx.typing(): + embed = self.embed_error_no_vc_dex + await ctx.send(embed=embed) + return + + if repeat_switch is None: + self.repeat_song = not self.repeat_song + if self.repeat_song: + repeat_switch = "on" + else: + repeat_switch = "off" + elif repeat_switch.lower() == "on": + self.repeat_song = True + elif repeat_switch.lower() == "off": + self.repeat_song = False + else: + async with ctx.typing(): + embed = discord.Embed( + title="Status", + colour=0xff0000, + timestamp=datetime.utcnow() + ) + embed.add_field( + name="Error", + value="Invalid value provided", + inline=True + ) + await ctx.send(embed=embed) + return + async with ctx.typing(): + embed = discord.Embed( + title="Status", + colour=0x00ff00, + timestamp=datetime.utcnow() + ) + embed.add_field( + name="Done", + value="Song repeat is now " + repeat_switch.lower(), + inline=True + ) + await ctx.send(embed=embed) + return # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="queue", aliases=["view"], help="displays the current queue") @@ -353,11 +490,13 @@ async def queue_command(self, ctx, *, url: typing.Optional[str]): if url != "": await self.play_command(ctx, url=url) return + if ctx.voice_client is None: async with ctx.typing(): embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) return + if len(self.music_queue) == 0: async with ctx.typing(): embed = discord.Embed( @@ -438,12 +577,13 @@ async def remove_command(self, ctx, pos): self.current -= 1 self.popped -= 1 elif self.current == pos: + self.repeat_song = False self.current -= 1 ctx.voice_client.stop() await ctx.send(embed=embed) # ---------------------------------------------------------------------------------------------------------------------- - @commands.command(name="jump", help="jumps to a song in the queue, takes song position as argument") + @commands.command(name="jump", alises=["jumpto"], help="jumps to a song in the queue, takes song position as argument") async def jump_command(self, ctx, pos): pos = int(pos) if ctx.voice_client is None: @@ -489,6 +629,7 @@ async def jump_command(self, ctx, pos): embed.add_field( name="Queue Looping", value="On" if self.loop_queue else "Off", inline=True) await ctx.send(embed=embed) + self.repeat_song = False self.popped = pos self.current = pos - 1 ctx.voice_client.stop() @@ -518,6 +659,8 @@ async def stop_command(self, ctx): self.current = -1 self.popped = 0 self.queued = 0 + self.loop_queue = False + self.repeat_song = False self.currently_playing_music = None self.currently_playing_player = None if ctx.voice_client is None: @@ -578,6 +721,7 @@ async def skip_command(self, ctx): value=ctx.author.mention, inline=False) embed.set_footer(text="skip requested by "+ctx.author.name) await ctx.send(embed=embed) + self.repeat_song = False self.popped += 1 ctx.voice_client.stop() return diff --git a/src/cogs/report.py b/src/cogs/report.py index d04bb057..1a41dd4e 100644 --- a/src/cogs/report.py +++ b/src/cogs/report.py @@ -20,7 +20,8 @@ async def on_ready(self): if m.bot: bot_count += 1 - channel = self.bot.get_channel(int(os.getenv('DEX_CONSOLE_CHANNEL_ID'))) + channel = self.bot.get_channel( + int(os.getenv('DEX_CONSOLE_CHANNEL_ID'))) embed = discord.Embed(title='Status', colour=0x0023dd, timestamp=datetime.utcnow()) fields = [ From 787ab655530f236fbcf742fa8eb5435bab733471 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Fri, 24 Jun 2022 00:25:48 +0530 Subject: [PATCH 37/60] Delete music2.py --- music2.py | 605 ------------------------------------------------------ 1 file changed, 605 deletions(-) delete mode 100644 music2.py diff --git a/music2.py b/music2.py deleted file mode 100644 index 3a4a4e2e..00000000 --- a/music2.py +++ /dev/null @@ -1,605 +0,0 @@ -import discord -import aiohttp -import json -import youtube_dl -import asyncio -import typing -import datetime -from discord.ext import commands - -# Suppress noise about console usage from errors -youtube_dl.utils.bug_reports_message = lambda: '' - - -YTDL_FORMAT_OPTIONS = { - 'format': 'bestaudio/best', - 'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s', - 'restrictfilenames': True, - 'noplaylist': True, - 'nocheckcertificate': True, - 'ignoreerrors': False, - 'logtostderr': False, - 'quiet': True, - 'no_warnings': True, - 'default_search': 'auto', - # binds to ipv4 since ipv6 addresses cause issues sometimes - 'source_address': '0.0.0.0' -} - -FFMPEG_OPTIONS = { - 'options': '-vn' -} - -ytdl = youtube_dl.YoutubeDL(YTDL_FORMAT_OPTIONS) - - -class YTDLSource(discord.PCMVolumeTransformer): - - def __init__(self, source, *, data, volume=0.5): - super().__init__(source, volume) - - self.data = data - self.title = data.get('title') - self.url = data.get('url') - - @classmethod - async def from_url(cls, url, *, loop=None, stream=False): - loop = loop or asyncio.get_event_loop() - data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=not stream)) - - if data is not None: - if 'entries' in data: - # take first item from a playlist - data = data['entries'][0] - else: - return None - - filename = data['url'] if stream else ytdl.prepare_filename(data) - return cls(discord.FFmpegPCMAudio(filename, **FFMPEG_OPTIONS), data=data) - - -class Music2(commands.Cog): - - # queue format: - # query/url(str) | download(bool) | ctx(ctx) - music_queue = [] - popped = 0 - currently_playing_music = () - currently_playing_player = None - is_playing = False - - bad_request_error_message = '' - bad_request_error_message += ( - ''.join("Bad response while searching for the music\n\n")) - bad_request_error_message += (''.join("**Possible causes include:**\n")) - bad_request_error_message += ( - ''.join("*1. bad network on the bot's end;\n")) - bad_request_error_message += ( - ''.join("2. the given search query couldn't find matching results;*\n")) - bad_request_error_message += (''.join( - "***3. too many queuing requests made, without letting the bot to respond to them;***\n")) - bad_request_error_message += (''.join( - "\n**To avoid any further unexpected errors, make the bot rejoin the voice channel using ` leave` and then ` join`**\n")) - bad_request_error_message += (''.join("**SORRY FOR THE INCONVENIENCE!**")) - - embed_error_no_vc_dex = discord.Embed( - title="Error", - description=''.join( - "Dex is not in any voice channel\n**Use ` join` to make it connect to one and then use music commands**"), - colour=0xff0000, - timestamp=datetime.datetime.utcnow() - ) - - MUSIC_ICON = "https://user-images.githubusercontent.com/63065397/156855077-ce6e0896-cc81-4d4d-98b8-3e7b70050afe.png" - - def __init__(self, bot): - self.bot = bot - self.is_playing = False - self.MUSIC_ICON = "https://user-images.githubusercontent.com/63065397/156855077-ce6e0896-cc81-4d4d-98b8-3e7b70050afe.png" - self.currently_playing_music = () - self.currently_playing_player = None - self.music_queue = [] - - @commands.command(name="join", aliases=["connect"], help="joins the voice channel of the author") - async def join_command(self, ctx): - if ctx.voice_client is None: - if ctx.author.voice is not None: - await ctx.author.voice.channel.connect() - return - else: - embed = discord.Embed( - title="Error", - description=ctx.author.mention + ", you are not connected to a voice channel", - colour=0xFF0000, - timestamp=datetime.datetime.utcnow() - ) - embed.set_footer(text="join request from " + ctx.author.name) - await ctx.send(embed=embed) - return - else: - if ctx.voice_client.is_playing() or ctx.voice_client.is_paused(): - pass - else: - if ctx.author.voice is not None: - await ctx.voice_client.move_to(ctx.author.voice.channel) - return - else: - embed = discord.Embed( - title="Error", - description=ctx.author.mention + ", you are not connected to a voice channel", - colour=0xFF0000, - timestamp=datetime.datetime.utcnow() - ) - embed.set_footer( - text="join request from " + ctx.author.name) - await ctx.send(embed=embed) - return - embed = discord.Embed( - title="Error", - description=''.join( - "Can't move b/w channels while playing music!\n**NOTE: **You can still add music to the queue!"), - colour=0xff0000, - timestamp=datetime.datetime.utcnow() - ) - embed.set_footer(text="join request from " + ctx.author.name) - await ctx.send(embed=embed) - - async def make_join(self, ctx): - if ctx.author.voice: - if ctx.voice_client is None: - await ctx.author.voice.channel.connect() - return True - else: - if (ctx.voice_client.is_playing() or ctx.voice_client.is_paused()) and (ctx.voice_client.channel != ctx.author.voice.channel): - async with ctx.typing(): - mssg_ = "Can't move b/w channels while playing music!\n**NOTE: **You can still add music to the queue!" - embed = discord.Embed( - title="Error", - description=mssg_, - colour=0xff0000, - timestamp=datetime.datetime.utcnow() - ) - embed.set_footer( - text="play request from " + ctx.author.name) - await ctx.send(embed=embed) - return True - else: - await ctx.voice_client.move_to(ctx.author.voice.channel) - return True - else: - async with ctx.typing(): - embed = discord.Embed( - title="Error", - description=ctx.author.mention + ", you are not connected to a voice channel", - colour=0xFF0000, - timestamp=datetime.datetime.utcnow() - ) - embed.set_footer(text="play request from " + ctx.author.name) - await ctx.send(embed=embed) - return False - - async def play_music_from_player(self, ctx, *, player): - if player is None: - return - self.currently_playing_player = player - embed = discord.Embed( - title="Now Playing", - description="- requested by " + - self.music_queue[0][1].author.mention, - colour=0x00ff00, - timestamp=datetime.datetime.utcnow() - ) - embed.set_thumbnail(url=self.MUSIC_ICON) - embed.set_author(name=player.title, url=player.url, - icon_url=ctx.author.avatar_url) - embed.add_field(name="Title", value=player.title, inline=False) - embed.add_field(name="Remaining in queue", - value=len(self.music_queue)-1, inline=False) - ctx.voice_client.play(player, after=lambda e: print( - f'Player error: {e}') if e else None) - await ctx.send(embed=embed) - - async def keep_playing(self, ctx): - while len(self.music_queue) > 0: - if (not ctx.voice_client.is_playing()) and (not ctx.voice_client.is_paused()): - self.is_playing = True - await self.play_music_from_player(self.music_queue[0][1], player=self.music_queue[0][0]) - self.music_queue.pop(0) - await asyncio.sleep(0.5) - - @commands.command(name="play", aliases=["stream", "p", "add"], help="streams a song directly from youtube") - async def play_command(self, ctx, *, url: typing.Optional[str]): - if (url is None) and (ctx.message.content[(len(ctx.message.content)-3):(len(ctx.message.content))] != "add"): - if ctx.voice_client is None: - await self.make_join(ctx) - if ctx.voice_client is None: - return - if ctx.voice_client.is_playing(): - return - if ctx.voice_client.is_paused(): - ctx.voice_client.resume() - elif len(self.music_queue) > 0: - if not ctx.voice_client.is_playing(): - await self.keep_playing(ctx) - else: - embed = discord.Embed( - title="Error", - description=''.join( - "Queue is empty, nothing to play\nUse ` play ` to add to queue"), - colour=0xff0000, - timestamp=datetime.datetime.utcnow() - ) - await ctx.send(embed=embed) - return - elif url is None: - async with ctx.typing(): - embed = discord.Embed( - title="Status", - colour=0xff0000, - timestamp=datetime.datetime.utcnow() - ) - n = "Error" - v = "Missing required arguements" - embed.add_field(name=n, value=v, inline=False) - await ctx.send(embed=embed) - - joined = await self.make_join(ctx) - if joined == False: - return - player = await YTDLSource.from_url(url, loop=self.bot.loop, stream=True) - if player is None: - async with ctx.typing(): - embed = discord.Embed( - title="Error", - description=''.join(self.bad_request_error_message), - colour=0xff0000, - timestamp=datetime.datetime.utcnow(), - ) - await ctx.send(embed=embed) - return - self.music_queue.append([player, ctx]) - async with ctx.typing(): - embed = discord.Embed( - title="Added to queue", - description="\"" + url + "\" requested by " + ctx.author.mention, - colour=0x00ff00, - timestamp=datetime.datetime.utcnow(), - ) - embed.set_thumbnail(url=self.MUSIC_ICON) - embed.set_author(name=player.title, url=player.url, - icon_url=ctx.author.avatar_url) - embed.add_field(name="Title", value=player.title, inline=False) - embed.add_field(name="Queue Position", value=len( - self.music_queue), inline=True) - await ctx.send(embed=embed) - await self.keep_playing(ctx) - - @commands.command(name='dplay', help="downloads a song and then plays it to reduce any possible lags") - async def dplay_command(self, ctx, *, url): - await self.make_join(ctx) - if ctx.voice_client is None: - return - player = await YTDLSource.from_url(url, loop=self.bot.loop) - if player is None: - async with ctx.typing(): - embed = discord.Embed( - title="Error", - description=''.join(self.bad_request_error_message), - colour=0xff0000, - timestamp=datetime.datetime.utcnow() - ) - await ctx.send(embed=embed) - return - self.music_queue.append([player, ctx]) - async with ctx.typing(): - embed = discord.Embed( - title="Downloaded & Added to queue", - description="\"" + url + "\" requested by " + ctx.author.mention, - colour=0x00ff00, - timestamp=datetime.datetime.utcnow(), - ) - embed.set_thumbnail(url=self.MUSIC_ICON) - embed.set_author(name=player.title, url=player.url, - icon_url=ctx.author.avatar_url) - embed.add_field(name="Title", value=player.title, inline=False) - embed.add_field(name="Queue Position", value=len( - self.music_queue), inline=True) - await ctx.send(embed=embed) - await self.keep_playing(ctx) - - # @commands.command(name="repeat", help="loops the currently playing song") - # async def loop(self, ctx): - # if ctx.voice_client is None: - # async with ctx.typing(): - # embed=self.embed_error_no_vc_dex - # await ctx.send(embed=embed) - # return - # if (not ctx.voice_client.is_playing()) and (not ctx.voice_client.is_paused()): - # async with ctx.typing(): - # embed=discord.Embed( - # title="Error", - # description=''.join("Queue is empty, nothing to loop through\nUse ` play ` to add to queue"), - # colour=0xff0000, - # timestamp=datetime.datetime.utcnow() - # ) - # await ctx.send(embed=embed) - # return - # while True: - - @commands.command(name="queue", aliases=["view"], help="displays the current queue") - async def queue_command(self, ctx, *args): - if (ctx.message.content[(len(ctx.message.content)-5):(len(ctx.message.content))] == "queue"): - url = "".join(args) - if url != "": - await self.play_command(ctx, url) - return - if ctx.voice_client is None: - async with ctx.typing(): - embed = self.embed_error_no_vc_dex - await ctx.send(embed=embed) - return - if len(self.music_queue) == 0: - async with ctx.typing(): - embed = discord.Embed( - title="Queue", - description=''.join( - "Queue is empty, nothing to play\nUse ` play ` to add to queue"), - colour=0xff0000, - timestamp=datetime.datetime.utcnow() - ) - await ctx.send(embed=embed) - return - embed = discord.Embed( - title="Queue", - colour=0x0000ff, - timestamp=datetime.datetime.utcnow() - ) - embed.set_thumbnail(url=self.MUSIC_ICON) - embed.set_author(name="Dex", icon_url=self.bot.user.avatar_url) - size = len(self.music_queue) - for i in range(0, size, 25): - if i + 25 > size: - for j in range(i, size): - embed.add_field( - name=str(j + 1), value=self.music_queue[j][0].title, inline=False) - else: - for j in range(i, i + 25): - embed.add_field( - name=str(j + 1), value=self.music_queue[j][0].title, inline=False) - async with ctx.typing(): - embed.set_footer( - text="Page " + str(int(i / 25) + 1) + " of " + str(int(size / 25) + 1)) - await ctx.send(embed=embed) - - @commands.command(name="remove", help="removes a song from the queue, takes song position as argument") - async def remove_command(self, ctx, pos): - pos = int(pos) - if ctx.voice_client is None: - async with ctx.typing(): - embed = self.embed_error_no_vc_dex - await ctx.send(embed=embed) - return - if len(self.music_queue) < int(pos): - async with ctx.typing(): - embed = discord.Embed( - title="Error", - description=''.join("There are only " + str(len(self.music_queue)) + - " songs in the queue\nNo song at position "+str(pos)+"\n**Use ` queue` to view the queue**"), - colour=0xff0000, - timestamp=datetime.datetime.utcnow() - ) - await ctx.send(embed=embed) - return - async with ctx.typing(): - embed = discord.Embed( - title="Removed from queue", - description="track requested by " + - self.music_queue[int(pos)-1][1].author.mention, - colour=0x00ff00, - timestamp=datetime.datetime.utcnow() - ) - player = self.music_queue[int(pos)-1][0] - embed.set_thumbnail(url=self.MUSIC_ICON) - embed.set_author(name=player.title, url=player.url, - icon_url=ctx.author.avatar_url) - embed.add_field(name="Title", value=player.title, inline=False) - embed.add_field(name="Remove request by", - value=ctx.author.mention, inline=True) - self.music_queue.pop(int(pos)-1) - await ctx.send(embed=embed) - - @commands.command(name="jump", help="jumps to a song in the queue, takes song position as argument") - async def jump_command(self, ctx, pos): - pos = int(pos) - if ctx.voice_client is None: - async with ctx.typing(): - embed = self.embed_error_no_vc_dex - await ctx.send(embed=embed) - return - if len(self.music_queue) < int(pos): - async with ctx.typing(): - embed = discord.Embed( - title="Error", - description=''.join("There are only " + str(len(self.music_queue)) + - " songs in the queue\nNo song at position "+str(pos)+"\n**Use ` queue` to view the queue**"), - colour=0xff0000, - timestamp=datetime.datetime.utcnow() - ) - await ctx.send(embed=embed) - return - async with ctx.typing(): - embed = discord.Embed( - title="Jumping to " + str(pos), - description="- requested by " + ctx.author.mention, - colour=0x00ff00, - timestamp=datetime.datetime.utcnow() - ) - player = self.music_queue[int(pos)-1][0] - embed.set_thumbnail(url=self.MUSIC_ICON) - embed.set_author(name=player.title, url=player.url, - icon_url=ctx.author.avatar_url) - embed.add_field(name="Title", value=player.title, inline=False) - embed.add_field(name="Remaining in queue", value=str( - len(self.music_queue)-pos), inline=True) - await ctx.send(embed=embed) - counter = 0 - while counter < int(pos) - 1: - self.music_queue.pop(0) - counter += 1 - await self.skip_command(ctx) - - @commands.command(name="volume", aliases=["vol"], help="changes the volume of the music player") - async def volume_command(self, ctx, volume: int): - if ctx.voice_client is None: - async with ctx.typing(): - embed = self.embed_error_no_vc_dex - await ctx.send(embed=embed) - return - ctx.voice_client.source.volume = volume / 100 - async with ctx.typing(): - embed = discord.Embed( - title=str(volume) + "%", - colour=0x00ff00, - timestamp=datetime.datetime.utcnow() - ) - embed.set_author(name="Volume set to", - icon_url=ctx.author.avatar_url) - await ctx.send(embed=embed) - - @commands.command(name="stop", aliases=["stfu", "shut"], help="stops the music player and clears the queue") - async def stop_command(self, ctx): - if ctx.voice_client is None: - async with ctx.typing(): - embed = self.embed_error_no_vc_dex - await ctx.send(embed=embed) - return - if ctx.voice_client.is_playing() or ctx.voice_client.is_paused(): - self.music_queue.clear() - ctx.voice_client.stop() - return - - @commands.command(name="pause", help="pauses the music player") - async def pause_command(self, ctx): - if ctx.voice_client is None: - embed = self.embed_error_no_vc_dex - await ctx.send(embed=embed) - elif ctx.voice_client.is_playing(): - ctx.voice_client.pause() - - @commands.command(name="resume", help="resumes the music player") - async def resume_command(self, ctx): - if ctx.voice_client is None: - embed = self.embed_error_no_vc_dex - await ctx.send(embed=embed) - elif ctx.voice_client.is_paused(): - ctx.voice_client.resume() - elif len(self.music_queue) > 0: - if not ctx.voice_client.is_playing(): - await self.keep_playing(ctx) - - @commands.command(name="leave", aliases=["disconnect, dc"], help="leaves if connected to any voice channel") - async def leave_command(self, ctx): - self.music_queue.clear() - self.currently_playing_music = None - self.currently_playing_player = None - if ctx.voice_client is None: - embed = self.embed_error_no_vc_dex - await ctx.send(embed=embed) - else: - await ctx.voice_client.disconnect() - - @commands.command(name="skip", aliases=["next"], help="skips the currently playing song") - async def skip_command(self, ctx): - if ctx.voice_client is None: - async with ctx.typing(): - embed = self.embed_error_no_vc_dex - await ctx.send(embed=embed) - else: - if ctx.voice_client.is_playing() or ctx.voice_client.is_paused(): - async with ctx.typing(): - embed = discord.Embed( - title="Skipping", - colour=0x00ff00, - timestamp=datetime.datetime.utcnow() - ) - player = self.currently_playing_player - embed.set_thumbnail(url=self.MUSIC_ICON) - embed.set_author( - name=player.title, url=player.url, icon_url=ctx.author.avatar_url) - embed.add_field( - name="Title", value=player.title, inline=False) - embed.add_field(name="Requested by", - value=ctx.author.mention, inline=False) - embed.set_footer(text="skip requested by "+ctx.author.name) - await ctx.send(embed=embed) - ctx.voice_client.stop() - - async def get_lyrics(self, song_title): - API_URL = "https://some-random-api.ml/lyrics?title=" + song_title - async with aiohttp.ClientSession() as session: - async with session.get(API_URL) as response: - data_json = await response.json() - return data_json - - @commands.command(name='lyrics', help='sends the lyrics of the song') - async def lyrics_command(self, ctx, *args) -> None: - song_title = '' - for arg in args: - song_title += arg+'%20' - if len(song_title) > 0: - song_title = song_title[:-3] - else: - if self.currently_playing_player is None: - async with ctx.typing(): - embed = discord.Embed( - title="Error", - description="No song is currently playing", - color=0xff0000, - timestamp=datetime.datetime.utcnow(), - ) - await ctx.send(embed=embed) - return - args = self.currently_playing_player.title.split() - for arg in args: - song_title += arg+'%20' - song_title = song_title[:-3] - - data = await self.get_lyrics(song_title) - if not 'lyrics' in data.keys(): - err_mssg = data['error'] - embed = discord.Embed( - title="Error", - description=err_mssg + - ('\n'+'[see results from GoogleSearch](https://www.google.com/search?q='+song_title+'+lyrics)'), - colour=0xff0000, - timestamp=datetime.datetime.utcnow(), - ) - await ctx.send(embed=embed) - else: - async with ctx.typing(): - lyrics = data['lyrics'] - extend_text = '\n[see results from GoogleSearch](https://www.google.com/search?q=' + \ - song_title+'+lyrics)' - if len(lyrics) > 3500: - lyrics = lyrics[:3500]+'... ' - extend_text = '[read more](https://www.google.com/search?q=' + \ - song_title+'+lyrics)' - - embed = discord.Embed( - title=data['title'], - description=lyrics+extend_text, - color=0x00ff00, - timestamp=datetime.datetime.utcnow(), - ) - embed.set_author( - name=data['author'], - ) - embed.set_thumbnail(url=data['thumbnail']['genius']) - embed.set_footer( - icon_url=ctx.author.avatar_url, - ) - await ctx.send(embed=embed) - - -# def setup(bot): -# bot.add_cog(Music(bot)) From 6b7315ea6895c85101409852e965f1304f18ecfa Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Fri, 24 Jun 2022 00:29:03 +0530 Subject: [PATCH 38/60] removed useless imports --- src/cogs/modset.py | 2 -- src/cogs/music.py | 3 --- 2 files changed, 5 deletions(-) diff --git a/src/cogs/modset.py b/src/cogs/modset.py index 6c1bfb46..3973179f 100644 --- a/src/cogs/modset.py +++ b/src/cogs/modset.py @@ -1,11 +1,9 @@ import discord -import psycopg2 from typing import Optional from datetime import datetime from discord.ext.commands import Cog from discord.ext.commands import command import os -import json class ModSet(Cog): diff --git a/src/cogs/music.py b/src/cogs/music.py index c2814725..ca860997 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -1,8 +1,5 @@ -from ast import alias -from turtle import title import discord import aiohttp -import json import youtube_dl import asyncio import typing From 0e7d14b763f19103c17176271fed5f8537a0c753 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Fri, 24 Jun 2022 00:54:58 +0530 Subject: [PATCH 39/60] Update music.py --- src/cogs/music.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index ca860997..23103b1e 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -215,7 +215,7 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): ctx.voice_client.resume() elif len(self.music_queue) > 0: if not ctx.voice_client.is_playing(): - self.keep_playing(ctx) + await self.keep_playing(ctx) else: embed = discord.Embed( title="Error", @@ -269,7 +269,7 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): embed.add_field(name="Queue Position", value=len( self.music_queue), inline=True) await ctx.send(embed=embed) - self.keep_playing(ctx) + await self.keep_playing(ctx) return # ---------------------------------------------------------------------------------------------------------------------- @@ -307,7 +307,7 @@ async def playm_command(self, ctx, *, args): embed.add_field(name="Queue Position", value=len( self.music_queue), inline=True) await ctx.send(embed=embed) - self.keep_playing(ctx) + await self.keep_playing(ctx) return # ---------------------------------------------------------------------------------------------------------------------- @@ -343,7 +343,7 @@ async def dplay_command(self, ctx, *, url): embed.add_field(name="Queue Position", value=len( self.music_queue), inline=True) await ctx.send(embed=embed) - self.keep_playing(ctx) + await self.keep_playing(ctx) return # ---------------------------------------------------------------------------------------------------------------------- @@ -381,7 +381,7 @@ async def dplaym_command(self, ctx, *, args): embed.add_field(name="Queue Position", value=len( self.music_queue), inline=True) await ctx.send(embed=embed) - self.keep_playing(ctx) + await self.keep_playing(ctx) return # ---------------------------------------------------------------------------------------------------------------------- From 153a475528169778beaae9af252c3e36369bfe03 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Fri, 24 Jun 2022 01:05:37 +0530 Subject: [PATCH 40/60] remove useless imports --- src/cogs/modset.py | 20 ++++++++++---------- src/cogs/music.py | 10 +++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/cogs/modset.py b/src/cogs/modset.py index 3973179f..0c7808ec 100644 --- a/src/cogs/modset.py +++ b/src/cogs/modset.py @@ -1,6 +1,6 @@ import discord from typing import Optional -from datetime import datetime +import datetime from discord.ext.commands import Cog from discord.ext.commands import command import os @@ -37,7 +37,7 @@ async def message_tags(self, ctx, switch: Optional[str]): embed = discord.Embed( title="Status", colour=0xff0000, - timestamp=datetime.utcnow() + timestamp=datetime.datetime.utcnow() ) embed.add_field( name="Error", @@ -56,7 +56,7 @@ async def message_tags(self, ctx, switch: Optional[str]): embed = discord.Embed( title="Status", colour=0x00ff00, - timestamp=datetime.utcnow() + timestamp=datetime.datetime.utcnow() ) embed.add_field( name="Done", @@ -71,7 +71,7 @@ async def change_prefix(self, ctx, *args): if ctx.guild.id == int(os.environ['DEX_PUBLIC_BOT_SERVER']): embed = discord.Embed(title="Status", colour=0xff0000, - timestamp=datetime.utcnow()) + timestamp=datetime.datetime.utcnow()) embed.add_field( name="Error", value="Prefix changes are not allowed on this server!", inline=True) await ctx.send(embed=embed) @@ -79,7 +79,7 @@ async def change_prefix(self, ctx, *args): if ctx.author != ctx.guild.owner: embed = discord.Embed(title="Status", colour=0xff0000, - timestamp=datetime.utcnow()) + timestamp=datetime.datetime.utcnow()) embed.add_field( name="Error", value="Only server owner can change the prefix!", inline=True) await ctx.send(embed=embed) @@ -93,14 +93,14 @@ async def change_prefix(self, ctx, *args): cur.close() embed = discord.Embed(title="Status", colour=0x00ff00, - timestamp=datetime.utcnow()) + timestamp=datetime.datetime.utcnow()) embed.add_field( name="Done", value="New Prefix is " + prefix, inline=True) await ctx.send(embed=embed) else: embed = discord.Embed(title="Status", colour=0xff0000, - timestamp=datetime.utcnow()) + timestamp=datetime.datetime.utcnow()) embed.add_field( name="Error", value="prefix length must be between (1 - 27)", inline=True) await ctx.send(embed=embed) @@ -110,7 +110,7 @@ async def leave_this_server(self, ctx): if ctx.author != ctx.guild.owner: embed = discord.Embed(title="Status", colour=0xff0000, - timestamp=datetime.utcnow()) + timestamp=datetime.datetime.utcnow()) embed.add_field( name="Error", value="Only server owner can use this command!", inline=True) await ctx.send(embed=embed) @@ -120,7 +120,7 @@ async def leave_this_server(self, ctx): Had a great time in {ctx.guild.name}! Now it's time, I guess! Report any issues: [Here](https://github.com/code-chaser/dex/issues/new) - """, color=0x8e38ce, timestamp=datetime.utcnow()) + """, color=0x8e38ce, timestamp=datetime.datetime.utcnow()) embed.set_image( url="https://user-images.githubusercontent.com/63065397/156924332-3638cd0d-9cf9-4e08-b4de-6f20cedd921a.png") embed.set_author( @@ -145,7 +145,7 @@ async def madeby(self, ctx): **codechaser#0647** **[GitHub](https://github.com/code-chaser)** """, - color=0x8e38ce, timestamp=datetime.utcnow()) + color=0x8e38ce, timestamp=datetime.datetime.utcnow()) embed.set_author(name="dex", url="https://github.com/code-chaser/dex/", icon_url=self.bot.user.avatar_url) diff --git a/src/cogs/music.py b/src/cogs/music.py index 23103b1e..618c7fbe 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -184,7 +184,7 @@ async def play_music_from_player(self, ctx, *, player): # ---------------------------------------------------------------------------------------------------------------------- async def keep_playing(self, ctx): - while ((len(self.music_queue) - self.popped > 0) or (self.loop_queue is True)) and (len(self.music_queue) > 0): + while ((len(self.music_queue) - self.current > 1) or (self.loop_queue is True)) and (len(self.music_queue) > 0): if ((not ctx.voice_client.is_playing()) and (not ctx.voice_client.is_paused())): self.is_playing = True if (not self.repeat_song) or (self.current == -1): @@ -409,7 +409,7 @@ async def loop_command(self, ctx, loop_switch: typing.Optional[str]): embed = discord.Embed( title="Status", colour=0xff0000, - timestamp=datetime.utcnow() + timestamp=datetime.datetime.utcnow() ) embed.add_field( name="Error", @@ -422,7 +422,7 @@ async def loop_command(self, ctx, loop_switch: typing.Optional[str]): embed = discord.Embed( title="Status", colour=0x00ff00, - timestamp=datetime.utcnow() + timestamp=datetime.datetime.utcnow() ) embed.add_field( name="Done", @@ -457,7 +457,7 @@ async def repeat_command(self, ctx, repeat_switch: typing.Optional[str]): embed = discord.Embed( title="Status", colour=0xff0000, - timestamp=datetime.utcnow() + timestamp=datetime.datetime.utcnow() ) embed.add_field( name="Error", @@ -470,7 +470,7 @@ async def repeat_command(self, ctx, repeat_switch: typing.Optional[str]): embed = discord.Embed( title="Status", colour=0x00ff00, - timestamp=datetime.utcnow() + timestamp=datetime.datetime.utcnow() ) embed.add_field( name="Done", From 3f5147ab0faf90b4fb5e7aec62730bf687508766 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Fri, 24 Jun 2022 02:04:39 +0530 Subject: [PATCH 41/60] Update music.py --- src/cogs/music.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index 618c7fbe..8e0aa5ce 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -63,7 +63,7 @@ async def from_url(cls, url, *, loop=None, stream=False): class Music(commands.Cog): # queue format: - # query/url(str) | download(bool) | ctx(ctx) + # player | ctx | url(from_user) | stream_or_not music_queue = [] popped = 0 current = -1 @@ -514,10 +514,21 @@ async def queue_command(self, ctx, *, url: typing.Optional[str]): embed.set_author(name="Dex", icon_url=self.bot.user.avatar_url) size = len(self.music_queue) for i in range(0, size, 25): + embed = discord.Embed( + title="Queue", + description=str("Page " + str(i // 25 + 1) + " of " + str(size // 25 + 1)), + colour=0x0000ff, + timestamp=datetime.datetime.utcnow() + ) + embed.set_thumbnail(url=self.MUSIC_ICON) + embed.set_author(name="Dex", icon_url=self.bot.user.avatar_url) for j in range(i, min(size, i + 25)): k = "**" if j == self.current else "" embed.add_field( - name=str(j + 1) + (" ***(Currently Playing)***" if j == self.current else ""), value=k+str(self.music_queue[j][0].title)+k, inline=False) + name=str(j + 1) + (" ***(Currently Playing)***" if j == self.current else ""), + value=k+str(self.music_queue[j][0].title)+k, + inline=False + ) async with ctx.typing(): embed.set_footer( text="Page " + str(int(i / 25) + 1) + " of " + str(int(size / 25) + 1)) From 2930f4ce1108e190ff519e89b7b0253bae1ca1d2 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Fri, 24 Jun 2022 02:44:42 +0530 Subject: [PATCH 42/60] Update music.py --- src/cogs/music.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cogs/music.py b/src/cogs/music.py index 8e0aa5ce..01e07123 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -106,6 +106,13 @@ def __init__(self, bot): self.currently_playing_music = () self.currently_playing_player = None self.music_queue = [] + # self.destroy() + # ---------------------------------------------------------------------------------------------------------------------- + + # async def destroy(self, bot): + # while(bot.user.voice.channel is not None): + # await asyncio.sleep(1) + # self.__del__() # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="join", aliases=["connect"], help="joins the voice channel of the author") @@ -159,6 +166,7 @@ async def leave_command(self, ctx): await ctx.send(embed=embed) else: await ctx.voice_client.disconnect() + self.__del__() # ---------------------------------------------------------------------------------------------------------------------- async def play_music_from_player(self, ctx, *, player): From 71e6676e4cc5585221ed1561b3554612ecd80fbd Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Fri, 24 Jun 2022 13:46:19 +0530 Subject: [PATCH 43/60] serious issue --- src/cogs/music.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index 01e07123..dbd740d5 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -64,15 +64,6 @@ class Music(commands.Cog): # queue format: # player | ctx | url(from_user) | stream_or_not - music_queue = [] - popped = 0 - current = -1 - queued = 0 - loop_queue = False - repeat_song = False - currently_playing_music = () - currently_playing_player = None - is_playing = False bad_request_error_message = '' bad_request_error_message += ( @@ -99,13 +90,22 @@ class Music(commands.Cog): MUSIC_ICON = "https://user-images.githubusercontent.com/63065397/156855077-ce6e0896-cc81-4d4d-98b8-3e7b70050afe.png" # ---------------------------------------------------------------------------------------------------------------------- - def __init__(self, bot): + async def __init__(self, bot): self.bot = bot self.is_playing = False self.MUSIC_ICON = "https://user-images.githubusercontent.com/63065397/156855077-ce6e0896-cc81-4d4d-98b8-3e7b70050afe.png" self.currently_playing_music = () self.currently_playing_player = None self.music_queue = [] + self.music_queue = [] + self.popped = 0 + self.current = -1 + self.queued = 0 + self.loop_queue = False + self.repeat_song = False + self.currently_playing_music = () + self.currently_playing_player = None + self.is_playing = False # self.destroy() # ---------------------------------------------------------------------------------------------------------------------- @@ -166,7 +166,6 @@ async def leave_command(self, ctx): await ctx.send(embed=embed) else: await ctx.voice_client.disconnect() - self.__del__() # ---------------------------------------------------------------------------------------------------------------------- async def play_music_from_player(self, ctx, *, player): @@ -811,6 +810,5 @@ async def lyrics_command(self, ctx, *args) -> None: await ctx.send(embed=embed) # ---------------------------------------------------------------------------------------------------------------------- - def setup(bot): bot.add_cog(Music(bot)) From 0719cce7f22d83090175807ad9532c54926e2fa2 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Fri, 24 Jun 2022 13:47:56 +0530 Subject: [PATCH 44/60] Update music.py --- src/cogs/music.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index dbd740d5..f6742aa4 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -90,7 +90,7 @@ class Music(commands.Cog): MUSIC_ICON = "https://user-images.githubusercontent.com/63065397/156855077-ce6e0896-cc81-4d4d-98b8-3e7b70050afe.png" # ---------------------------------------------------------------------------------------------------------------------- - async def __init__(self, bot): + def __init__(self, bot): self.bot = bot self.is_playing = False self.MUSIC_ICON = "https://user-images.githubusercontent.com/63065397/156855077-ce6e0896-cc81-4d4d-98b8-3e7b70050afe.png" From d62a05864c31ea88ceaac138c33388e3c3e30963 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Fri, 24 Jun 2022 13:53:09 +0530 Subject: [PATCH 45/60] Update music.py --- src/cogs/music.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index f6742aa4..606e8fdd 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -156,8 +156,8 @@ async def leave_command(self, ctx): self.music_queue.clear() self.currently_playing_music = None self.current = -1 - self.popped = 0 self.queued = 0 + self.popped = 0 self.loop_queue = False self.repeat_song = False self.currently_playing_player = None From e1b34b168d2a7e5e013c8782112366f9580e6c36 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Fri, 24 Jun 2022 14:33:27 +0530 Subject: [PATCH 46/60] bugfix --- src/cogs/music.py | 73 ++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index 606e8fdd..034888d4 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -63,7 +63,7 @@ async def from_url(cls, url, *, loop=None, stream=False): class Music(commands.Cog): # queue format: - # player | ctx | url(from_user) | stream_or_not + # [guild.id] -> [player | ctx | url(from_user) | stream_or_not] bad_request_error_message = '' bad_request_error_message += ( @@ -96,16 +96,13 @@ def __init__(self, bot): self.MUSIC_ICON = "https://user-images.githubusercontent.com/63065397/156855077-ce6e0896-cc81-4d4d-98b8-3e7b70050afe.png" self.currently_playing_music = () self.currently_playing_player = None - self.music_queue = [] - self.music_queue = [] + self.music_queue = {} self.popped = 0 self.current = -1 self.queued = 0 + self.vol = 1 self.loop_queue = False self.repeat_song = False - self.currently_playing_music = () - self.currently_playing_player = None - self.is_playing = False # self.destroy() # ---------------------------------------------------------------------------------------------------------------------- @@ -153,10 +150,11 @@ async def join_command(self, ctx): @commands.command(name="leave", aliases=["disconnect, dc"], help="leaves if connected to any voice channel") async def leave_command(self, ctx): - self.music_queue.clear() + self.music_queue[str(ctx.guild.id)].clear() self.currently_playing_music = None self.current = -1 self.queued = 0 + self.vol = 1 self.popped = 0 self.loop_queue = False self.repeat_song = False @@ -175,7 +173,7 @@ async def play_music_from_player(self, ctx, *, player): embed = discord.Embed( title="Now Playing", description="- requested by " + - self.music_queue[self.current][1].author.mention, + self.music_queue[str(ctx.guild.id)][self.current][1].author.mention, colour=0x00ff00, timestamp=datetime.datetime.utcnow() ) @@ -185,24 +183,25 @@ async def play_music_from_player(self, ctx, *, player): embed.add_field(name="Title", value=player.title, inline=False) embed.add_field(name="Position in queue", value=self.current+1, inline=False) + ctx.voice_client.source.volume = self.vol ctx.voice_client.play(player, after=lambda e: print( f'Player error: {e}') if e else None) await ctx.send(embed=embed) # ---------------------------------------------------------------------------------------------------------------------- async def keep_playing(self, ctx): - while ((len(self.music_queue) - self.current > 1) or (self.loop_queue is True)) and (len(self.music_queue) > 0): + while ((len(self.music_queue[str(ctx.guild.id)]) - self.current > 1) or (self.loop_queue is True)) and (len(self.music_queue[str(ctx.guild.id)]) > 0): if ((not ctx.voice_client.is_playing()) and (not ctx.voice_client.is_paused())): self.is_playing = True if (not self.repeat_song) or (self.current == -1): self.current += 1 - if self.popped == len(self.music_queue): + if self.popped == len(self.music_queue[str(ctx.guild.id)]): self.popped = 0 - if self.current == len(self.music_queue): + if self.current == len(self.music_queue[str(ctx.guild.id)]): self.current = 0 - player = await YTDLSource.from_url(self.music_queue[self.current][2], loop=self.bot.loop, stream=self.music_queue[self.current][3]) - self.music_queue[self.current][0] = player - await self.play_music_from_player(self.music_queue[self.current][1], player=player) + player = await YTDLSource.from_url(self.music_queue[str(ctx.guild.id)][self.current][2], loop=self.bot.loop, stream=self.music_queue[str(ctx.guild.id)][self.current][3]) + self.music_queue[str(ctx.guild.id)][self.current][0] = player + await self.play_music_from_player(self.music_queue[str(ctx.guild.id)][self.current][1], player=player) if not self.repeat_song: self.popped += 1 await asyncio.sleep(0.5) @@ -220,7 +219,7 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): return if ctx.voice_client.is_paused(): ctx.voice_client.resume() - elif len(self.music_queue) > 0: + elif len(self.music_queue[str(ctx.guild.id)]) > 0: if not ctx.voice_client.is_playing(): await self.keep_playing(ctx) else: @@ -260,7 +259,7 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): ) await ctx.send(embed=embed) return - self.music_queue.append([player, ctx, url, True]) + self.music_queue[str(ctx.guild.id)].append([player, ctx, url, True]) self.queued += 1 async with ctx.typing(): embed = discord.Embed( @@ -274,7 +273,7 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): icon_url=ctx.author.avatar_url) embed.add_field(name="Title", value=player.title, inline=False) embed.add_field(name="Queue Position", value=len( - self.music_queue), inline=True) + self.music_queue[str(ctx.guild.id)]), inline=True) await ctx.send(embed=embed) await self.keep_playing(ctx) return @@ -298,7 +297,7 @@ async def playm_command(self, ctx, *, args): ) await ctx.send(embed=embed) continue - self.music_queue.append([player, ctx, url, True]) + self.music_queue[str(ctx.guild.id)].append([player, ctx, url, True]) self.queued += 1 async with ctx.typing(): embed = discord.Embed( @@ -312,7 +311,7 @@ async def playm_command(self, ctx, *, args): icon_url=ctx.author.avatar_url) embed.add_field(name="Title", value=player.title, inline=False) embed.add_field(name="Queue Position", value=len( - self.music_queue), inline=True) + self.music_queue[str(ctx.guild.id)]), inline=True) await ctx.send(embed=embed) await self.keep_playing(ctx) return @@ -334,7 +333,7 @@ async def dplay_command(self, ctx, *, url): ) await ctx.send(embed=embed) return - self.music_queue.append([player, ctx, url, False]) + self.music_queue[str(ctx.guild.id)].append([player, ctx, url, False]) self.queued += 1 async with ctx.typing(): embed = discord.Embed( @@ -348,7 +347,7 @@ async def dplay_command(self, ctx, *, url): icon_url=ctx.author.avatar_url) embed.add_field(name="Title", value=player.title, inline=False) embed.add_field(name="Queue Position", value=len( - self.music_queue), inline=True) + self.music_queue[str(ctx.guild.id)]), inline=True) await ctx.send(embed=embed) await self.keep_playing(ctx) return @@ -372,7 +371,7 @@ async def dplaym_command(self, ctx, *, args): ) await ctx.send(embed=embed) continue - self.music_queue.append([player, ctx, url, False]) + self.music_queue[str(ctx.guild.id)].append([player, ctx, url, False]) self.queued += 1 async with ctx.typing(): embed = discord.Embed( @@ -386,7 +385,7 @@ async def dplaym_command(self, ctx, *, args): icon_url=ctx.author.avatar_url) embed.add_field(name="Title", value=player.title, inline=False) embed.add_field(name="Queue Position", value=len( - self.music_queue), inline=True) + self.music_queue[str(ctx.guild.id)]), inline=True) await ctx.send(embed=embed) await self.keep_playing(ctx) return @@ -501,7 +500,7 @@ async def queue_command(self, ctx, *, url: typing.Optional[str]): await ctx.send(embed=embed) return - if len(self.music_queue) == 0: + if len(self.music_queue[str(ctx.guild.id)]) == 0: async with ctx.typing(): embed = discord.Embed( title="Queue", @@ -519,7 +518,7 @@ async def queue_command(self, ctx, *, url: typing.Optional[str]): ) embed.set_thumbnail(url=self.MUSIC_ICON) embed.set_author(name="Dex", icon_url=self.bot.user.avatar_url) - size = len(self.music_queue) + size = len(self.music_queue[str(ctx.guild.id)]) for i in range(0, size, 25): embed = discord.Embed( title="Queue", @@ -533,7 +532,7 @@ async def queue_command(self, ctx, *, url: typing.Optional[str]): k = "**" if j == self.current else "" embed.add_field( name=str(j + 1) + (" ***(Currently Playing)***" if j == self.current else ""), - value=k+str(self.music_queue[j][0].title)+k, + value=k+str(self.music_queue[str(ctx.guild.id)][j][0].title)+k, inline=False ) async with ctx.typing(): @@ -560,12 +559,12 @@ async def remove_command(self, ctx, pos): ) await ctx.send(embed=embed) return - if (1 > int(pos)) or (len(self.music_queue) < int(pos)): + if (1 > int(pos)) or (len(self.music_queue[str(ctx.guild.id)]) < int(pos)): async with ctx.typing(): embed = discord.Embed( title="Error", description=str( - "Queue Position must be between (1 & "+str(len(self.music_queue))+")"), + "Queue Position must be between (1 & "+str(len(self.music_queue[str(ctx.guild.id)]))+")"), colour=0xff0000, timestamp=datetime.datetime.utcnow() ) @@ -576,18 +575,18 @@ async def remove_command(self, ctx, pos): embed = discord.Embed( title="Removed from queue", description="track requested by " + - self.music_queue[int(pos)][1].author.mention, + self.music_queue[str(ctx.guild.id)][int(pos)][1].author.mention, colour=0x00ff00, timestamp=datetime.datetime.utcnow() ) - player = self.music_queue[int(pos)][0] + player = self.music_queue[str(ctx.guild.id)][int(pos)][0] embed.set_thumbnail(url=self.MUSIC_ICON) embed.set_author(name=player.title, url=player.url, icon_url=ctx.author.avatar_url) embed.add_field(name="Title", value=player.title, inline=False) embed.add_field(name="Remove request by", value=ctx.author.mention, inline=True) - self.music_queue.pop(int(pos)) + self.music_queue[str(ctx.guild.id)].pop(int(pos)) if self.current > pos: self.current -= 1 self.popped -= 1 @@ -617,12 +616,12 @@ async def jump_command(self, ctx, pos): ) await ctx.send(embed=embed) return - if (1 > int(pos)) or (len(self.music_queue) < int(pos)): + if (1 > int(pos)) or (len(self.music_queue[str(ctx.guild.id)]) < int(pos)): async with ctx.typing(): embed = discord.Embed( title="Error", description=str( - "Queue Position must be between (1 & "+str(len(self.music_queue))+")"), + "Queue Position must be between (1 & "+str(len(self.music_queue[str(ctx.guild.id)]))+")"), colour=0xff0000, timestamp=datetime.datetime.utcnow() ) @@ -636,7 +635,7 @@ async def jump_command(self, ctx, pos): colour=0x00ff00, timestamp=datetime.datetime.utcnow() ) - player = self.music_queue[int(pos)][0] + player = self.music_queue[str(ctx.guild.id)][int(pos)][0] embed.set_thumbnail(url=self.MUSIC_ICON) embed.set_author(name=player.title, url=player.url, icon_url=ctx.author.avatar_url) @@ -658,6 +657,7 @@ async def volume_command(self, ctx, volume: int): await ctx.send(embed=embed) return ctx.voice_client.source.volume = volume / 100 + self.vol=volume async with ctx.typing(): embed = discord.Embed( title=str(volume) + "%", @@ -674,6 +674,7 @@ async def stop_command(self, ctx): self.current = -1 self.popped = 0 self.queued = 0 + self.vol = 1 self.loop_queue = False self.repeat_song = False self.currently_playing_music = None @@ -684,7 +685,7 @@ async def stop_command(self, ctx): await ctx.send(embed=embed) return if ctx.voice_client.is_playing() or ctx.voice_client.is_paused(): - self.music_queue.clear() + self.music_queue[str(ctx.guild.id)].clear() ctx.voice_client.stop() return # ---------------------------------------------------------------------------------------------------------------------- @@ -706,7 +707,7 @@ async def resume_command(self, ctx): await ctx.send(embed=embed) elif ctx.voice_client.is_paused(): ctx.voice_client.resume() - elif len(self.music_queue) > 0: + elif len(self.music_queue[str(ctx.guild.id)]) > 0: if not ctx.voice_client.is_playing(): await self.keep_playing(ctx) return From 646202af650b8c428b8a771c8758a3bd08fa0bb0 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Fri, 24 Jun 2022 15:01:53 +0530 Subject: [PATCH 47/60] Update music.py --- src/cogs/music.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/cogs/music.py b/src/cogs/music.py index 034888d4..97542699 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -111,9 +111,20 @@ def __init__(self, bot): # await asyncio.sleep(1) # self.__del__() # ---------------------------------------------------------------------------------------------------------------------- + + # async def on_voice_state_update(self): + # pass + # ---------------------------------------------------------------------------------------------------------------------- + + def create_guild_queue(self,ctx): + if str(ctx.guild.id) not in self.music_queue.keys(): + self.music_queue[str(ctx.guild.id)] = [] + return + # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="join", aliases=["connect"], help="joins the voice channel of the author") async def join_command(self, ctx): + self.create_guild_queue(ctx) if ctx.author.voice is None: async with ctx.typing(): embed = discord.Embed( @@ -150,6 +161,7 @@ async def join_command(self, ctx): @commands.command(name="leave", aliases=["disconnect, dc"], help="leaves if connected to any voice channel") async def leave_command(self, ctx): + self.create_guild_queue(ctx) self.music_queue[str(ctx.guild.id)].clear() self.currently_playing_music = None self.current = -1 @@ -210,6 +222,7 @@ async def keep_playing(self, ctx): @commands.command(name="play", aliases=["stream", "p", "add"], help="streams a song directly from youtube") async def play_command(self, ctx, *, url: typing.Optional[str]): + self.create_guild_queue(ctx) if (url is None) and (ctx.message.content[(len(ctx.message.content)-3):(len(ctx.message.content))] != "add"): if ctx.voice_client is None: await self.join_command(ctx) @@ -281,6 +294,7 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): @commands.command(name="playm", aliases=["streamm", "pm", "addm"], help="plays multiple songs (seperated by semicolons ';')") async def playm_command(self, ctx, *, args): + self.create_guild_queue(ctx) urls = args.split(';') joined = await self.join_command(ctx) if joined == False: @@ -319,6 +333,7 @@ async def playm_command(self, ctx, *, args): @commands.command(name='dplay', help="downloads a song and then queues it to reduce any possible lags") async def dplay_command(self, ctx, *, url): + self.create_guild_queue(ctx) joined = await self.join_command(ctx) if joined == False: return @@ -355,6 +370,7 @@ async def dplay_command(self, ctx, *, url): @commands.command(name='dplaym', help="dplays multiple songs (seperated by semicolons ';')") async def dplaym_command(self, ctx, *, args): + self.create_guild_queue(ctx) urls = args.split(';') joined = await self.join_command(ctx) if joined == False: @@ -394,6 +410,8 @@ async def dplaym_command(self, ctx, *, args): @commands.command(name='loop', help="toggles looping of the queue") async def loop_command(self, ctx, loop_switch: typing.Optional[str]): + self.create_guild_queue(ctx) + if ctx.voice_client is None: async with ctx.typing(): embed = self.embed_error_no_vc_dex @@ -442,6 +460,8 @@ async def loop_command(self, ctx, loop_switch: typing.Optional[str]): @commands.command(name='repeat', help="toggles repeating of the currently playing song") async def repeat_command(self, ctx, repeat_switch: typing.Optional[str]): + self.create_guild_queue(ctx) + if ctx.voice_client is None: async with ctx.typing(): embed = self.embed_error_no_vc_dex @@ -489,6 +509,9 @@ async def repeat_command(self, ctx, repeat_switch: typing.Optional[str]): @commands.command(name="queue", aliases=["view"], help="displays the current queue") async def queue_command(self, ctx, *, url: typing.Optional[str]): + + self.create_guild_queue(ctx) + if url is not None: if url != "": await self.play_command(ctx, url=url) @@ -543,6 +566,7 @@ async def queue_command(self, ctx, *, url: typing.Optional[str]): @commands.command(name="remove", help="removes a song from the queue, takes song position as argument") async def remove_command(self, ctx, pos): + self.create_guild_queue(ctx) if ctx.voice_client is None: async with ctx.typing(): embed = self.embed_error_no_vc_dex @@ -599,6 +623,7 @@ async def remove_command(self, ctx, pos): @commands.command(name="jump", alises=["jumpto"], help="jumps to a song in the queue, takes song position as argument") async def jump_command(self, ctx, pos): + self.create_guild_queue(ctx) pos = int(pos) if ctx.voice_client is None: async with ctx.typing(): @@ -671,6 +696,7 @@ async def volume_command(self, ctx, volume: int): @commands.command(name="stop", aliases=["stfu", "shut"], help="stops the music player and clears the queue") async def stop_command(self, ctx): + self.create_guild_queue(ctx) self.current = -1 self.popped = 0 self.queued = 0 @@ -692,6 +718,7 @@ async def stop_command(self, ctx): @commands.command(name="pause", help="pauses the music player") async def pause_command(self, ctx): + self.create_guild_queue(ctx) if ctx.voice_client is None: embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) @@ -702,6 +729,7 @@ async def pause_command(self, ctx): @commands.command(name="resume", help="resumes the music player") async def resume_command(self, ctx): + self.create_guild_queue(ctx) if ctx.voice_client is None: embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) @@ -715,6 +743,7 @@ async def resume_command(self, ctx): @commands.command(name="skip", aliases=["next"], help="skips the currently playing song") async def skip_command(self, ctx): + self.create_guild_queue(ctx) if ctx.voice_client is None: async with ctx.typing(): embed = self.embed_error_no_vc_dex @@ -753,6 +782,7 @@ async def get_lyrics(self, song_title): @commands.command(name='lyrics', help='sends the lyrics of the song') async def lyrics_command(self, ctx, *args) -> None: + self.create_guild_queue(ctx) song_title = '' for arg in args: song_title += arg+'%20' From 593d856aeb2956e510e4d0cc3137d729a05907ed Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Fri, 24 Jun 2022 15:21:18 +0530 Subject: [PATCH 48/60] Update music.py --- src/cogs/music.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index 97542699..0df718be 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -182,23 +182,25 @@ async def play_music_from_player(self, ctx, *, player): if player is None: return self.currently_playing_player = player - embed = discord.Embed( - title="Now Playing", - description="- requested by " + - self.music_queue[str(ctx.guild.id)][self.current][1].author.mention, - colour=0x00ff00, - timestamp=datetime.datetime.utcnow() - ) - embed.set_thumbnail(url=self.MUSIC_ICON) - embed.set_author(name=player.title, url=player.url, - icon_url=ctx.author.avatar_url) - embed.add_field(name="Title", value=player.title, inline=False) - embed.add_field(name="Position in queue", - value=self.current+1, inline=False) - ctx.voice_client.source.volume = self.vol + async with ctx.typing(): + embed = discord.Embed( + title="Now Playing", + description="- requested by " + + self.music_queue[str(ctx.guild.id)][self.current][1].author.mention, + colour=0x00ff00, + timestamp=datetime.datetime.utcnow() + ) + embed.set_thumbnail(url=self.MUSIC_ICON) + embed.set_author(name=player.title, url=player.url, + icon_url=ctx.author.avatar_url) + embed.add_field(name="Title", value=player.title, inline=False) + embed.add_field(name="Position in queue", + value=self.current+1, inline=False) + embed.add_field(name="Volume", value=str(self.vol * 100) + "%", inline=False) + await ctx.send(embed=embed) ctx.voice_client.play(player, after=lambda e: print( f'Player error: {e}') if e else None) - await ctx.send(embed=embed) + ctx.voice_client.source.volume = self.vol # ---------------------------------------------------------------------------------------------------------------------- async def keep_playing(self, ctx): @@ -682,7 +684,7 @@ async def volume_command(self, ctx, volume: int): await ctx.send(embed=embed) return ctx.voice_client.source.volume = volume / 100 - self.vol=volume + self.vol = volume / 100 async with ctx.typing(): embed = discord.Embed( title=str(volume) + "%", From af49c7e129c2201268b12be8985a092649a36e18 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sat, 25 Jun 2022 13:26:41 +0530 Subject: [PATCH 49/60] Update music.py --- src/cogs/music.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index 0df718be..45d1b20d 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -63,7 +63,7 @@ async def from_url(cls, url, *, loop=None, stream=False): class Music(commands.Cog): # queue format: - # [guild.id] -> [player | ctx | url(from_user) | stream_or_not] + # [guild.id] -> [0 player | 1 ctx | 2 url(from_user) | 3 stream_or_not] bad_request_error_message = '' bad_request_error_message += ( @@ -512,6 +512,9 @@ async def repeat_command(self, ctx, repeat_switch: typing.Optional[str]): @commands.command(name="queue", aliases=["view"], help="displays the current queue") async def queue_command(self, ctx, *, url: typing.Optional[str]): + if str(ctx.guild.id) in self.music_queue: # for debugging purposes + print(self.music_queue[str(ctx.guild.id)]) + self.create_guild_queue(ctx) if url is not None: From 18028066901ab04572ea8d3f5a8075adf1374716 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sat, 25 Jun 2022 14:33:39 +0530 Subject: [PATCH 50/60] Update music.py --- src/cogs/music.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cogs/music.py b/src/cogs/music.py index 45d1b20d..4251fca3 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -302,6 +302,7 @@ async def playm_command(self, ctx, *, args): if joined == False: return for url in urls: + url = url.strip() player = await YTDLSource.from_url(url, loop=self.bot.loop, stream=True) if player is None: async with ctx.typing(): @@ -378,6 +379,7 @@ async def dplaym_command(self, ctx, *, args): if joined == False: return for url in urls: + url = url.strip() player = await YTDLSource.from_url(url, loop=self.bot.loop) if player is None: async with ctx.typing(): From e56bf6ea596d61f0f25523192bcc98d6f612942a Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sat, 25 Jun 2022 14:44:52 +0530 Subject: [PATCH 51/60] Update music.py --- src/cogs/music.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index 4251fca3..3d1b6c45 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -301,6 +301,7 @@ async def playm_command(self, ctx, *, args): joined = await self.join_command(ctx) if joined == False: return + last_url = urls.pop() for url in urls: url = url.strip() player = await YTDLSource.from_url(url, loop=self.bot.loop, stream=True) @@ -330,7 +331,7 @@ async def playm_command(self, ctx, *, args): embed.add_field(name="Queue Position", value=len( self.music_queue[str(ctx.guild.id)]), inline=True) await ctx.send(embed=embed) - await self.keep_playing(ctx) + await self.play_command(ctx, url=last_url) return # ---------------------------------------------------------------------------------------------------------------------- @@ -378,6 +379,7 @@ async def dplaym_command(self, ctx, *, args): joined = await self.join_command(ctx) if joined == False: return + last_url=urls.pop() for url in urls: url = url.strip() player = await YTDLSource.from_url(url, loop=self.bot.loop) @@ -407,7 +409,7 @@ async def dplaym_command(self, ctx, *, args): embed.add_field(name="Queue Position", value=len( self.music_queue[str(ctx.guild.id)]), inline=True) await ctx.send(embed=embed) - await self.keep_playing(ctx) + await self.dplay_command(ctx, url=last_url) return # ---------------------------------------------------------------------------------------------------------------------- From 81ee4bc703b53c2194652a61c9f4a15e421f4169 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sat, 25 Jun 2022 17:54:08 +0530 Subject: [PATCH 52/60] some progress (flag:X3s4) --- src/cogs/music.py | 82 +++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 31 deletions(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index 3d1b6c45..3c797bf9 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -97,7 +97,6 @@ def __init__(self, bot): self.currently_playing_music = () self.currently_playing_player = None self.music_queue = {} - self.popped = 0 self.current = -1 self.queued = 0 self.vol = 1 @@ -167,7 +166,6 @@ async def leave_command(self, ctx): self.current = -1 self.queued = 0 self.vol = 1 - self.popped = 0 self.loop_queue = False self.repeat_song = False self.currently_playing_player = None @@ -207,17 +205,12 @@ async def keep_playing(self, ctx): while ((len(self.music_queue[str(ctx.guild.id)]) - self.current > 1) or (self.loop_queue is True)) and (len(self.music_queue[str(ctx.guild.id)]) > 0): if ((not ctx.voice_client.is_playing()) and (not ctx.voice_client.is_paused())): self.is_playing = True - if (not self.repeat_song) or (self.current == -1): + if (not self.repeat_song): self.current += 1 - if self.popped == len(self.music_queue[str(ctx.guild.id)]): - self.popped = 0 - if self.current == len(self.music_queue[str(ctx.guild.id)]): - self.current = 0 + self.current %= len(self.music_queue[str(ctx.guild.id)]) player = await YTDLSource.from_url(self.music_queue[str(ctx.guild.id)][self.current][2], loop=self.bot.loop, stream=self.music_queue[str(ctx.guild.id)][self.current][3]) self.music_queue[str(ctx.guild.id)][self.current][0] = player await self.play_music_from_player(self.music_queue[str(ctx.guild.id)][self.current][1], player=player) - if not self.repeat_song: - self.popped += 1 await asyncio.sleep(0.5) return # ---------------------------------------------------------------------------------------------------------------------- @@ -622,7 +615,6 @@ async def remove_command(self, ctx, pos): self.music_queue[str(ctx.guild.id)].pop(int(pos)) if self.current > pos: self.current -= 1 - self.popped -= 1 elif self.current == pos: self.repeat_song = False self.current -= 1 @@ -678,7 +670,6 @@ async def jump_command(self, ctx, pos): name="Queue Looping", value="On" if self.loop_queue else "Off", inline=True) await ctx.send(embed=embed) self.repeat_song = False - self.popped = pos self.current = pos - 1 ctx.voice_client.stop() # ---------------------------------------------------------------------------------------------------------------------- @@ -707,7 +698,6 @@ async def volume_command(self, ctx, volume: int): async def stop_command(self, ctx): self.create_guild_queue(ctx) self.current = -1 - self.popped = 0 self.queued = 0 self.vol = 1 self.loop_queue = False @@ -750,8 +740,8 @@ async def resume_command(self, ctx): return # ---------------------------------------------------------------------------------------------------------------------- - @commands.command(name="skip", aliases=["next"], help="skips the currently playing song") - async def skip_command(self, ctx): + @commands.command(name="next", aliases=["skip"], help="plays the next song in the queue") + async def next_command(self, ctx): self.create_guild_queue(ctx) if ctx.voice_client is None: async with ctx.typing(): @@ -759,24 +749,53 @@ async def skip_command(self, ctx): await ctx.send(embed=embed) else: if ctx.voice_client.is_playing() or ctx.voice_client.is_paused(): - async with ctx.typing(): - embed = discord.Embed( - title="Skipping", - colour=0x00ff00, - timestamp=datetime.datetime.utcnow() - ) - player = self.currently_playing_player - embed.set_thumbnail(url=self.MUSIC_ICON) - embed.set_author( - name=player.title, url=player.url, icon_url=ctx.author.avatar_url) - embed.add_field( - name="Title", value=player.title, inline=False) - embed.add_field(name="Requested by", - value=ctx.author.mention, inline=False) - embed.set_footer(text="skip requested by "+ctx.author.name) - await ctx.send(embed=embed) + # async with ctx.typing(): + # embed = discord.Embed( + # title="Skipping", + # colour=0x00ff00, + # timestamp=datetime.datetime.utcnow() + # ) + # player = self.currently_playing_player + # embed.set_thumbnail(url=self.MUSIC_ICON) + # embed.set_author( + # name=player.title, url=player.url, icon_url=ctx.author.avatar_url) + # embed.add_field( + # name="Title", value=player.title, inline=False) + # embed.add_field(name="Requested by", + # value=ctx.author.mention, inline=False) + # embed.set_footer(text="skip requested by "+ctx.author.name) + # await ctx.send(embed=embed) + self.repeat_song = False + ctx.voice_client.stop() + return + # ---------------------------------------------------------------------------------------------------------------------- + + @commands.command(name="previous", aliases=["prev"], help="plays the previous song in the queue") + async def next_command(self, ctx): + self.create_guild_queue(ctx) + if ctx.voice_client is None: + async with ctx.typing(): + embed = self.embed_error_no_vc_dex + await ctx.send(embed=embed) + else: + if ctx.voice_client.is_playing() or ctx.voice_client.is_paused(): + # async with ctx.typing(): + # embed = discord.Embed( + # title="Skipping", + # colour=0x00ff00, + # timestamp=datetime.datetime.utcnow() + # ) + # player = self.currently_playing_player + # embed.set_thumbnail(url=self.MUSIC_ICON) + # embed.set_author( + # name=player.title, url=player.url, icon_url=ctx.author.avatar_url) + # embed.add_field( + # name="Title", value=player.title, inline=False) + # embed.add_field(name="Requested by", + # value=ctx.author.mention, inline=False) + # embed.set_footer(text="skip requested by "+ctx.author.name) + # await ctx.send(embed=embed) self.repeat_song = False - self.popped += 1 ctx.voice_client.stop() return # ---------------------------------------------------------------------------------------------------------------------- @@ -850,5 +869,6 @@ async def lyrics_command(self, ctx, *args) -> None: await ctx.send(embed=embed) # ---------------------------------------------------------------------------------------------------------------------- + def setup(bot): bot.add_cog(Music(bot)) From a57d7e5d3e1a35a368a839d704759f814f5c72c7 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sat, 25 Jun 2022 21:20:54 +0530 Subject: [PATCH 53/60] using discord.ui.Button --- src/cogs/music.py | 73 ++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index 3c797bf9..c4bc7afb 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -5,6 +5,7 @@ import typing import datetime from discord.ext import commands +from discord.ui import Button, Paginator, View # Suppress noise about console usage from errors youtube_dl.utils.bug_reports_message = lambda: '' @@ -97,7 +98,7 @@ def __init__(self, bot): self.currently_playing_music = () self.currently_playing_player = None self.music_queue = {} - self.current = -1 + self.current = 0 self.queued = 0 self.vol = 1 self.loop_queue = False @@ -163,7 +164,7 @@ async def leave_command(self, ctx): self.create_guild_queue(ctx) self.music_queue[str(ctx.guild.id)].clear() self.currently_playing_music = None - self.current = -1 + self.current = 0 self.queued = 0 self.vol = 1 self.loop_queue = False @@ -181,6 +182,7 @@ async def play_music_from_player(self, ctx, *, player): return self.currently_playing_player = player async with ctx.typing(): + # Embed embed = discord.Embed( title="Now Playing", description="- requested by " + @@ -195,7 +197,23 @@ async def play_music_from_player(self, ctx, *, player): embed.add_field(name="Position in queue", value=self.current+1, inline=False) embed.add_field(name="Volume", value=str(self.vol * 100) + "%", inline=False) - await ctx.send(embed=embed) + # View + restart_btn = Button() + previous_btn = Button() + play_btn = Button() + pause_btn = Button() + next_btn = Button() + repeat_song_btn = Button() + loop_queue_btn = Button() + view = discord.ui.View() + view.add_item(restart_btn) + view.add_item(previous_btn) + view.add_item(play_btn) + view.add_item(pause_btn) + view.add_item(next_btn) + view.add_item(repeat_song_btn) + view.add_item(loop_queue_btn) + await ctx.send(embed=embed, view=view) ctx.voice_client.play(player, after=lambda e: print( f'Player error: {e}') if e else None) ctx.voice_client.source.volume = self.vol @@ -506,6 +524,19 @@ async def repeat_command(self, ctx, repeat_switch: typing.Optional[str]): return # ---------------------------------------------------------------------------------------------------------------------- + @commands.command(name='restart', help="restarts the currently playing song") + async def restart_command(self, ctx): + self.create_guild_queue(ctx) + if ctx.voice_client is None: + async with ctx.typing(): + embed = self.embed_error_no_vc_dex + await ctx.send(embed=embed) + return + self.current -= (1 if not self.repeat_song else 0) + ctx.voice_client.stop() + return + # ---------------------------------------------------------------------------------------------------------------------- + @commands.command(name="queue", aliases=["view"], help="displays the current queue") async def queue_command(self, ctx, *, url: typing.Optional[str]): @@ -697,7 +728,7 @@ async def volume_command(self, ctx, volume: int): @commands.command(name="stop", aliases=["stfu", "shut"], help="stops the music player and clears the queue") async def stop_command(self, ctx): self.create_guild_queue(ctx) - self.current = -1 + self.current = 0 self.queued = 0 self.vol = 1 self.loop_queue = False @@ -749,22 +780,7 @@ async def next_command(self, ctx): await ctx.send(embed=embed) else: if ctx.voice_client.is_playing() or ctx.voice_client.is_paused(): - # async with ctx.typing(): - # embed = discord.Embed( - # title="Skipping", - # colour=0x00ff00, - # timestamp=datetime.datetime.utcnow() - # ) - # player = self.currently_playing_player - # embed.set_thumbnail(url=self.MUSIC_ICON) - # embed.set_author( - # name=player.title, url=player.url, icon_url=ctx.author.avatar_url) - # embed.add_field( - # name="Title", value=player.title, inline=False) - # embed.add_field(name="Requested by", - # value=ctx.author.mention, inline=False) - # embed.set_footer(text="skip requested by "+ctx.author.name) - # await ctx.send(embed=embed) + self.current += 0 self.repeat_song = False ctx.voice_client.stop() return @@ -779,22 +795,7 @@ async def next_command(self, ctx): await ctx.send(embed=embed) else: if ctx.voice_client.is_playing() or ctx.voice_client.is_paused(): - # async with ctx.typing(): - # embed = discord.Embed( - # title="Skipping", - # colour=0x00ff00, - # timestamp=datetime.datetime.utcnow() - # ) - # player = self.currently_playing_player - # embed.set_thumbnail(url=self.MUSIC_ICON) - # embed.set_author( - # name=player.title, url=player.url, icon_url=ctx.author.avatar_url) - # embed.add_field( - # name="Title", value=player.title, inline=False) - # embed.add_field(name="Requested by", - # value=ctx.author.mention, inline=False) - # embed.set_footer(text="skip requested by "+ctx.author.name) - # await ctx.send(embed=embed) + self.current -= 2 self.repeat_song = False ctx.voice_client.stop() return From 09d19abb4d9ab853b5fd76c2ae2f40445a980f8c Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sat, 25 Jun 2022 21:38:45 +0530 Subject: [PATCH 54/60] sadly, `discord.ui` needs `dpy>=2.0` --- src/cogs/music.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index c4bc7afb..7536efe2 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -5,7 +5,6 @@ import typing import datetime from discord.ext import commands -from discord.ui import Button, Paginator, View # Suppress noise about console usage from errors youtube_dl.utils.bug_reports_message = lambda: '' @@ -198,22 +197,22 @@ async def play_music_from_player(self, ctx, *, player): value=self.current+1, inline=False) embed.add_field(name="Volume", value=str(self.vol * 100) + "%", inline=False) # View - restart_btn = Button() - previous_btn = Button() - play_btn = Button() - pause_btn = Button() - next_btn = Button() - repeat_song_btn = Button() - loop_queue_btn = Button() - view = discord.ui.View() - view.add_item(restart_btn) - view.add_item(previous_btn) - view.add_item(play_btn) - view.add_item(pause_btn) - view.add_item(next_btn) - view.add_item(repeat_song_btn) - view.add_item(loop_queue_btn) - await ctx.send(embed=embed, view=view) + # restart_btn = Button() + # previous_btn = Button() + # play_btn = Button() + # pause_btn = Button() + # next_btn = Button() + # repeat_song_btn = Button() + # loop_queue_btn = Button() + # view = discord.ui.View() + # view.add_item(restart_btn) + # view.add_item(previous_btn) + # view.add_item(play_btn) + # view.add_item(pause_btn) + # view.add_item(next_btn) + # view.add_item(repeat_song_btn) + # view.add_item(loop_queue_btn) + await ctx.send(embed=embed) ctx.voice_client.play(player, after=lambda e: print( f'Player error: {e}') if e else None) ctx.voice_client.source.volume = self.vol From a60664f48628486423ef99420a8ff80d6e03ca8b Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sat, 25 Jun 2022 21:44:52 +0530 Subject: [PATCH 55/60] Update music.py --- src/cogs/music.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index 7536efe2..810f42b7 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -786,7 +786,7 @@ async def next_command(self, ctx): # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="previous", aliases=["prev"], help="plays the previous song in the queue") - async def next_command(self, ctx): + async def previous_command(self, ctx): self.create_guild_queue(ctx) if ctx.voice_client is None: async with ctx.typing(): From 3e485245bfc0b57383935c19b0eed16546af075e Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sat, 25 Jun 2022 21:48:21 +0530 Subject: [PATCH 56/60] Update music.py --- src/cogs/music.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index 810f42b7..a12fce79 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -97,7 +97,7 @@ def __init__(self, bot): self.currently_playing_music = () self.currently_playing_player = None self.music_queue = {} - self.current = 0 + self.current = -1 self.queued = 0 self.vol = 1 self.loop_queue = False @@ -163,7 +163,7 @@ async def leave_command(self, ctx): self.create_guild_queue(ctx) self.music_queue[str(ctx.guild.id)].clear() self.currently_playing_music = None - self.current = 0 + self.current = -1 self.queued = 0 self.vol = 1 self.loop_queue = False @@ -727,7 +727,7 @@ async def volume_command(self, ctx, volume: int): @commands.command(name="stop", aliases=["stfu", "shut"], help="stops the music player and clears the queue") async def stop_command(self, ctx): self.create_guild_queue(ctx) - self.current = 0 + self.current = -1 self.queued = 0 self.vol = 1 self.loop_queue = False From e1b6e5bd1c0b1737cf0c61aebb1e5cc807b747d3 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sat, 25 Jun 2022 22:29:55 +0530 Subject: [PATCH 57/60] Update music.py --- src/cogs/music.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index a12fce79..4466ef44 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -195,7 +195,7 @@ async def play_music_from_player(self, ctx, *, player): embed.add_field(name="Title", value=player.title, inline=False) embed.add_field(name="Position in queue", value=self.current+1, inline=False) - embed.add_field(name="Volume", value=str(self.vol * 100) + "%", inline=False) + embed.add_field(name="Volume", value=str(int(self.vol * 100)) + "%", inline=False) # View # restart_btn = Button() # previous_btn = Button() @@ -779,9 +779,19 @@ async def next_command(self, ctx): await ctx.send(embed=embed) else: if ctx.voice_client.is_playing() or ctx.voice_client.is_paused(): - self.current += 0 - self.repeat_song = False - ctx.voice_client.stop() + if self.current < len(self.music_queue[str(ctx.guild.id)]) - 1 or self.loop_queue: + self.current += 0 + self.repeat_song = False + ctx.voice_client.stop() + else: + async with ctx.typing(): + embed=discord.Embed( + title="Error", + description="Nothing to play after this", + colour=0xff0000, + timestamp=datetime.datetime.utcnow() + ) + await ctx.send(embed=embed) return # ---------------------------------------------------------------------------------------------------------------------- @@ -794,9 +804,19 @@ async def previous_command(self, ctx): await ctx.send(embed=embed) else: if ctx.voice_client.is_playing() or ctx.voice_client.is_paused(): - self.current -= 2 - self.repeat_song = False - ctx.voice_client.stop() + if self.current > 0 or self.loop_queue: + self.current -= 2 + self.repeat_song = False + ctx.voice_client.stop() + else: + async with ctx.typing(): + embed=discord.Embed( + title="Error", + description="Nothing to play before this", + colour=0xff0000, + timestamp=datetime.datetime.utcnow() + ) + await ctx.send(embed=embed) return # ---------------------------------------------------------------------------------------------------------------------- From b16de19db3635f78c1d146d06b08be2dcfc8711e Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sat, 25 Jun 2022 23:49:36 +0530 Subject: [PATCH 58/60] bugfixes --- src/cogs/music.py | 248 +++++++++++++++++++++++++--------------------- 1 file changed, 133 insertions(+), 115 deletions(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index 4466ef44..37d6609a 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -62,9 +62,6 @@ async def from_url(cls, url, *, loop=None, stream=False): class Music(commands.Cog): - # queue format: - # [guild.id] -> [0 player | 1 ctx | 2 url(from_user) | 3 stream_or_not] - bad_request_error_message = '' bad_request_error_message += ( ''.join("Bad response while searching for the music\n\n")) @@ -92,30 +89,39 @@ class Music(commands.Cog): def __init__(self, bot): self.bot = bot - self.is_playing = False - self.MUSIC_ICON = "https://user-images.githubusercontent.com/63065397/156855077-ce6e0896-cc81-4d4d-98b8-3e7b70050afe.png" - self.currently_playing_music = () - self.currently_playing_player = None + # ------------------------------------- + self.properties = {} + # "guild_id": str -> { + # "is_playing": False, + # "currently_playing_player": None, + # "current": -1, + # "queued": 0, + # "vol": 1, + # "loop_queue": False, + # "repeat_song": False + # } + # ------------------------------------- self.music_queue = {} - self.current = -1 - self.queued = 0 - self.vol = 1 - self.loop_queue = False - self.repeat_song = False - # self.destroy() - # ---------------------------------------------------------------------------------------------------------------------- - - # async def destroy(self, bot): - # while(bot.user.voice.channel is not None): - # await asyncio.sleep(1) - # self.__del__() + # [guild.id] -> [0 player | 1 ctx | 2 url(from_user) | 3 stream_or_not] + # ------------------------------------- + return # ---------------------------------------------------------------------------------------------------------------------- - + # async def on_voice_state_update(self): # pass # ---------------------------------------------------------------------------------------------------------------------- - - def create_guild_queue(self,ctx): + + def add_guild(self, ctx): + if str(ctx.guild.id) not in self.properties: + self.properties[str(ctx.guild.id)] = { + "is_playing": False, + "currently_playing_player": None, + "current": -1, + "queued": 0, + "vol": 1, + "loop_queue": False, + "repeat_song": False + } if str(ctx.guild.id) not in self.music_queue.keys(): self.music_queue[str(ctx.guild.id)] = [] return @@ -123,7 +129,7 @@ def create_guild_queue(self,ctx): @commands.command(name="join", aliases=["connect"], help="joins the voice channel of the author") async def join_command(self, ctx): - self.create_guild_queue(ctx) + self.add_guild(ctx) if ctx.author.voice is None: async with ctx.typing(): embed = discord.Embed( @@ -160,15 +166,14 @@ async def join_command(self, ctx): @commands.command(name="leave", aliases=["disconnect, dc"], help="leaves if connected to any voice channel") async def leave_command(self, ctx): - self.create_guild_queue(ctx) + self.add_guild(ctx) self.music_queue[str(ctx.guild.id)].clear() - self.currently_playing_music = None - self.current = -1 - self.queued = 0 - self.vol = 1 - self.loop_queue = False - self.repeat_song = False - self.currently_playing_player = None + self.properties[str(ctx.guild.id)]["current"] = -1 + self.properties[str(ctx.guild.id)]["queued"] = 0 + self.properties[str(ctx.guild.id)]["vol"] = 1 + self.properties[str(ctx.guild.id)]["loop_queue"] = False + self.properties[str(ctx.guild.id)]["repeat_song"] = False + self.properties[str(ctx.guild.id)]["currently_playing_player"] = None if ctx.voice_client is None: embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) @@ -179,23 +184,25 @@ async def leave_command(self, ctx): async def play_music_from_player(self, ctx, *, player): if player is None: return - self.currently_playing_player = player + self.properties[str(ctx.guild.id)]["currently_playing_player"] = player async with ctx.typing(): # Embed embed = discord.Embed( title="Now Playing", description="- requested by " + - self.music_queue[str(ctx.guild.id)][self.current][1].author.mention, + self.music_queue[str(ctx.guild.id) + ][self.properties[str(ctx.guild.id)]["current"]][1].author.mention, colour=0x00ff00, timestamp=datetime.datetime.utcnow() ) embed.set_thumbnail(url=self.MUSIC_ICON) embed.set_author(name=player.title, url=player.url, - icon_url=ctx.author.avatar_url) + icon_url=ctx.author.avatar_url) embed.add_field(name="Title", value=player.title, inline=False) embed.add_field(name="Position in queue", - value=self.current+1, inline=False) - embed.add_field(name="Volume", value=str(int(self.vol * 100)) + "%", inline=False) + value=self.properties[str(ctx.guild.id)]["current"]+1, inline=False) + embed.add_field(name="Volume", value=str( + int(self.properties[str(ctx.guild.id)]["vol"] * 100)) + "%", inline=False) # View # restart_btn = Button() # previous_btn = Button() @@ -215,26 +222,29 @@ async def play_music_from_player(self, ctx, *, player): await ctx.send(embed=embed) ctx.voice_client.play(player, after=lambda e: print( f'Player error: {e}') if e else None) - ctx.voice_client.source.volume = self.vol + ctx.voice_client.source.volume = self.properties[str( + ctx.guild.id)]["vol"] # ---------------------------------------------------------------------------------------------------------------------- async def keep_playing(self, ctx): - while ((len(self.music_queue[str(ctx.guild.id)]) - self.current > 1) or (self.loop_queue is True)) and (len(self.music_queue[str(ctx.guild.id)]) > 0): + while ((len(self.music_queue[str(ctx.guild.id)]) - self.properties[str(ctx.guild.id)]["current"] > 1) or (self.properties[str(ctx.guild.id)]["loop_queue"] is True)) and (len(self.music_queue[str(ctx.guild.id)]) > 0): if ((not ctx.voice_client.is_playing()) and (not ctx.voice_client.is_paused())): - self.is_playing = True - if (not self.repeat_song): - self.current += 1 - self.current %= len(self.music_queue[str(ctx.guild.id)]) - player = await YTDLSource.from_url(self.music_queue[str(ctx.guild.id)][self.current][2], loop=self.bot.loop, stream=self.music_queue[str(ctx.guild.id)][self.current][3]) - self.music_queue[str(ctx.guild.id)][self.current][0] = player - await self.play_music_from_player(self.music_queue[str(ctx.guild.id)][self.current][1], player=player) + self.properties[str(ctx.guild.id)]["is_playing"] = True + if (not self.properties[str(ctx.guild.id)]["repeat_song"]): + self.properties[str(ctx.guild.id)]["current"] += 1 + self.properties[str(ctx.guild.id)]["current"] %= len( + self.music_queue[str(ctx.guild.id)]) + player = await YTDLSource.from_url(self.music_queue[str(ctx.guild.id)][self.properties[str(ctx.guild.id)]["current"]][2], loop=self.bot.loop, stream=self.music_queue[str(ctx.guild.id)][self.properties[str(ctx.guild.id)]["current"]][3]) + self.music_queue[str(ctx.guild.id)][self.properties[str( + ctx.guild.id)]["current"]][0] = player + await self.play_music_from_player(self.music_queue[str(ctx.guild.id)][self.properties[str(ctx.guild.id)]["current"]][1], player=player) await asyncio.sleep(0.5) return # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="play", aliases=["stream", "p", "add"], help="streams a song directly from youtube") async def play_command(self, ctx, *, url: typing.Optional[str]): - self.create_guild_queue(ctx) + self.add_guild(ctx) if (url is None) and (ctx.message.content[(len(ctx.message.content)-3):(len(ctx.message.content))] != "add"): if ctx.voice_client is None: await self.join_command(ctx) @@ -285,7 +295,7 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): await ctx.send(embed=embed) return self.music_queue[str(ctx.guild.id)].append([player, ctx, url, True]) - self.queued += 1 + self.properties[str(ctx.guild.id)]["queued"] += 1 async with ctx.typing(): embed = discord.Embed( title="Added to queue", @@ -306,7 +316,7 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): @commands.command(name="playm", aliases=["streamm", "pm", "addm"], help="plays multiple songs (seperated by semicolons ';')") async def playm_command(self, ctx, *, args): - self.create_guild_queue(ctx) + self.add_guild(ctx) urls = args.split(';') joined = await self.join_command(ctx) if joined == False: @@ -325,8 +335,9 @@ async def playm_command(self, ctx, *, args): ) await ctx.send(embed=embed) continue - self.music_queue[str(ctx.guild.id)].append([player, ctx, url, True]) - self.queued += 1 + self.music_queue[str(ctx.guild.id)].append( + [player, ctx, url, True]) + self.properties[str(ctx.guild.id)]["queued"] += 1 async with ctx.typing(): embed = discord.Embed( title="Added to queue", @@ -347,7 +358,7 @@ async def playm_command(self, ctx, *, args): @commands.command(name='dplay', help="downloads a song and then queues it to reduce any possible lags") async def dplay_command(self, ctx, *, url): - self.create_guild_queue(ctx) + self.add_guild(ctx) joined = await self.join_command(ctx) if joined == False: return @@ -363,7 +374,7 @@ async def dplay_command(self, ctx, *, url): await ctx.send(embed=embed) return self.music_queue[str(ctx.guild.id)].append([player, ctx, url, False]) - self.queued += 1 + self.properties[str(ctx.guild.id)]["queued"] += 1 async with ctx.typing(): embed = discord.Embed( title="Downloaded & Added to queue", @@ -384,12 +395,12 @@ async def dplay_command(self, ctx, *, url): @commands.command(name='dplaym', help="dplays multiple songs (seperated by semicolons ';')") async def dplaym_command(self, ctx, *, args): - self.create_guild_queue(ctx) + self.add_guild(ctx) urls = args.split(';') joined = await self.join_command(ctx) if joined == False: return - last_url=urls.pop() + last_url = urls.pop() for url in urls: url = url.strip() player = await YTDLSource.from_url(url, loop=self.bot.loop) @@ -403,8 +414,9 @@ async def dplaym_command(self, ctx, *, args): ) await ctx.send(embed=embed) continue - self.music_queue[str(ctx.guild.id)].append([player, ctx, url, False]) - self.queued += 1 + self.music_queue[str(ctx.guild.id)].append( + [player, ctx, url, False]) + self.properties[str(ctx.guild.id)]["queued"] += 1 async with ctx.typing(): embed = discord.Embed( title="Downloaded & Added to queue", @@ -426,8 +438,8 @@ async def dplaym_command(self, ctx, *, args): @commands.command(name='loop', help="toggles looping of the queue") async def loop_command(self, ctx, loop_switch: typing.Optional[str]): - self.create_guild_queue(ctx) - + self.add_guild(ctx) + if ctx.voice_client is None: async with ctx.typing(): embed = self.embed_error_no_vc_dex @@ -435,15 +447,16 @@ async def loop_command(self, ctx, loop_switch: typing.Optional[str]): return if loop_switch is None: - self.loop_queue = not self.loop_queue - if self.loop_queue: + self.properties[str(ctx.guild.id)]["loop_queue"] = not self.properties[str( + ctx.guild.id)]["loop_queue"] + if self.properties[str(ctx.guild.id)]["loop_queue"]: loop_switch = "on" else: loop_switch = "off" elif loop_switch.lower() == "on": - self.loop_queue = True + self.properties[str(ctx.guild.id)]["loop_queue"] = True elif loop_switch.lower() == "off": - self.loop_queue = False + self.properties[str(ctx.guild.id)]["loop_queue"] = False else: async with ctx.typing(): embed = discord.Embed( @@ -476,8 +489,8 @@ async def loop_command(self, ctx, loop_switch: typing.Optional[str]): @commands.command(name='repeat', help="toggles repeating of the currently playing song") async def repeat_command(self, ctx, repeat_switch: typing.Optional[str]): - self.create_guild_queue(ctx) - + self.add_guild(ctx) + if ctx.voice_client is None: async with ctx.typing(): embed = self.embed_error_no_vc_dex @@ -485,15 +498,16 @@ async def repeat_command(self, ctx, repeat_switch: typing.Optional[str]): return if repeat_switch is None: - self.repeat_song = not self.repeat_song - if self.repeat_song: + self.properties[str(ctx.guild.id)]["repeat_song"] = not self.properties[str( + ctx.guild.id)]["repeat_song"] + if self.properties[str(ctx.guild.id)]["repeat_song"]: repeat_switch = "on" else: repeat_switch = "off" elif repeat_switch.lower() == "on": - self.repeat_song = True + self.properties[str(ctx.guild.id)]["repeat_song"] = True elif repeat_switch.lower() == "off": - self.repeat_song = False + self.properties[str(ctx.guild.id)]["repeat_song"] = False else: async with ctx.typing(): embed = discord.Embed( @@ -525,25 +539,23 @@ async def repeat_command(self, ctx, repeat_switch: typing.Optional[str]): @commands.command(name='restart', help="restarts the currently playing song") async def restart_command(self, ctx): - self.create_guild_queue(ctx) + self.add_guild(ctx) if ctx.voice_client is None: async with ctx.typing(): embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) return - self.current -= (1 if not self.repeat_song else 0) + self.properties[str(ctx.guild.id)]["current"] -= ( + 1 if not self.properties[str(ctx.guild.id)]["repeat_song"] else 0) ctx.voice_client.stop() return # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="queue", aliases=["view"], help="displays the current queue") async def queue_command(self, ctx, *, url: typing.Optional[str]): - - if str(ctx.guild.id) in self.music_queue: # for debugging purposes - print(self.music_queue[str(ctx.guild.id)]) - - self.create_guild_queue(ctx) - + + self.add_guild(ctx) + if url is not None: if url != "": await self.play_command(ctx, url=url) @@ -577,17 +589,21 @@ async def queue_command(self, ctx, *, url: typing.Optional[str]): for i in range(0, size, 25): embed = discord.Embed( title="Queue", - description=str("Page " + str(i // 25 + 1) + " of " + str(size // 25 + 1)), + description=str("Page " + str(i // 25 + 1) + + " of " + str(size // 25 + 1)), colour=0x0000ff, timestamp=datetime.datetime.utcnow() ) embed.set_thumbnail(url=self.MUSIC_ICON) embed.set_author(name="Dex", icon_url=self.bot.user.avatar_url) for j in range(i, min(size, i + 25)): - k = "**" if j == self.current else "" + k = "**" if j == self.properties[str( + ctx.guild.id)]["current"] else "" embed.add_field( - name=str(j + 1) + (" ***(Currently Playing)***" if j == self.current else ""), - value=k+str(self.music_queue[str(ctx.guild.id)][j][0].title)+k, + name=str( + j + 1) + (" ***(Currently Playing)***" if j == self.properties[str(ctx.guild.id)]["current"] else ""), + value=k + + str(self.music_queue[str(ctx.guild.id)][j][0].title)+k, inline=False ) async with ctx.typing(): @@ -598,7 +614,7 @@ async def queue_command(self, ctx, *, url: typing.Optional[str]): @commands.command(name="remove", help="removes a song from the queue, takes song position as argument") async def remove_command(self, ctx, pos): - self.create_guild_queue(ctx) + self.add_guild(ctx) if ctx.voice_client is None: async with ctx.typing(): embed = self.embed_error_no_vc_dex @@ -631,7 +647,8 @@ async def remove_command(self, ctx, pos): embed = discord.Embed( title="Removed from queue", description="track requested by " + - self.music_queue[str(ctx.guild.id)][int(pos)][1].author.mention, + self.music_queue[str(ctx.guild.id)][int(pos) + ][1].author.mention, colour=0x00ff00, timestamp=datetime.datetime.utcnow() ) @@ -643,18 +660,18 @@ async def remove_command(self, ctx, pos): embed.add_field(name="Remove request by", value=ctx.author.mention, inline=True) self.music_queue[str(ctx.guild.id)].pop(int(pos)) - if self.current > pos: - self.current -= 1 - elif self.current == pos: - self.repeat_song = False - self.current -= 1 + if self.properties[str(ctx.guild.id)]["current"] > pos: + self.properties[str(ctx.guild.id)]["current"] -= 1 + elif self.properties[str(ctx.guild.id)]["current"] == pos: + self.properties[str(ctx.guild.id)]["repeat_song"] = False + self.properties[str(ctx.guild.id)]["current"] -= 1 ctx.voice_client.stop() await ctx.send(embed=embed) # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="jump", alises=["jumpto"], help="jumps to a song in the queue, takes song position as argument") async def jump_command(self, ctx, pos): - self.create_guild_queue(ctx) + self.add_guild(ctx) pos = int(pos) if ctx.voice_client is None: async with ctx.typing(): @@ -697,22 +714,23 @@ async def jump_command(self, ctx, pos): icon_url=ctx.author.avatar_url) embed.add_field(name="Title", value=player.title, inline=False) embed.add_field( - name="Queue Looping", value="On" if self.loop_queue else "Off", inline=True) + name="Queue Looping", value="On" if self.properties[str(ctx.guild.id)]["loop_queue"] else "Off", inline=True) await ctx.send(embed=embed) - self.repeat_song = False - self.current = pos - 1 + self.properties[str(ctx.guild.id)]["repeat_song"] = False + self.properties[str(ctx.guild.id)]["current"] = pos - 1 ctx.voice_client.stop() # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="volume", aliases=["vol"], help="changes the volume of the music player") async def volume_command(self, ctx, volume: int): + self.add_guild(ctx) if ctx.voice_client is None: async with ctx.typing(): embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) return ctx.voice_client.source.volume = volume / 100 - self.vol = volume / 100 + self.properties[str(ctx.guild.id)]["vol"] = volume / 100 async with ctx.typing(): embed = discord.Embed( title=str(volume) + "%", @@ -726,14 +744,13 @@ async def volume_command(self, ctx, volume: int): @commands.command(name="stop", aliases=["stfu", "shut"], help="stops the music player and clears the queue") async def stop_command(self, ctx): - self.create_guild_queue(ctx) - self.current = -1 - self.queued = 0 - self.vol = 1 - self.loop_queue = False - self.repeat_song = False - self.currently_playing_music = None - self.currently_playing_player = None + self.add_guild(ctx) + self.properties[str(ctx.guild.id)]["current"] = -1 + self.properties[str(ctx.guild.id)]["queued"] = 0 + self.properties[str(ctx.guild.id)]["vol"] = 1 + self.properties[str(ctx.guild.id)]["loop_queue"] = False + self.properties[str(ctx.guild.id)]["repeat_song"] = False + self.properties[str(ctx.guild.id)]["currently_playing_player"] = None if ctx.voice_client is None: async with ctx.typing(): embed = self.embed_error_no_vc_dex @@ -747,7 +764,7 @@ async def stop_command(self, ctx): @commands.command(name="pause", help="pauses the music player") async def pause_command(self, ctx): - self.create_guild_queue(ctx) + self.add_guild(ctx) if ctx.voice_client is None: embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) @@ -758,7 +775,7 @@ async def pause_command(self, ctx): @commands.command(name="resume", help="resumes the music player") async def resume_command(self, ctx): - self.create_guild_queue(ctx) + self.add_guild(ctx) if ctx.voice_client is None: embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) @@ -772,20 +789,20 @@ async def resume_command(self, ctx): @commands.command(name="next", aliases=["skip"], help="plays the next song in the queue") async def next_command(self, ctx): - self.create_guild_queue(ctx) + self.add_guild(ctx) if ctx.voice_client is None: async with ctx.typing(): embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) else: if ctx.voice_client.is_playing() or ctx.voice_client.is_paused(): - if self.current < len(self.music_queue[str(ctx.guild.id)]) - 1 or self.loop_queue: - self.current += 0 - self.repeat_song = False + if self.properties[str(ctx.guild.id)]["current"] < len(self.music_queue[str(ctx.guild.id)]) - 1 or self.properties[str(ctx.guild.id)]["loop_queue"]: + self.properties[str(ctx.guild.id)]["current"] += 0 + self.properties[str(ctx.guild.id)]["repeat_song"] = False ctx.voice_client.stop() else: async with ctx.typing(): - embed=discord.Embed( + embed = discord.Embed( title="Error", description="Nothing to play after this", colour=0xff0000, @@ -797,20 +814,20 @@ async def next_command(self, ctx): @commands.command(name="previous", aliases=["prev"], help="plays the previous song in the queue") async def previous_command(self, ctx): - self.create_guild_queue(ctx) + self.add_guild(ctx) if ctx.voice_client is None: async with ctx.typing(): embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) else: if ctx.voice_client.is_playing() or ctx.voice_client.is_paused(): - if self.current > 0 or self.loop_queue: - self.current -= 2 - self.repeat_song = False + if self.properties[str(ctx.guild.id)]["current"] > 0 or self.properties[str(ctx.guild.id)]["loop_queue"]: + self.properties[str(ctx.guild.id)]["current"] -= 2 + self.properties[str(ctx.guild.id)]["repeat_song"] = False ctx.voice_client.stop() else: async with ctx.typing(): - embed=discord.Embed( + embed = discord.Embed( title="Error", description="Nothing to play before this", colour=0xff0000, @@ -830,14 +847,14 @@ async def get_lyrics(self, song_title): @commands.command(name='lyrics', help='sends the lyrics of the song') async def lyrics_command(self, ctx, *args) -> None: - self.create_guild_queue(ctx) + self.add_guild(ctx) song_title = '' for arg in args: song_title += arg+'%20' if len(song_title) > 0: song_title = song_title[:-3] else: - if self.currently_playing_player is None: + if self.properties[str(ctx.guild.id)]["currently_playing_player"] is None: async with ctx.typing(): embed = discord.Embed( title="Error", @@ -847,7 +864,8 @@ async def lyrics_command(self, ctx, *args) -> None: ) await ctx.send(embed=embed) return - args = self.currently_playing_player.title.split() + args = self.properties[str( + ctx.guild.id)]["currently_playing_player"].title.split() for arg in args: song_title += arg+'%20' song_title = song_title[:-3] From 340050f616e3f40a2e762b7a65105ec71b42c7cd Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sun, 26 Jun 2022 00:13:40 +0530 Subject: [PATCH 59/60] Update music.py --- src/cogs/music.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index 37d6609a..b13c7a39 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -98,7 +98,8 @@ def __init__(self, bot): # "queued": 0, # "vol": 1, # "loop_queue": False, - # "repeat_song": False + # "repeat_song": False, + # "inside_keep_playing": False # } # ------------------------------------- self.music_queue = {} @@ -120,7 +121,8 @@ def add_guild(self, ctx): "queued": 0, "vol": 1, "loop_queue": False, - "repeat_song": False + "repeat_song": False, + "inside_keep_playing": False } if str(ctx.guild.id) not in self.music_queue.keys(): self.music_queue[str(ctx.guild.id)] = [] @@ -174,6 +176,8 @@ async def leave_command(self, ctx): self.properties[str(ctx.guild.id)]["loop_queue"] = False self.properties[str(ctx.guild.id)]["repeat_song"] = False self.properties[str(ctx.guild.id)]["currently_playing_player"] = None + self.properties[str(ctx.guild.id)]["is_playing"] = False + self.properties[str(ctx.guild.id)]["inside_keep_playing"] = False if ctx.voice_client is None: embed = self.embed_error_no_vc_dex await ctx.send(embed=embed) @@ -227,6 +231,7 @@ async def play_music_from_player(self, ctx, *, player): # ---------------------------------------------------------------------------------------------------------------------- async def keep_playing(self, ctx): + self.properties[str(ctx.guild.id)]["inside_keep_playing"] = True while ((len(self.music_queue[str(ctx.guild.id)]) - self.properties[str(ctx.guild.id)]["current"] > 1) or (self.properties[str(ctx.guild.id)]["loop_queue"] is True)) and (len(self.music_queue[str(ctx.guild.id)]) > 0): if ((not ctx.voice_client.is_playing()) and (not ctx.voice_client.is_paused())): self.properties[str(ctx.guild.id)]["is_playing"] = True @@ -239,6 +244,7 @@ async def keep_playing(self, ctx): ctx.guild.id)]["current"]][0] = player await self.play_music_from_player(self.music_queue[str(ctx.guild.id)][self.properties[str(ctx.guild.id)]["current"]][1], player=player) await asyncio.sleep(0.5) + self.properties[str(ctx.guild.id)]["inside_keep_playing"] = False return # ---------------------------------------------------------------------------------------------------------------------- @@ -256,7 +262,8 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): ctx.voice_client.resume() elif len(self.music_queue[str(ctx.guild.id)]) > 0: if not ctx.voice_client.is_playing(): - await self.keep_playing(ctx) + if not self.properties[str(ctx.guild.id)]["inside_keep_playing"]: + await self.keep_playing(ctx) else: embed = discord.Embed( title="Error", @@ -310,7 +317,8 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): embed.add_field(name="Queue Position", value=len( self.music_queue[str(ctx.guild.id)]), inline=True) await ctx.send(embed=embed) - await self.keep_playing(ctx) + if not self.properties[str(ctx.guild.id)]["inside_keep_playing"]: + await self.keep_playing(ctx) return # ---------------------------------------------------------------------------------------------------------------------- @@ -389,7 +397,8 @@ async def dplay_command(self, ctx, *, url): embed.add_field(name="Queue Position", value=len( self.music_queue[str(ctx.guild.id)]), inline=True) await ctx.send(embed=embed) - await self.keep_playing(ctx) + if not self.properties[str(ctx.guild.id)]["inside_keep_playing"]: + await self.keep_playing(ctx) return # ---------------------------------------------------------------------------------------------------------------------- @@ -781,8 +790,8 @@ async def resume_command(self, ctx): await ctx.send(embed=embed) elif ctx.voice_client.is_paused(): ctx.voice_client.resume() - elif len(self.music_queue[str(ctx.guild.id)]) > 0: - if not ctx.voice_client.is_playing(): + elif not ctx.voice_client.is_playing(): + if not self.properties[str(ctx.guild.id)]["inside_keep_playing"]: await self.keep_playing(ctx) return # ---------------------------------------------------------------------------------------------------------------------- From bea8d00a0971975a36ae6ac911d8e83d0f2121c0 Mon Sep 17 00:00:00 2001 From: Yashvardhan Baid Date: Sun, 26 Jun 2022 01:03:12 +0530 Subject: [PATCH 60/60] Update music.py --- src/cogs/music.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cogs/music.py b/src/cogs/music.py index b13c7a39..8ec1a7ae 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -91,7 +91,8 @@ def __init__(self, bot): self.bot = bot # ------------------------------------- self.properties = {} - # "guild_id": str -> { + # FORMAT OF DICT self.properties: + # [str(guild.id)] -> { # "is_playing": False, # "currently_playing_player": None, # "current": -1, @@ -103,7 +104,8 @@ def __init__(self, bot): # } # ------------------------------------- self.music_queue = {} - # [guild.id] -> [0 player | 1 ctx | 2 url(from_user) | 3 stream_or_not] + # FORMAT OF DICT self.music_queue: + # [str(guild.id)] -> [0 player | 1 ctx | 2 url(from_user) | 3 stream_or_not] # ------------------------------------- return # ----------------------------------------------------------------------------------------------------------------------