diff --git a/requirements.txt b/requirements.txt index e52984b2..8a0c1fa3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,6 +7,4 @@ requests==2.27.1 aiohttp==3.7.4 typing==3.7.4.3 async-timeout==3.0.1 -psycopg2==2.9.3 -config==0.5.1 -configparser==5.2.0 \ No newline at end of file +asyncpg==0.25.0 diff --git a/src/bot.py b/src/bot.py index b4cfe53d..c7dd5da6 100644 --- a/src/bot.py +++ b/src/bot.py @@ -1,7 +1,7 @@ import discord import os -import datetime -import psycopg2 +import asyncpg +from datetime import datetime from discord.ext import commands @@ -12,57 +12,69 @@ 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, + command_prefix=self.get_pref, intents=discord.Intents.all(), activity=discord.Activity( type=discord.ActivityType.listening, name="$dex help", large_image_url=self.EXHAUSTED_FACE, small_image_url=self.EXHAUSTED_FACE, - start=datetime.datetime(2022, 2, 24), + start=datetime(2022, 2, 24), ), ) + self.DB_CONNECTION = None + self.DATABASE = {} + self.loop.create_task(self.startup()) for file in os.listdir('./src/cogs'): if file.endswith('.py'): self.load_extension(f'src.cogs.{file[:-3]}') - def connect_to_db(self) -> None: - self.DB_CONNECTION = psycopg2.connect( + async def connect_to_db(self) -> None: + self.DB_CONNECTION = await asyncpg.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'), + password=os.getenv('DEX_DB_PASSWORD') ) + print("\nDATABASE CONNECTED\n") - async def get_prefix(self, message): - cur = self.DB_CONNECTION.cursor() - cur.execute('SELECT prefix FROM guilds WHERE guild_id = \'' + - str(message.guild.id) + '\';') - prefix = cur.fetchone() - return prefix + async def clone_database(self): + await self.DB_CONNECTION.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.DATABASE['guilds'] = {} + self.DATABASE['guilds'] = {result['guild_id']: {k: v for k, v in result.items() if k != 'guild_id'} for result in await self.DB_CONNECTION.fetch("SELECT * FROM guilds")} + print("\nDATABASE CLONED\n") + print("\n\n****DATABASE DICTIONARY****\n\n") + print(self.DATABASE) + print("\n\n") + return + + async def startup(self): + print("\nINSIDE Bot.startup()\n") + await self.connect_to_db() + await self.clone_database() + + def get_pref(self, _, message): + return self.DATABASE['guilds'][str(message.guild.id)]['prefix'] def run(self) -> None: super().run(os.getenv('DEX_BOT_TOKEN')) async def on_ready(self): print('Logged in as {0.user}'.format(self)) - cur = self.DB_CONNECTION.cursor() - 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 (\'' + - str(guild.id)+'\', \'$dex \', \'on\');') - self.DB_CONNECTION.commit() - cur.close() + + async def on_guild_join(self, guild): + if str(guild.id) in self.DATABASE['guilds'].keys(): + return + await self.DB_CONNECTION.execute('INSERT INTO guilds (guild_id,prefix,tag_messages) VALUES (\'' + + str(guild.id)+'\', \'$dex \', \'on\');') + self.DATABASE['guilds'][str(guild.id)] = {} + self.DATABASE['guilds'][str(guild.id)] = { + 'prefix': '$dex ', 'tag_messages': 'on'} for channel in guild.text_channels: if channel.permissions_for(guild.me).send_messages: general = channel @@ -70,32 +82,28 @@ async def on_guild_join(self, guild) -> None: await general.send(embed=self.intro_msg_embed(guild)) return - async def on_guild_remove(self, guild) -> None: - cur = self.DB_CONNECTION.cursor() - cur.execute('DELETE FROM guilds WHERE guild_id = \'' + - str(guild.id) + '\';') - self.DB_CONNECTION.commit() - cur.close() + async def on_guild_remove(self, guild): + await self.DB_CONNECTION.execute('DELETE FROM guilds WHERE guild_id = \'' + + str(guild.id) + '\';') + if str(guild.id) in self.DATABASE['guilds'].keys(): + self.DATABASE['guilds'].pop(str(guild.id)) return - async def on_message(self, message) -> None: + async def on_message(self, message): await self.process_commands(message) - cur = self.DB_CONNECTION.cursor() - cur.execute('SELECT tag_messages FROM guilds WHERE guild_id = \'' + - str(message.guild.id) + '\';') - tag_switch = cur.fetchone() - cur.close() + tag_switch = self.DATABASE['guilds'][str( + message.guild.id)]['tag_messages'] target = message.author if target == self.user: return print("\n\n-----------------------\n-----------------------\n\n" + str(message.content) + "\n-----------------------\n") - if tag_switch[0] == 'off': + if tag_switch == 'off': return embed = discord.Embed( title='Message Tagged', colour=target.colour, - timestamp=datetime.datetime.utcnow(), + timestamp=datetime.utcnow(), ) embed.set_footer( text=''.join('` tags off` -to turn this off'), @@ -109,7 +117,7 @@ async def on_command_error(self, ctx, error) -> None: embed = discord.Embed( title='Status', colour=0xff0000, - timestamp=datetime.datetime.utcnow(), + timestamp=datetime.utcnow(), ) if isinstance(error, commands.MissingPermissions): n = 'Error' @@ -141,7 +149,7 @@ def intro_msg_embed(self, guild): title='**GREETINGS!**', description=description, color=self.DEX_YELLOW, - timestamp=datetime.datetime.utcnow(), + timestamp=datetime.utcnow(), ) embed.set_image(url=self.INTRO_IMG_URL) embed.set_author( diff --git a/src/cogs/fun.py b/src/cogs/fun.py index 32b4af06..d05a0940 100644 --- a/src/cogs/fun.py +++ b/src/cogs/fun.py @@ -1,8 +1,8 @@ import discord import aiohttp import os -import datetime -import typing +from typing import Optional +from datetime import datetime from discord.ext import commands @@ -22,7 +22,7 @@ async def get_iquote(self): async def inspire_command(self, ctx): embed = discord.Embed(title="Inspirational Quote", colour=ctx.author.colour, - timestamp=datetime.datetime.utcnow()) + timestamp=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) @@ -42,7 +42,7 @@ async def apod_command(self, ctx): embed = discord.Embed(title="NASA", description="Picture of the day", colour=0x0B3D91, - timestamp=datetime.datetime.utcnow()) + timestamp=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]") @@ -65,7 +65,7 @@ async def get_meme(self): async def meme_command(self, ctx): embed = discord.Embed(title="MEME", colour=0xffee00, - timestamp=datetime.datetime.utcnow()) + timestamp=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) @@ -84,14 +84,14 @@ async def get_subreddit(self, subreddit): return (data_json) @commands.command(name="reddit", aliases=["subreddit"], help="shows top headlines of the given subreddit") - async def subreddit_command(self, ctx, subreddit, number: typing.Optional[int]): + async def subreddit_command(self, ctx, subreddit, number: 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() + timestamp=datetime.utcnow() ) embed.add_field(name="Error", value="Not Found", inline=True) embed.set_footer(text="given subreddit: "+subreddit) @@ -101,7 +101,7 @@ async def subreddit_command(self, ctx, subreddit, number: typing.Optional[int]): title="Error", description="API Request Fail", colour=0xff0000, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) for key_i in data.keys(): if key_i != 'message' and key_i != 'error': @@ -117,7 +117,7 @@ async def subreddit_command(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.utcnow()) embed.set_thumbnail( url="https://user-images.githubusercontent.com/63065397/156344382-821872f3-b6e3-46e7-b925-b5f1a0821da8.png") i = 1 diff --git a/src/cogs/info.py b/src/cogs/info.py index 7dfa1249..dde88e7e 100644 --- a/src/cogs/info.py +++ b/src/cogs/info.py @@ -1,19 +1,17 @@ +import discord from typing import Optional from datetime import datetime -from discord import Embed, Member, Guild -from discord.ext.commands import Cog -from discord.ext.commands import command from discord.ext import commands -class Info(Cog): +class Info(commands.Cog): def __init__(self, bot): self.bot = bot - @command(name="userinfo", aliases=["ui", "memberinfo", "mi"], help="shows user info") - async def userinfo_command(self, ctx, target: Optional[Member]): + @commands.command(name="userinfo", aliases=["ui", "memberinfo", "mi"], help="shows user info") + async def userinfo_command(self, ctx, target: Optional[discord.Member]): target = target or ctx.author - embed = Embed(title="User Information", + embed = discord.Embed(title="User Information", colour=target.colour, timestamp=datetime.utcnow()) embed.set_thumbnail(url=target.avatar_url) @@ -35,8 +33,8 @@ async def userinfo_command(self, ctx, target: Optional[Member]): embed.add_field(name=n, value=v, inline=i) await ctx.send(embed=embed) - @command(name="serverinfo", aliases=["si", "guildinfo", "gi"], help="shows server information") - async def serverinfo_command(self, ctx, target: Optional[Guild]): + @commands.command(name="serverinfo", aliases=["si", "guildinfo", "gi"], help="shows server information") + async def serverinfo_command(self, ctx, target: Optional[discord.Guild]): flag = True if(target): flag = False @@ -44,7 +42,7 @@ async def serverinfo_command(self, ctx, target: Optional[Guild]): if g.id == target.id: flag = True target = target or ctx.guild - embed = Embed(title="Server Information", + embed = discord.Embed(title="Server Information", colour=ctx.guild.owner.colour, timestamp=datetime.utcnow()) if flag == False: diff --git a/src/cogs/modset.py b/src/cogs/modset.py index ccad9a39..703eb4ec 100644 --- a/src/cogs/modset.py +++ b/src/cogs/modset.py @@ -1,35 +1,30 @@ import discord -from typing import Optional -import datetime -from discord.ext.commands import Cog -from discord.ext.commands import command import os +from typing import Optional +from datetime import datetime +from discord.ext import commands -class ModSet(Cog): +class ModSet(commands.Cog): def __init__(self, bot): self.bot = bot - @command(name="modset", aliases=["mset", "modsettings"]) + @commands.command(name="modset", aliases=["mset", "modsettings"]) async def modset(self, ctx, target: Optional[discord.Member]): pass - @command(name="tags", aliases=["tagging", "msgtag"], help="toggles message tags") + @commands.command(name="tags", aliases=["tagging", "msgtag"], help="toggles message tags") async def tags_command(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) + '\';') - tag_messages = cur.fetchone() - cur.close() - tag_switch = tag_messages[0] + tag_switch = self.bot.DATABASE['guilds'][str( + ctx.guild.id)]['tag_messages'] if switch is None: if tag_switch == "off": tag_switch = "on" else: tag_switch = "off" - elif switch.lower() == "off" or switch == "0": + elif switch == "0" or switch.lower() == "off": tag_switch = "off" - elif switch.lower() == "on" or switch == "1": + elif switch == "1" or switch.lower() == "on": tag_switch = "on" else: @@ -37,7 +32,7 @@ async def tags_command(self, ctx, switch: Optional[str]): embed = discord.Embed( title="Status", colour=0xff0000, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) embed.add_field( name="Error", @@ -47,16 +42,15 @@ async def tags_command(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() + await self.bot.DB_CONNECTION.execute('UPDATE guilds SET tag_messages = \'' + tag_switch + + '\' WHERE guild_id = \'' + str(ctx.guild.id) + '\';') + self.bot.DATABASE['guilds'][str( + ctx.guild.id)]['tag_messages'] = tag_switch async with ctx.typing(): embed = discord.Embed( title="Status", colour=0x00ff00, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) embed.add_field( name="Done", @@ -65,52 +59,123 @@ async def tags_command(self, ctx, switch: Optional[str]): ) await ctx.send(embed=embed) - @command(name="changepref", aliases=["changeprefix"], help="changes the prefix to the appended string") + @commands.command(name="changepref", aliases=["changeprefix"], help="changes the prefix to the appended string") async def changeprefix_command(self, ctx, *args): prefix = "".join(args) if ctx.guild.id == int(os.environ['DEX_PUBLIC_BOT_SERVER']): embed = discord.Embed(title="Status", + description="Permission Denied", colour=0xff0000, - timestamp=datetime.datetime.utcnow()) + 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 = discord.Embed(title="Status", + description="Permission Denied", colour=0xff0000, - timestamp=datetime.datetime.utcnow()) + timestamp=datetime.utcnow()) embed.add_field( name="Error", value="Only server owner can change the prefix!", inline=True) 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)+"\';") - self.bot.DB_CONNECTION.commit() - cur.close() + await self.bot.DB_CONNECTION.execute("UPDATE guilds SET prefix = \'"+prefix + + "\' WHERE guild_id = \'"+str(ctx.guild.id)+"\';") + self.bot.DATABASE['guilds'][str( + ctx.guild.id)]['prefix'] = prefix embed = discord.Embed(title="Status", colour=0x00ff00, - timestamp=datetime.datetime.utcnow()) + timestamp=datetime.utcnow()) embed.add_field( - name="Done", value="New Prefix is " + prefix, inline=True) + name="Done", value="New Prefix is `" + prefix + "`", inline=True) await ctx.send(embed=embed) else: embed = discord.Embed(title="Status", colour=0xff0000, - timestamp=datetime.datetime.utcnow()) + timestamp=datetime.utcnow()) embed.add_field( 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)") + @commands.command(name="prefixspace", aliases=["prefspace"], help="toggles the trailing space in the prefix") + async def prefixspace_command(self, ctx, switch: Optional[str]): + if ctx.guild.id == int(os.environ['DEX_PUBLIC_BOT_SERVER']): + embed = discord.Embed(title="Status", + description="Permission Denied", + 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) + return + if ctx.author != ctx.guild.owner: + embed = discord.Embed(title="Status", + description="Permission Denied", + 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) + return + prefix_space_switch = 'on' if self.bot.DATABASE['guilds'][str( + ctx.guild.id)]['prefix'][-1] == ' ' else 'off' + if switch is None: + if prefix_space_switch == 'on': + prefix_space_switch = 'off' + else: + prefix_space_switch = 'on' + elif switch == "0" or switch.lower() == "off": + prefix_space_switch = "off" + elif switch == "1" or switch.lower() == "on": + prefix_space_switch = "on" + 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 + + prefix = self.bot.DATABASE['guilds'][str(ctx.guild.id)]['prefix'] = self.bot.DATABASE['guilds'][str( + ctx.guild.id)]['prefix'].strip() + (' ' if prefix_space_switch == 'on' else '') + await self.bot.DB_CONNECTION.execute("UPDATE guilds SET prefix = \'" + prefix + + "\' WHERE guild_id = \'" + str(ctx.guild.id) + "\';") + + async with ctx.typing(): + embed = discord.Embed( + title="Status", + colour=0x00ff00, + timestamp=datetime.utcnow() + ) + embed.add_field( + name="Done", + value="Prefix Space is now " + prefix_space_switch, + inline=False + ) + embed.add_field( + name="Prefix", + value="`" + prefix + "`", + inline=False + ) + await ctx.send(embed=embed) + + @commands.command(name="goodbye!", aliases=["leaveThisServer"], help="makes the bot to leave the server (only for server owner)") async def goodbye_command(self, ctx): if ctx.author != ctx.guild.owner: embed = discord.Embed(title="Status", + description="Permission Denied", colour=0xff0000, - timestamp=datetime.datetime.utcnow()) + timestamp=datetime.utcnow()) embed.add_field( name="Error", value="Only server owner can use this command!", inline=True) await ctx.send(embed=embed) @@ -120,7 +185,7 @@ async def goodbye_command(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.datetime.utcnow()) + """, color=0x8e38ce, timestamp=datetime.utcnow()) embed.set_image( url="https://user-images.githubusercontent.com/63065397/156924332-3638cd0d-9cf9-4e08-b4de-6f20cedd921a.png") embed.set_author( @@ -131,21 +196,16 @@ async def goodbye_command(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)+"\';") - self.bot.DB_CONNECTION.commit() - cur.close() return - @command(name="madeby?", help="shows the creator of the bot") + @commands.command(name="madeby?", help="shows the creator of the bot") async def madeby_command(self, ctx): async with ctx.typing(): embed = discord.Embed(title="Made by", description=""" **codechaser#0647** **[GitHub](https://github.com/code-chaser)** """, - color=0x8e38ce, timestamp=datetime.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) diff --git a/src/cogs/music.py b/src/cogs/music.py index 8ec1a7ae..45de94a6 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -2,8 +2,8 @@ import aiohttp import youtube_dl import asyncio -import typing -import datetime +from typing import Optional +from datetime import datetime from discord.ext import commands # Suppress noise about console usage from errors @@ -81,7 +81,7 @@ class Music(commands.Cog): 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() + timestamp=datetime.utcnow() ) MUSIC_ICON = "https://user-images.githubusercontent.com/63065397/156855077-ce6e0896-cc81-4d4d-98b8-3e7b70050afe.png" @@ -140,7 +140,7 @@ async def join_command(self, ctx): title="Error", description=ctx.author.mention + ", you are not connected to a voice channel", colour=0xFF0000, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) embed.set_footer(text="join request from " + ctx.author.name) await ctx.send(embed=embed) @@ -157,7 +157,7 @@ async def join_command(self, ctx): 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() + timestamp=datetime.utcnow() ) embed.set_footer( text="join request from " + ctx.author.name) @@ -199,7 +199,7 @@ async def play_music_from_player(self, ctx, *, player): self.music_queue[str(ctx.guild.id) ][self.properties[str(ctx.guild.id)]["current"]][1].author.mention, colour=0x00ff00, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) embed.set_thumbnail(url=self.MUSIC_ICON) embed.set_author(name=player.title, url=player.url, @@ -251,7 +251,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]): + async def play_command(self, ctx, *, url: Optional[str]): 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: @@ -272,7 +272,7 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): description=''.join( "Queue is empty, nothing to play\nUse ` play ` to add to queue"), colour=0xff0000, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) await ctx.send(embed=embed) return @@ -281,7 +281,7 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): embed = discord.Embed( title="Status", colour=0xff0000, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) n = "Error" v = "Missing required arguements" @@ -299,7 +299,7 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): title="Error", description=''.join(self.bad_request_error_message), colour=0xff0000, - timestamp=datetime.datetime.utcnow(), + timestamp=datetime.utcnow(), ) await ctx.send(embed=embed) return @@ -310,7 +310,7 @@ async def play_command(self, ctx, *, url: typing.Optional[str]): title="Added to queue", description="\"" + url + "\" requested by " + ctx.author.mention, colour=0x00ff00, - timestamp=datetime.datetime.utcnow(), + timestamp=datetime.utcnow(), ) embed.set_thumbnail(url=self.MUSIC_ICON) embed.set_author(name=player.title, url=player.url, @@ -341,7 +341,7 @@ async def playm_command(self, ctx, *, args): title="Error", description=''.join(self.bad_request_error_message), colour=0xff0000, - timestamp=datetime.datetime.utcnow(), + timestamp=datetime.utcnow(), ) await ctx.send(embed=embed) continue @@ -353,7 +353,7 @@ async def playm_command(self, ctx, *, args): title="Added to queue", description="\"" + url + "\" requested by " + ctx.author.mention, colour=0x00ff00, - timestamp=datetime.datetime.utcnow(), + timestamp=datetime.utcnow(), ) embed.set_thumbnail(url=self.MUSIC_ICON) embed.set_author(name=player.title, url=player.url, @@ -379,7 +379,7 @@ async def dplay_command(self, ctx, *, url): title="Error", description=''.join(self.bad_request_error_message), colour=0xff0000, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) await ctx.send(embed=embed) return @@ -390,7 +390,7 @@ async def dplay_command(self, ctx, *, url): title="Downloaded & Added to queue", description="\"" + url + "\" requested by " + ctx.author.mention, colour=0x00ff00, - timestamp=datetime.datetime.utcnow(), + timestamp=datetime.utcnow(), ) embed.set_thumbnail(url=self.MUSIC_ICON) embed.set_author(name=player.title, url=player.url, @@ -421,7 +421,7 @@ async def dplaym_command(self, ctx, *, args): title="Error", description=''.join(self.bad_request_error_message), colour=0xff0000, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) await ctx.send(embed=embed) continue @@ -433,7 +433,7 @@ async def dplaym_command(self, ctx, *, args): title="Downloaded & Added to queue", description="\"" + url + "\" requested by " + ctx.author.mention, colour=0x00ff00, - timestamp=datetime.datetime.utcnow(), + timestamp=datetime.utcnow(), ) embed.set_thumbnail(url=self.MUSIC_ICON) embed.set_author(name=player.title, url=player.url, @@ -447,7 +447,7 @@ 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]): + async def loop_command(self, ctx, loop_switch: Optional[str]): self.add_guild(ctx) @@ -473,7 +473,7 @@ async def loop_command(self, ctx, loop_switch: typing.Optional[str]): embed = discord.Embed( title="Status", colour=0xff0000, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) embed.add_field( name="Error", @@ -486,7 +486,7 @@ async def loop_command(self, ctx, loop_switch: typing.Optional[str]): embed = discord.Embed( title="Status", colour=0x00ff00, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) embed.add_field( name="Done", @@ -498,7 +498,7 @@ 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]): + async def repeat_command(self, ctx, repeat_switch: Optional[str]): self.add_guild(ctx) @@ -524,7 +524,7 @@ async def repeat_command(self, ctx, repeat_switch: typing.Optional[str]): embed = discord.Embed( title="Status", colour=0xff0000, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) embed.add_field( name="Error", @@ -537,7 +537,7 @@ async def repeat_command(self, ctx, repeat_switch: typing.Optional[str]): embed = discord.Embed( title="Status", colour=0x00ff00, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) embed.add_field( name="Done", @@ -563,7 +563,7 @@ async def restart_command(self, ctx): # ---------------------------------------------------------------------------------------------------------------------- @commands.command(name="queue", aliases=["view"], help="displays the current queue") - async def queue_command(self, ctx, *, url: typing.Optional[str]): + async def queue_command(self, ctx, *, url: Optional[str]): self.add_guild(ctx) @@ -585,14 +585,14 @@ async def queue_command(self, ctx, *, url: typing.Optional[str]): description=''.join( "Queue is empty, nothing to play\nUse ` play ` to add to queue"), colour=0xff0000, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) await ctx.send(embed=embed) return embed = discord.Embed( title="Queue", colour=0x0000ff, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) embed.set_thumbnail(url=self.MUSIC_ICON) embed.set_author(name="Dex", icon_url=self.bot.user.avatar_url) @@ -603,7 +603,7 @@ async def queue_command(self, ctx, *, url: typing.Optional[str]): description=str("Page " + str(i // 25 + 1) + " of " + str(size // 25 + 1)), colour=0x0000ff, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) embed.set_thumbnail(url=self.MUSIC_ICON) embed.set_author(name="Dex", icon_url=self.bot.user.avatar_url) @@ -638,7 +638,7 @@ async def remove_command(self, ctx, pos): description=''.join( "Missing required argument: ``"), colour=0xff0000, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) await ctx.send(embed=embed) return @@ -649,7 +649,7 @@ async def remove_command(self, ctx, pos): description=str( "Queue Position must be between (1 & "+str(len(self.music_queue[str(ctx.guild.id)]))+")"), colour=0xff0000, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) await ctx.send(embed=embed) return @@ -661,7 +661,7 @@ async def remove_command(self, ctx, pos): self.music_queue[str(ctx.guild.id)][int(pos) ][1].author.mention, colour=0x00ff00, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) player = self.music_queue[str(ctx.guild.id)][int(pos)][0] embed.set_thumbnail(url=self.MUSIC_ICON) @@ -696,7 +696,7 @@ async def jump_command(self, ctx, pos): description=''.join( "Missing required argument: ``"), colour=0xff0000, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) await ctx.send(embed=embed) return @@ -707,7 +707,7 @@ async def jump_command(self, ctx, pos): description=str( "Queue Position must be between (1 & "+str(len(self.music_queue[str(ctx.guild.id)]))+")"), colour=0xff0000, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) await ctx.send(embed=embed) return @@ -717,7 +717,7 @@ async def jump_command(self, ctx, pos): title="Jumping to " + str(pos + 1), description="- requested by " + ctx.author.mention, colour=0x00ff00, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) player = self.music_queue[str(ctx.guild.id)][int(pos)][0] embed.set_thumbnail(url=self.MUSIC_ICON) @@ -746,7 +746,7 @@ async def volume_command(self, ctx, volume: int): embed = discord.Embed( title=str(volume) + "%", colour=0x00ff00, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) embed.set_author(name="Volume set to", icon_url=ctx.author.avatar_url) @@ -817,7 +817,7 @@ async def next_command(self, ctx): title="Error", description="Nothing to play after this", colour=0xff0000, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) await ctx.send(embed=embed) return @@ -842,7 +842,7 @@ async def previous_command(self, ctx): title="Error", description="Nothing to play before this", colour=0xff0000, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) await ctx.send(embed=embed) return @@ -871,7 +871,7 @@ async def lyrics_command(self, ctx, *args) -> None: title="Error", description="No song is currently playing", color=0xff0000, - timestamp=datetime.datetime.utcnow(), + timestamp=datetime.utcnow(), ) await ctx.send(embed=embed) return @@ -889,7 +889,7 @@ async def lyrics_command(self, ctx, *args) -> None: description=err_mssg + ('\n'+'[see results from GoogleSearch](https://www.google.com/search?q='+song_title+'+lyrics)'), colour=0xff0000, - timestamp=datetime.datetime.utcnow(), + timestamp=datetime.utcnow(), ) await ctx.send(embed=embed) else: @@ -906,7 +906,7 @@ async def lyrics_command(self, ctx, *args) -> None: title=data['title'], description=lyrics+extend_text, color=0x00ff00, - timestamp=datetime.datetime.utcnow(), + timestamp=datetime.utcnow(), ) embed.set_author( name=data['author'], diff --git a/src/cogs/other.py b/src/cogs/other.py index d8e5b7de..e7c933d1 100644 --- a/src/cogs/other.py +++ b/src/cogs/other.py @@ -1,6 +1,6 @@ import discord import aiohttp -import datetime +from datetime import datetime from discord.ext import commands @@ -33,7 +33,7 @@ async def covid19_command(self, ctx, *args): title=(k["Country"]).title(), description="COVID-19 Statistics", colour=0xff0000, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) flag_url = "https://flagcdn.com/w640/" + \ str(k["CountryCode"]).lower() + ".jpg" @@ -57,7 +57,7 @@ async def covid19_command(self, ctx, *args): title="Global", description="COVID-19 Statistics", colour=0xff0000, - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) embed.set_thumbnail( url="https://user-images.githubusercontent.com/63065397/156144079-6f90504d-ad48-4f2e-bec5-bae31cebd858.png" @@ -101,7 +101,7 @@ async def ping_command(self, ctx): title="Ping", description="**"+str(ping)+"ms**", colour=discord.Color.from_rgb(int(red*255), int(green*255), 0), - timestamp=datetime.datetime.utcnow() + timestamp=datetime.utcnow() ) await ctx.send(embed=embed) # ----------------------------------------------------------------------------------------------------------------------