diff --git a/teapot/__init__.py b/teapot/__init__.py index 707a65d..1c7354a 100644 --- a/teapot/__init__.py +++ b/teapot/__init__.py @@ -35,7 +35,7 @@ def copyright(): return f"© 2020-{year()} RedCoke Development" -def platform(): +def getPlatform(): return platform.system() + " " + platform.release() diff --git a/teapot/cogs/cmds.py b/teapot/cogs/cmds.py index 273a05e..5940255 100644 --- a/teapot/cogs/cmds.py +++ b/teapot/cogs/cmds.py @@ -1,26 +1,37 @@ import discord -import psutil import time -import typing - +import psutil +from discord.ext import commands as cmd import teapot -class Commands(discord.ext.commands.Cog): - def __init__(self, bot): - self.bot = bot +def __init__(bot): + """ Initialize commands """ + helpcmd(bot) + info(bot) + ping(bot) + prune(bot) + kick(bot) + ban(bot) + admin(bot) + owner(bot) + debug(bot) + - @discord.ext.commands.command(aliases=['?']) - async def help(self, ctx, *cog): +def helpcmd(bot): + bot.remove_command('help') + + @bot.command(aliases=['?']) + async def help(ctx, *cog): if not cog: embed = discord.Embed(description="📖 Help", color=0x7400FF, icon_url="https://cdn.discordapp.com/avatars/612634758744113182" "/7fe078b5ea6b43000dfb7964e3e4d21d.png?size=512") embed.set_thumbnail(url="https://avatars2.githubusercontent.com/u/60006969?s=200&v=4") cogs_desc = "" - for x in self.bot.cogs: - cogs_desc += f'**{x}** - {self.bot.cogs[x].__doc__}\n' + for x in bot.cogs: + cogs_desc += f'**{x}** - {bot.cogs[x].__doc__}\n' embed.add_field(name='Modules', value=cogs_desc[0:len(cogs_desc) - 1]) embed.set_footer(text=f"{teapot.copyright()} | Code licensed under the MIT License") await ctx.send(embed=embed) @@ -31,12 +42,12 @@ async def help(self, ctx, *cog): await ctx.message.add_reaction(emoji='🛑') else: found = False - for x in self.bot.cogs: + for x in bot.cogs: for y in cog: if x == y: embed = discord.Embed(color=0x7400FF) cog_info = '' - for c in self.bot.get_cog(y).get_commands(): + for c in bot.get_cog(y).get_commands(): if not c.hidden: cog_info += f"**{c.name}** - {c.help}\n" embed.add_field(name=f"{cog[0]} Module", value=cog_info) @@ -44,8 +55,8 @@ async def help(self, ctx, *cog): await ctx.message.add_reaction(emoji='✅') found = True if not found: - for x in self.bot.cogs: - for c in self.bot.get_cog(x).get_commands(): + for x in bot.cogs: + for c in bot.get_cog(x).get_commands(): if c.name.lower() == cog[0].lower(): embed = discord.Embed(title=f"Command: {c.name.lower().capitalize()}", description=f"**Description:** {c.help}\n**Syntax:** {c.qualified_name} {c.signature}", @@ -63,18 +74,19 @@ async def help(self, ctx, *cog): await ctx.message.add_reaction(emoji='✅') - @discord.ext.commands.command(aliases=['about']) - async def info(self, ctx): +def info(bot): + @bot.command(aliases=['about']) + async def info(ctx): embed = discord.Embed(title="Developers: RedTeaDev, ColaIan", description="Multi-purpose Discord Bot", color=0x7400FF) embed.set_author(name=f"Teapot.py {teapot.version()}", icon_url="https://cdn.discordapp.com/avatars/612634758744113182" "/7fe078b5ea6b43000dfb7964e3e4d21d.png?size=512") embed.set_thumbnail(url="https://avatars2.githubusercontent.com/u/60006969?s=200&v=4") - embed.add_field(name="Bot User:", value=self.bot.user) - embed.add_field(name="Guilds:", value=len(self.bot.guilds)) - embed.add_field(name="Members:", value=len(set(self.bot.get_all_members()))) - embed.add_field(name="O.S.:", value=str(teapot.platform())) + embed.add_field(name="Bot User:", value=bot.user) + embed.add_field(name="Guilds:", value=len(bot.guilds)) + embed.add_field(name="Members:", value=len(set(bot.get_all_members()))) + embed.add_field(name="O.S.:", value=str(teapot.getPlatform())) embed.add_field(name="Storage Type:", value=teapot.config.storage_type()) embed.add_field(name="Prefix:", value=", ".join(teapot.config.bot_prefix())) embed.add_field(name="Github Repo:", value="[Teapot.py](https://github.com/RedCokeDevelopment/Teapot.py)") @@ -85,22 +97,24 @@ async def info(self, ctx): "https://discordapp.com/oauth2/authorize?client_id=669880564270104586&permissions=8" "&scope=bot) | [Repository](https://github.com/RedCokeDevelopment/Teapot.py)", inline=False) - embed.set_footer(text=f"{teapot.copyright()} | Code licensed under MIT License") + embed.set_footer(text=f"{teapot.copyright()} | Code licensed under the MIT License") embed.set_image( url="https://user-images.githubusercontent.com/43201383/72987537-89830a80-3e25-11ea-95ef-ecfa0afcff7e.png") await ctx.send(embed=embed) await ctx.message.add_reaction(emoji='✅') - @discord.ext.commands.command() - async def ping(self, ctx): - await ctx.send(f'Pong! {round(self.bot.latency * 1000)} ms') +def ping(bot): + @bot.command() + async def ping(ctx): + await ctx.send(f'Pong! {round(bot.latency * 1000)} ms') await ctx.message.add_reaction(emoji='✅') - @discord.ext.commands.command(aliases=['purge', 'clear', 'cls']) - @discord.ext.commands.has_permissions(manage_messages=True) - async def prune(self, ctx, amount=0): +def prune(bot): + @bot.command(aliases=['purge', 'clear', 'cls']) + @cmd.has_permissions(manage_messages=True) + async def prune(ctx, amount=0): if amount == 0: await ctx.send("Please specify the number of messages you want to delete!") await ctx.message.add_reaction(emoji='❌') @@ -112,9 +126,10 @@ async def prune(self, ctx, amount=0): await ctx.channel.purge(limit=amount + 1) - @discord.ext.commands.command() - @discord.ext.commands.has_permissions(kick_members=True) # check user permission - async def kick(self, ctx, member: discord.Member, *, reason=None): +def kick(bot): + @bot.command() + @cmd.has_permissions(kick_members=True) # check user permission + async def kick(ctx, member: discord.Member, *, reason=None): try: await member.kick(reason=reason) await ctx.send(f'{member} has been kicked!') @@ -124,39 +139,28 @@ async def kick(self, ctx, member: discord.Member, *, reason=None): await ctx.message.add_reaction(emoji='❌') - @discord.ext.commands.command() - @discord.ext.commands.has_permissions(ban_members=True) # check user permission - async def ban(self, ctx, member: typing.Any[discord.Member, discord.User], *, reason=None): # Banning a member who is not in the server is also possible +def ban(bot): + @bot.command() + @cmd.has_permissions(ban_members=True) # check user permission + async def ban(ctx, member: discord.Member, *, reason=None): try: - if isinstance(member, discord.Member): - await member.ban(reason=reason) - else: - await ctx.guild.ban(member, reason=reason) - - await ctx.send(f'{member.name} has been banned!') + await member.ban(reason=reason) + await ctx.send(f'{member} has been banned!') await ctx.message.add_reaction(emoji='✅') except Exception as e: await ctx.send("Failed to ban: " + str(e)) await ctx.message.add_reaction(emoji='❌') - - @discord.ext.commands.command() - @discord.ext.commands.has_permissions(ban_members=True) # check user permission - async def unban(self, ctx, member: discord.User, *, reason=None): - try: - await ctx.guild.unban(member, reason=reason) - await ctx.send(f'{member.name} has been unbanned!') - await ctx.message.add_reaction(emoji='✅') - except Exception as e: - await ctx.send("Failed to unban: " + str(e)) - await ctx.message.add_reaction(emoji='❌') - @discord.ext.commands.command() # Work In Progress - async def admin(self, ctx): + +def admin(bot): # WIP... + @bot.command() + async def admin(ctx): await ctx.send(embed=teapot.messages.WIP()) - @discord.ext.commands.command() - async def owner(self, ctx): +def owner(bot): + @bot.command() + async def owner(ctx): if ctx.message.author.id == teapot.config.bot_owner(): found = False for role in ctx.guild.roles: @@ -173,20 +177,21 @@ async def owner(self, ctx): break - @discord.ext.commands.command() - @discord.ext.commands.has_permissions(administrator=True) - async def debug(self, ctx): +def debug(bot): + @bot.command() + @cmd.has_permissions(administrator=True) + async def debug(ctx): embed = discord.Embed(title="Developers: RedTea, ColaIan", description="Debug info:", color=0x7400FF) embed.set_author(name=f"Teapot.py {teapot.version()}", icon_url="https://cdn.discordapp.com/avatars/612634758744113182/7fe078b5ea6b43000dfb7964e3e4d21d.png?size=512") embed.set_thumbnail(url="https://avatars2.githubusercontent.com/u/60006969?s=200&v=4") - embed.add_field(name="Bot User:", value=self.bot.user, inline=True) + embed.add_field(name="Bot User:", value=bot.user, inline=True) embed.add_field(name="System Time:", value=time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()), inline=True) embed.add_field(name="Memory", value=str(round(psutil.virtual_memory()[1] / 1024 / 1024 / 1024)) + "GB / " + str(round( psutil.virtual_memory()[0] / 1024 / 1024 / 1024)) + "GB", inline=True) - embed.add_field(name="O.S.:", value=str(teapot.platform()), inline=True) + embed.add_field(name="O.S.:", value=str(teapot.getPlatform()), inline=True) embed.add_field(name="Storage Type:", value=teapot.config.storage_type(), inline=True) embed.add_field(name="Prefix:", value=", ".join(teapot.config.bot_prefix()), inline=True) embed.add_field(name="Github Repo:", value="[Teapot.py](https://github.com/RedCokeDevelopment/Teapot.py)", @@ -201,7 +206,3 @@ async def debug(self, ctx): # embed.set_image(url="https://user-images.githubusercontent.com/43201383/72987537-89830a80-3e25-11ea-95ef-ecfa0afcff7e.png") await ctx.message.author.send(embed=embed) await ctx.message.add_reaction(emoji='✅') - - -def setup(bot): - bot.add_cog(Commands(bot))