async def redirect_list(self, ctx): try: async with self.bot.db.acquire() as con: overrides = await con.fetch( f"SELECT * FROM redirects WHERE guild_id={ctx.guild.id} AND type='override'" ) rglobal = await con.fetch( f"SELECT * FROM redirects WHERE guild_id={ctx.guild.id} AND type='all'" ) except Exception: raise customerrors.RedirectSearchError() or_count = [ f"`{ovr['command']}` ⟶ <#{ovr['channel_id']}> [*set by <@{ovr['author_id']}>*]" for ovr in overrides ] if overrides else ["No overriding redirects exist"] rg_count = f"{len(rglobal)} commands are globally redirected" if rglobal else "No global redirects exist" pag = paginator.EmbedPaginator(ctx, entries=or_count, per_page=10, show_entry_count=False) pag.embed.title = "Command Redirects" pag.embed.set_footer(text=rg_count) return await pag.paginate()
async def warns(self, ctx, *, user: discord.Member = None): if user is None: user = ctx.author warns = await self.bot.pool.fetch( "SELECT * FROM warns WHERE userid = $1 AND guildid = $2", user.id, ctx.guild.id) if warns == []: embed = discord.Embed(title="Error", color=discord.Color.blurple(), description="This user has not been warned") await ctx.send(embed=embed) return pag = paginator.EmbedPaginator() for warning in warns: count = await self.bot.pool.fetchval( "SELECT COUNT(*) FROM warns WHERE userid = $1 AND guildid = $2", user.id, ctx.guild.id) embed = discord.Embed(title=f"{user} has {count} warning(s)", color=discord.Color.blurple()) moderator = warning["modname"] reason = warning["reason"] embed.add_field(name=f"Warned by: {moderator}", value=f"For Reason: {reason}") pag.add_page(embed) interface = Paginator(ctx, pag) await interface.send_pages()
async def search(self, ctx, *, keyword): entries = await self.search_tags(ctx, keyword) pag = paginator.EmbedPaginator(ctx, entries=entries, per_page=10, show_entry_count=True) pag.embed.title = "Search Results" return await pag.paginate()
async def help(self, ctx): pag = paginator.EmbedPaginator() hp = ("main", "normal", "economy", "shop", "snipe", "moderation") for p in hp: pag.add_page(await getattr(self.help_pages, p)(ctx)) interface = Paginator(ctx, pag) await interface.send_pages()
async def guild(self, ctx): entries = [ f"{guild.name}" for guild in await self.get_premium_guilds() ] pag = paginator.EmbedPaginator(ctx, entries=entries, per_page=10, show_entry_count=True) pag.embed.title = "MarwynnBot Premium Servers" return await pag.paginate()
async def serverlink_list(self, ctx): entries = [ f"<#{entry['channel_id']}>" for entry in await self.get_serverlink_channels(ctx) ] pag = paginator.EmbedPaginator(ctx, entries=entries, per_page=20, show_entry_count=False) pag.embed.title = "Registered ServerLink Channels" return await pag.paginate()
async def user(self, ctx, source: str = "guild"): op = source if source == "guild" else "global" entries = [ f"{user.mention} - {user.name}" for user in await self.get_premium_users(ctx.guild, op) ] pag = paginator.EmbedPaginator(ctx, entries=entries, per_page=10, show_entry_count=True) pag.embed.title = f"MarwynnBot Premium Users in {ctx.guild.name}" if op == "guild" else "MarwynnBot Premium Users" return await pag.paginate()
async def warns(self, ctx, *, user: discord.Member = None): if user is None: warns = await self.bot.pool.fetch( "SELECT * FROM warns WHERE guildid = $1 ORDER BY time DESC", ctx.guild.id) title = f"There are {len(warns)} warning(s) in this server." else: warns = await self.bot.pool.fetch( "SELECT * FROM warns WHERE userid = $1 AND guildid = $2 ORDER BY time DESC", user.id, ctx.guild.id) title = f"{user.name} has {len(warns)} warning(s)." if warns == []: em = discord.Embed(color=discord.Color.red()) em.add_field(name="No Warnings", value="No warnings have been found.") await ctx.send(embed=em) return pag = paginator.EmbedPaginator() for warning in warns: em = discord.Embed(color=discord.Color.red()) em.title = title isname = ctx.guild.get_member(warning["issuerid"]) if user is None: isname = ctx.guild.get_member(warning["userid"]) if isname is None: isname = "Unknown User" else: isname = isname.name elif isname is None: isname = warning["issuername"] else: isname = isname.name if user: em.add_field(name=f"Moderator: {isname}", value=warning["reason"]) else: em.add_field(name=f"User: {isname}", value=warning["reason"]) em.timestamp = warning["time"] pag.add_page(em) interface = Paginator(ctx, pag) await interface.send_pages()
async def counter(self, ctx, name=None, mode='server'): if name == "server" or name == "global": mode = name name = None if not name: async with self.bot.db.acquire() as con: if mode == 'server': result = (await con.fetch( f"SELECT counter FROM guild WHERE guild_id = {ctx.guild.id}" ))[0]['counter'] result_dict = json.loads(result) title = f"Counters for {ctx.guild.name}" entries = [ f"***{key.lower()}:*** *used {result_dict[key]} {'times' if result_dict[key] != 1 else 'time'}*" for key in result_dict.keys() ] else: result = (await con.fetch(f"SELECT * from global_counters")) title = "Global Counters" entries = [ f"***{record['command'].lower()}:*** *used {record['amount']} {'times' if record['amount'] != 1 else 'time'}*" for record in result ] pag = paginator.EmbedPaginator(ctx, entries=sorted(entries), per_page=20, show_entry_count=True) pag.embed.title = title return await pag.paginate() else: command = self.bot.get_command(name) async with self.bot.db.acquire() as con: if mode == "global": amount = (await con.fetch( f"SELECT amount from global_counters WHERE command = '{command.name}'" ))[0]['amount'] title = f"Global Counter for {command.name.title()}" else: amount = (await con.fetch( f"SELECT counter->>'{command.name}' from guild WHERE guild_id = {ctx.guild.id}" ))[0][0] title = f"Server Counter for {command.name.title()}" description = f"***{command.name}:*** *used {amount} {'times' if amount != 1 else 'time'}*" embed = discord.Embed(title=title, description=description, color=discord.Color.blue()) return await ctx.channel.send(embed=embed)
async def lock_list(self, ctx, *, flag: str = "all"): if flag not in ['all', 'lock', 'unlock']: flag == 'all' entries = await self.get_locks(ctx, flag) if not entries: embed = discord.Embed( title="No Locks Set", description= f"{ctx.author.mention}, this server does not have any {flag + 'ed' if flag != 'all' else 'locked'} channels", color=discord.Color.dark_red()) return await ctx.channel.send(embed=embed) else: pag = paginator.EmbedPaginator(ctx, entries=entries, per_page=10, show_entry_count=True) pag.embed.title = f"{flag.title() if flag != 'all' else 'All Locked'} Channels" return await pag.paginate()
async def cases(self, ctx, user: discord.Member = None): """Shows the amount of cases for the server.""" modcases = await self.bot.pool.fetch( "SELECT * FROM modcases WHERE guildid = $1", ctx.guild.id) if modcases == []: em = discord.Embed(color=discord.Color.blurple()) em.add_field(name="Error", value="No cases have been found.") await ctx.send(embed=em) return pag = paginator.EmbedPaginator() for case in modcases: casenumber = case["casenumber"] casetype = case["casetype"] caseuserid = case["caseuserid"] casemodid = case["casemodid"] casereason = case["casereason"] em = discord.Embed(color=discord.Color.blurple()) em.title = f"Case #{casenumber} | {casetype}" caseuser = await self.bot.fetch_user(caseuserid) casemod = await self.bot.fetch_user(casemodid) em.add_field( name="User", value= f"{caseuser.mention} ({caseuser.name}#{caseuser.discriminator})", inline=False) em.add_field( name="Moderator", value= f"{casemod.mention} ({casemod.name}#{casemod.discriminator})", inline=False) em.add_field(name="Reason", value=casereason, inline=False) pag.add_page(em) interface = Paginator(ctx, pag) await interface.send_pages()
async def keys(self, ctx): keys = await self.bot.pool.fetch("SELECT * FROM apikeys") if keys == []: em = discord.Embed(color=discord.Color.red()) em.add_field(name="No API Keys", value="No API Keys have been found.") await ctx.send(embed=em) return pag = paginator.EmbedPaginator() for key in keys: em = discord.Embed(titile="API Keys", color=discord.Color.red()) em.add_field(name="Name:", value=key['name']) em.add_field(name="Key:", value=key['key']) pag.add_page(em) interface = Paginator(ctx, pag) await interface.send_pages()
async def todo_list(self, ctx, *, flag: str = None): if not flag in ["active", "done", "complete"]: entries = await self.get_todos(ctx, list=True, detailed=True) title = f"All Todos Created" elif flag == "active": entries = await self.get_todos(ctx, req_active=True, list=True, detailed=True) title = "Your Active Todos" elif flag in ["done", "complete", "completed", "finished"]: title = "Your Completed Todos" entries = await self.get_todos(ctx, req_complete=True, list=True, detailed=True) pag = paginator.EmbedPaginator(ctx, entries=entries, per_page=10, show_entry_count=True) pag.embed.title = title return await pag.paginate()
async def list2(self, ctx, channel: discord.TextChannel = None): """Lists notifications in the current channel.""" msgs = await lang.get_lang(ctx) if not ctx.guild: return await ctx.send(msgs['permissions']['no_pm']) channel = channel or ctx.channel notifs = list( r.table('notifications').filter(r.row['channel'].eq(str( channel.id))).run(self.bot.rethink, durability="soft")) if len(notifs) == 0: return await ctx.send(msgs['notifs']['no_notifs']) e = discord.Embed( color=0x6441A4, title=f"Notifications for #{ctx.channel.name}", description= f"Notification count: {len(notifs)}\n[View on Dashboard](https://dash.twitchbot.io/servers/{ctx.guild.id})" ) for notif in notifs: e.add_field(name=notif.get('name', notif['streamer']), value=notif['message']) pager = paginator.EmbedPaginator(e) await pager.page(ctx)
async def lang(self, ctx, language=None): msgs = await lang.get_lang(ctx) if language is None: return await ctx.send( msgs['general']['lang_current'].format(lang=msgs['_lang_name']) ) else: if language == "help": lang_help = await lang.gen_lang_help(ctx) e = paginator.EmbedPaginator(lang_help, per_page=7) return await e.page(ctx) if not language in self.bot.languages: return await ctx.send(msgs['general']['lang_unavailable']) cursor = r.table('user_options').insert( { "id": str(ctx.author.id), "lang": language }, conflict="update").run(self.bot.rethink, durability="soft", noreply=True) msgs = await lang.get_lang(ctx) return await ctx.send( msgs['general']['lang_set'].format(lang=msgs['_lang_name']))
async def list(self, ctx): desc_list = await self.list_user_tags(ctx) pag = paginator.EmbedPaginator(ctx, entries=desc_list, per_page=10) pag.embed.title = "Your Tags" return await pag.paginate()