diff options
Diffstat (limited to 'code/cogs')
-rw-r--r-- | code/cogs/cog_commands.py | 36 | ||||
-rw-r--r-- | code/cogs/tree_sync.py | 34 | ||||
-rw-r--r-- | code/cogs/user_count.py | 45 |
3 files changed, 115 insertions, 0 deletions
diff --git a/code/cogs/cog_commands.py b/code/cogs/cog_commands.py new file mode 100644 index 0000000..fa6b24d --- /dev/null +++ b/code/cogs/cog_commands.py @@ -0,0 +1,36 @@ +from discord.ext import commands + +from global_variables import BOT_COLOR + + +class ReloadCog(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.command() + @commands.dm_only() + @commands.is_owner() + async def reloadcog(self, ctx: commands.Context, cog: str = None): + if not cog: + return await ctx.send("No cog provided.") + + cog = cog.lower() + await self.bot.reload_extension(f"cogs.{cog}") + + await ctx.send(f"Cog {cog} has been reloaded") + + @commands.command() + @commands.dm_only() + @commands.is_owner() + async def loadcog(self, ctx: commands.Context, cog: str = None): + if not cog: + return await ctx.send("No cog provided.") + + cog = cog.lower() + await self.bot.load_extension(f"cogs.{cog}") + + await ctx.send(f"Cog {cog} has been loaded") + + +async def setup(bot): + await bot.add_cog(ReloadCog(bot)) diff --git a/code/cogs/tree_sync.py b/code/cogs/tree_sync.py new file mode 100644 index 0000000..cdc172d --- /dev/null +++ b/code/cogs/tree_sync.py @@ -0,0 +1,34 @@ +from discord.ext import commands +from discord import Object + + +class TreeSync(commands.Cog): + def __init__(self, bot): + self.bot = bot + + + @commands.command() + @commands.dm_only() + @commands.is_owner() + async def sync(self, ctx: commands.Context, *, guild: Object = None) -> None: + if not guild or guild == None: + await self.bot.tree.sync() + await ctx.author.send("Synced commands globally") + return + + elif guild != None: + self.bot.tree.copy_global_to(guild=guild) + await self.bot.tree.sync(guild=guild) + + await ctx.author.send(f"Synced the tree to 1 test guild.") + + @sync.error + async def error_sync(self, ctx, error): + if isinstance(error, commands.errors.PrivateMessageOnly): + pass + else: + await ctx.author.send("That is not a valid guild ID") + + +async def setup(bot): + await bot.add_cog(TreeSync(bot)) diff --git a/code/cogs/user_count.py b/code/cogs/user_count.py new file mode 100644 index 0000000..c2d7321 --- /dev/null +++ b/code/cogs/user_count.py @@ -0,0 +1,45 @@ +from discord.ext import commands +import discord + +from global_variables import BOT_COLOR + + +class UserCount(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.command() + @commands.dm_only() + @commands.is_owner() + async def info(self, ctx: commands.Context): + total_guilds = {} + + for guild in self.bot.guilds: + total_guilds[guild.name] = guild.member_count + + # Sort the dictionary by value descending + total_guilds = dict( + sorted(total_guilds.items(), key=lambda item: item[1], reverse=True) + ) + + total_members = 0 + + for guild in total_guilds: + total_members += total_guilds[guild] + + embed = discord.Embed( + title="User Count", + description=f"Total Members: `{total_members:,}`\nTotal Guilds: `{len(self.bot.guilds):,}`", + color=BOT_COLOR, + ) + # Add the top 5 guilds to the embed + for guild in list(total_guilds)[:5]: + embed.add_field( + name=guild, value=f"```{total_guilds[guild]:,}```", inline=False + ) + + await ctx.send(embed=embed) + + +async def setup(bot): + await bot.add_cog(UserCount(bot)) |