def staff_command_check(ctx: Context) -> bool: if not ctx.guild: # Return False in a DM log.info( f"{ctx.author} tried to use the '{ctx.command.name}'command from a DM. " "This command is restricted by the staff_command decorator. Rejecting request." ) return False # Is owner if ctx.author == ctx.guild.owner: return True # Get guild configured staff roles staff_roles = [] for role in _get(ctx.guild.id, 'group', 'staff'): staff_roles.append(_get(ctx.guild.id, 'roles', role)) for role in ctx.author.roles: if role.id in staff_roles: log.info( f"'{ctx.guild.name}' '{role.name}' {ctx.author} passes check for '{ctx.command.name}'." ) return True log.info(f"{ctx.author} does not have the required role to use " f"the '{ctx.command.name}' command, so the request is rejected.") return False
async def status(self, ctx, ip_port=None): """Ping an MCBE server for info""" if ip_port is None: ip_port = _get(ctx.guild.id, 'status', 'default') if ip_port == "all": status_aliases = _get(ctx.guild.id, 'status', 'aliases') if status_aliases == None: await ctx.send(f'ctx.guild.name has yet no status defaults,') return servers = status_aliases.values() else: servers = ip_port.split() # Replace alias from config if parsed servers = [ _get(ctx.guild.id, 'status', 'aliases').get(i, i) for i in servers ] for server in servers: # Set portless input to default port, 19132 try: server_ip, server_port = server.split(":") except: server_ip = server server_port = 19132 # Ping server q = Query(server_ip, int(server_port)) server_data = q.query() if server_data is None: await ctx.send(f'Failed to get ping data from {server}') # Set-up embed server_status = discord.Embed(title=server_ip, description="Offline", colour=0xff0000) if server_data.SUCCESS: server_status.colour = 0x00ff00 server_status.description = "Online" server_status.add_field(name="Name", value=server_data.SERVER_NAME, inline=False) server_status.add_field( name="Players", value= f'{server_data.NUM_PLAYERS}/{server_data.MAX_PLAYERS}', inline=True) server_status.add_field(name=server_data.GAME_ID, value=server_data.GAME_VERSION, inline=True) await ctx.send(embed=server_status)
async def groups(self, ctx): """List/manage permission groups for TRB commands""" if ctx.invoked_subcommand is None: groups = _get(ctx.guild.id, 'group') mods = groups['mods'] staff = groups['staff'] others = [] # Combine groups without duplicates unique = set(mods + staff) for role in ctx.guild.roles: if role.name.lower() not in unique: others.append(role.name.lower()) mods_roles = '\n-'.join(mods) staff_roles = '\n-'.join(staff) others_roles = '\n-'.join(others) group_list = discord.Embed(title=f'{ctx.guild.name} Role Groups', colour=0x4b4740) group_list.add_field(name='Moderators', value=f'-{mods_roles}') group_list.add_field(name='Staff', value=f'-{staff_roles}') group_list.add_field(name='Others', value=f'-{others_roles}') await ctx.send(embed=group_list)
async def status_alias(self, ctx): """List server aliases for status command""" if ctx.invoked_subcommand is None: aliases = _get(ctx.guild.id, 'status', 'aliases') if aliases is None: await ctx.send( f'No server aliases have been set for {ctx.guild.name}') return alias_list = discord.Embed( title=f'{ctx.guild.name} Status Aliases', colour=0x4b4740) for alias in aliases: alias_list.add_field(name=alias, value=aliases[alias]) await ctx.send(embed=alias_list)
async def post_updates(self, updates): for branch in updates: log.info(f'Posting new {branch} changelogs...') payload = updates[branch] # Get update channel id for update branch from all guild configs channels = [ _get(guild.id, 'updates', branch) for guild in self.bot.guilds ] # Post to all channels for channel_id in channels: if channel_id is None: continue channel = self.bot.get_channel(channel_id) await channel.send(payload)
async def _updates(self, ctx): """List the channels where MCBE updates will be posted""" if ctx.invoked_subcommand is None: # Get guild's update channel dictionary channels = _get(ctx.guild.id, 'updates') title = f'{ctx.guild.name} Update Channels' guild_updates = Embed(colour=Colours.techrock) guild_updates.set_author(name=title, icon_url=Icons.techrock) # Loop though update channel dictionary for branch in channels: channel_id = channels[branch] if channel_id is None: guild_updates.add_field(name=branch, value='Not set') continue channel = self.bot.get_channel(channel_id) guild_updates.add_field(name=branch, value=channel.mention) await ctx.send(embed=guild_updates)
async def build_pages(self) -> None: """Builds the list of content pages to be paginated through in the help message, as a list of str.""" # Use LinePaginator to restrict embed line height paginator = LinePaginator(prefix='', suffix='', max_lines=self._max_lines) prefix = _get(self._ctx.guild.id, 'prefix') # show signature if query is a command if isinstance(self.query, commands.Command): signature = self._get_command_params(self.query) parent = self.query.full_parent_name + ' ' if self.query.parent else '' paginator.add_line(f'**```{prefix}{parent}{signature}```**') # show command aliases aliases = ', '.join(f'`{a}`' for a in self.query.aliases) if aliases: paginator.add_line(f'**Can also use:** {aliases}\n') if not await self.query.can_run(self._ctx): paginator.add_line('***You cannot run this command.***\n') # show name if query is a cog if isinstance(self.query, Cog): paginator.add_line(f'**{self.query.name}**') if self.description: paginator.add_line(f'*{self.description}*') # list all children commands of the queried object if isinstance(self.query, (commands.GroupMixin, Cog)): # remove hidden commands if session is not wanting hiddens if not self._show_hidden: filtered = [c for c in self.query.commands if not c.hidden] else: filtered = self.query.commands # if after filter there are no commands, finish up if not filtered: self._pages = paginator.pages return # set category to Commands if cog if isinstance(self.query, Cog): grouped = (('**Commands:**', self.query.commands),) # set category to Subcommands if command elif isinstance(self.query, commands.Command): grouped = (('**Subcommands:**', self.query.commands),) # don't show prefix for subcommands prefix = '' # otherwise sort and organise all commands into categories else: cat_sort = sorted(filtered, key=self._category_key) grouped = itertools.groupby(cat_sort, key=self._category_key) # process each category for category, cmds in grouped: cmds = sorted(cmds, key=lambda c: c.name) # if there are no commands, skip category if len(cmds) == 0: continue cat_cmds = [] # format details for each child command for command in cmds: # skip if hidden and hide if session is set to if command.hidden and not self._show_hidden: continue # see if the user can run the command strikeout = '' # Patch to make the !help command work outside of #bot-commands again # This probably needs a proper rewrite, but this will make it work in # the mean time. try: can_run = await command.can_run(self._ctx) except CheckFailure: can_run = False if not can_run: # skip if we don't show commands they can't run if self._only_can_run: continue strikeout = '~~' signature = self._get_command_params(command) info = f"{strikeout}**`{prefix}{signature}`**{strikeout}" # handle if the command has no docstring if command.short_doc: cat_cmds.append(f'{info}\n*{command.short_doc}*') else: cat_cmds.append(f'{info}\n*No details provided.*') # state var for if the category should be added next print_cat = 1 new_page = True for details in cat_cmds: # keep details together, paginating early if it won't fit lines_adding = len(details.split('\n')) + print_cat if paginator._linecount + lines_adding > self._max_lines: paginator._linecount = 0 new_page = True paginator.close_page() # new page so print category title again print_cat = 1 if print_cat: if new_page: paginator.add_line('') paginator.add_line(category) print_cat = 0 paginator.add_line(details) # save organised pages to session self._pages = paginator.pages
async def on_message(self, message): if _get(message.guild.id, 'toggle', 'memes') is False: return if re.search(" do(es)? ?n'?o?t work", message.content.lower()): await message.channel.send('Welcome to BE')