async def _warnlist_member(self, ctx: commands.Context, member: discord.Member, page_num: int = 1) -> None: """ Handles getting the warns for a specific member """ async with self.bot.pool.acquire() as connection: warns = await connection.fetch( "SELECT * FROM warn WHERE member_id = ($1) AND guild_id = $2 ORDER BY id;", member.id, ctx.guild.id) if len(warns) > 0: embed = self.bot.EmbedPages( self.bot.PageTypes.WARN, warns, f"{member.display_name}'s warnings", Colour.from_rgb(177, 252, 129), self.bot, ctx.author, ctx.channel, thumbnail_url=get_guild_icon_url(ctx.guild), icon_url=get_user_avatar_url(ctx.author, mode=1)[0], footer= f"Requested by: {ctx.author.display_name} ({ctx.author})\n" + self.bot.correct_time().strftime(self.bot.ts_format)) await embed.set_page(int(page_num)) await embed.send() else: await ctx.send("No warnings recorded!")
async def info(self, ctx: commands.Context, *, role: discord.Role | str) -> None: """ Displays various details about a specified role. Works with a role mention, role name or role ID. """ if type(role) is not discord.Role: role = await self.find_closest_role(ctx, role, verbosity=Verbosity.ALL) if len(role) > 1: return role = role[0] embed = Embed(title=f"Role info ~ {role.name}", colour=role.colour) embed.add_field(name="Created at", value=self.bot.correct_time(role.created_at)) embed.add_field(name="Members", value=len(role.members)) embed.add_field(name="Position", value=role.position) embed.add_field(name="Displays separately", value=role.hoist) embed.add_field(name="Mentionable", value=role.mentionable) embed.add_field(name="Colour", value=role.colour) embed.add_field(name="Role ID", value=role.id) icon_url = get_guild_icon_url(ctx.guild) if icon_url: embed.set_thumbnail(url=icon_url) embed.set_footer( text=f"Requested by: {ctx.author.display_name} ({ctx.author})\n" + self.bot.correct_time().strftime(self.bot.ts_format), icon_url=get_user_avatar_url(ctx.author, mode=1)[0]) await ctx.send(embed=embed)
async def get_leaderboard(self, ctx: commands.Context) -> None: async with self.bot.pool.acquire() as connection: leaderboard = await connection.fetch( "SELECT member_id, reps FROM rep WHERE guild_id = $1 ORDER BY reps DESC", ctx.guild.id) if len(leaderboard) == 0: await self.bot.DefaultEmbedResponses.error_embed( self.bot, ctx, f"There aren't any reputation points in {ctx.guild.name} yet! " ) return embed = self.bot.EmbedPages( self.bot.PageTypes.REP, leaderboard, f"{ctx.guild.name}'s Reputation Leaderboard", Colour.from_rgb(177, 252, 129), self.bot, ctx.author, ctx.channel, thumbnail_url=get_guild_icon_url(ctx.guild), icon_url=get_user_avatar_url(ctx.author, mode=1)[0], footer=f"Requested by: {ctx.author.display_name} ({ctx.author})\n" + self.bot.correct_time().strftime(self.bot.ts_format)) await embed.set_page(1) # Default first page await embed.send()
async def serverinfo(self, ctx: commands.Context) -> None: """ Information about the server. """ guild = ctx.message.guild time_ = guild.created_at time_since = discord.utils.utcnow() - time_ join = Embed( title=f"**__{str(guild)}__**", description= f"Created at {self.bot.correct_time(time_).strftime(self.bot.ts_format)}. That's {time_since.days} days ago!", color=Colour.from_rgb(21, 125, 224)) icon_url = get_guild_icon_url(guild) if icon_url: join.set_thumbnail(url=icon_url) join.add_field( name="Users Online", value= f"{len([x for x in guild.members if x.status != Status.offline])}/{len(guild.members)}" ) if ctx.guild.rules_channel: # only community join.add_field(name="Rules Channel", value=f"{ctx.guild.rules_channel.mention}") join.add_field(name="Text Channels", value=f"{len(guild.text_channels)}") join.add_field(name="Voice Channels", value=f"{len(guild.voice_channels)}") join.add_field(name="Roles", value=f"{len(guild.roles)}") join.add_field(name="Owner", value=f"{str(guild.owner)}") join.add_field(name="Server ID", value=f"{guild.id}") join.add_field( name="Emoji slots filled", value=f"{len(ctx.guild.emojis)}/{ctx.guild.emoji_limit}") join.add_field( name="Sticker slots filled", value=f"{len(ctx.guild.stickers)}/{ctx.guild.sticker_limit}") join.add_field(name="Upload size limit", value=f"{guild.filesize_limit/1048576} MB") join.add_field( name="Boost level", value= f"{ctx.guild.premium_tier} ({ctx.guild.premium_subscription_count} boosts, {len(ctx.guild.premium_subscribers)} boosters)" ) join.add_field( name="Default Notification Level", value=f"{self.bot.make_readable(guild.default_notifications.name)}" ) join.set_footer( text=f"Requested by: {ctx.author.display_name} ({ctx.author})\n" + (self.bot.correct_time()).strftime(self.bot.ts_format), icon_url=get_user_avatar_url(ctx.author, mode=1)[0]) await ctx.send(embed=join)
async def warns(self, ctx: commands.Context, member: discord.Member = None) -> None: """ Shows a user their warnings, or shows staff members all/a single persons warnings """ is_staff = await self.bot.is_staff(ctx) if is_staff: if not member: # Show all warns async with self.bot.pool.acquire() as connection: warns = await connection.fetch( "SELECT * FROM warn WHERE guild_id = $1 ORDER BY id;", ctx.guild.id) if len(warns) > 0: embed = self.bot.EmbedPages( self.bot.PageTypes.WARN, warns, f"{ctx.guild.name if not member else member.display_name}'s warnings", Colour.from_rgb(177, 252, 129), self.bot, ctx.author, ctx.channel, thumbnail_url=get_guild_icon_url(ctx.guild), icon_url=get_user_avatar_url(ctx.author, mode=1)[0], footer= f"Requested by: {ctx.author.display_name} ({ctx.author})\n" + self.bot.correct_time().strftime(self.bot.ts_format)) await embed.set_page(1) await embed.send() else: await ctx.send("No warnings recorded!") else: # Show member's warns await self._warnlist_member( ctx, member, 1) # Last parameter is the page number to start on else: if not member or member.id == ctx.author.id: # Show ctx.author warns await self._warnlist_member(ctx, ctx.author, 1) else: await ctx.send( "You don't have permission to view other people's warns.")
async def list_server_roles(self, ctx: commands.Context) -> None: """ Lists all the roles on the server. """ embed = self.bot.EmbedPages( self.bot.PageTypes.ROLE_LIST, ctx.guild.roles[1:][::-1], f":information_source: Roles in {ctx.guild.name}", ctx.author.colour, self.bot, ctx.author, ctx.channel, thumbnail_url=get_guild_icon_url(ctx.guild), icon_url=get_user_avatar_url(ctx.author, mode=1)[0], footer=f"Requested by: {ctx.author.display_name} ({ctx.author})\n" + self.bot.correct_time().strftime(self.bot.ts_format)) await embed.set_page(1) await embed.send()
async def view(self, ctx: commands.Context) -> None: """ View all of the starboards in the current guild """ starboards = await self._get_starboards(ctx.guild.id) embed = self.bot.EmbedPages( self.bot.PageTypes.STARBOARD_LIST, starboards, f":information_source: {ctx.guild.name}'s starboards", self.bot.GOLDEN_YELLOW, self.bot, ctx.author, ctx.channel, thumbnail_url=get_guild_icon_url(ctx.guild), icon_url=get_user_avatar_url(ctx.author, mode=1)[0], footer=f"Requested by: {ctx.author.display_name} ({ctx.author})\n" + self.bot.correct_time().strftime(self.bot.ts_format), ) await embed.set_page(1) await embed.send()
async def list(self, ctx: commands.Context, page_num: int = 1) -> None: async with self.bot.pool.acquire() as connection: qotds = await connection.fetch( "SELECT * FROM qotd WHERE guild_id = $1 ORDER BY id", ctx.guild.id) if len(qotds) > 0: embed = self.bot.EmbedPages( self.bot.PageTypes.QOTD, qotds, f"{ctx.guild.name}'s QOTDs", Colour.from_rgb(177, 252, 129), self.bot, ctx.author, ctx.channel, thumbnail_url=get_guild_icon_url(ctx.guild), icon_url=get_user_avatar_url(ctx.author, mode=1)[0], footer= f"Requested by: {ctx.author.display_name} ({ctx.author})\n" + self.bot.correct_time().strftime(self.bot.ts_format)) await embed.set_page(int(page_num)) await embed.send() else: await ctx.send("No QOTD have been submitted in this guild before.")
async def resultsday(self, ctx: commands.Context, hour: str = "") -> None: if ctx.invoked_with in ["resultsday", "gcseresults", "results", None]: which = "GCSE" else: which = "A-Level" if not hour: hour = 10 else: try: hour = int(hour) except ValueError: await ctx.send( "You must choose an integer between 0 and 23 for the command to work!" ) if not 0 <= hour < 24: await ctx.send("The hour must be between 0 and 23!") return if hour == 12: string = "noon" elif hour == 0: string = "0:00AM" elif hour >= 12: string = f"{hour - 12}PM" else: string = f"{hour}AM" rn = self.bot.correct_time() if which == "GCSE": time_ = self.bot.correct_time( datetime(year=2022, month=8, day=18, hour=hour, minute=0, second=0)) else: time_ = self.bot.correct_time( datetime(year=2022, month=8, day=11, hour=hour, minute=0, second=0)) embed = Embed( title= f"Countdown until {which} results day at {string} (on {time_.day}/{time_.month}/{time_.year})", color=Colour.from_rgb(148, 0, 211)) if rn > time_: embed.description = "Results have already been released!" else: time_ = time_ - rn m, s = divmod(time_.seconds, 60) h, m = divmod(m, 60) embed.description = f"{time_.days} days {h} hours {m} minutes {s} seconds remaining" embed.set_footer( text=f"Requested by: {ctx.author.display_name} ({ctx.author})\n" + (self.bot.correct_time()).strftime(self.bot.ts_format), icon_url=get_user_avatar_url(ctx.author, mode=1)[0]) icon_url = get_guild_icon_url(ctx.guild) if icon_url: embed.set_thumbnail(url=icon_url) await ctx.send(embed=embed)
async def config(self, ctx: commands.Context) -> None: """ View the current configuration settings of the guild """ if not (ctx.author.guild_permissions.administrator or await self.is_staff(ctx)): await self.bot.DefaultEmbedResponses.invalid_perms(self.bot, ctx) return if ctx.invoked_subcommand is None: # User is staff and no subcommand => send embed """ To get the config options 1. Copy self.CONFIG into a new variable 2. Foreach config option, append the option to the list under the specific option's key (this is the embed value) 3. Pass the dict into EmbedPages for formatting """ data = copy.deepcopy(self.CONFIG) config_dict = self.bot.configs[ctx.guild.id] for key in config_dict.keys(): if key not in data.keys(): continue # This clause ensures that variables, e.g. "bruhs", that are in the DB but not in self.CONFIG, do not appear if not config_dict[key] or data[key][0] not in [ Validation.Channel, Validation.Role ]: data[key].append(config_dict[key] if config_dict[key] is not None else "*N/A*") elif data[key][0] == Validation.Channel: channel = ctx.guild.get_channel_or_thread( config_dict[key] ) # note that this is gonna have to be looked at again if any other types of channels are to be allowed data[key].append(f"{channel.mention} ({config_dict[key]})" if channel else "*N/A*") elif data[key][0] == Validation.Role: role = ctx.guild.get_role(config_dict[key]) data[key].append(f"{role.mention} ({config_dict[key]})" if role else "*N/A*") p = ( await self.bot.get_used_prefixes(ctx) )[-1] # guild will be last if set, if not it'll fall back to global desc = f"Below are the configurable options for {ctx.guild.name}. To change one, do `{p}config set <key> <value>` where <key> is the option you'd like to change, e.g. `{p}config set qotd_limit 2`" embed = self.bot.EmbedPages( self.bot.PageTypes.CONFIG, data, f":tools: {ctx.guild.name} ({ctx.guild.id}) configuration", ctx.author.colour, self.bot, ctx.author, ctx.channel, desc=desc, thumbnail_url=get_guild_icon_url(ctx.guild), icon_url=get_user_avatar_url(ctx.author, mode=1)[0], footer= f"Requested by: {ctx.author.display_name} ({ctx.author})\n" + self.bot.correct_time().strftime(self.bot.ts_format)) await embed.set_page(1) # Default first page await embed.send()