def has_permission(self, member: discord.Member) -> bool: """Does a member have permission to edit commands""" if self.everyone_permission: return True if is_admin(member) or self.bot.is_bot_admin(member): return True return False
async def clear(self, ctx: commands.Context) -> None: """Clear Mincraft server info for `ctx.guild` Args: ctx (Context): context from command call """ if is_admin(ctx.author) or self.bot.is_bot_admin(ctx.author): self.db.drop_table(ctx.guild) await self.bot.message_guild('cleared Minecraft server info', ctx.channel) else: raise commands.MissingPermissions
async def address(self, ctx: commands.Context, address: str) -> None: """Change Minecraft server name for the guild Args: ctx (Context): context from command call address (str): new ip address """ if is_admin(ctx.author) or self.bot.is_bot_admin(ctx.author): self.db.set(ctx.guild, 'address', address) await self.bot.message_guild( 'updated server address to: {}'.format(address), ctx.channel) else: raise commands.MissingPermissions
async def name(self, ctx: commands.Context, name: str) -> None: """Change Minecraft server name for the guild Args: ctx (Context): context from command call name (str): new server name """ if is_admin(ctx.author) or self.bot.is_bot_admin(ctx.author): self.db.set(ctx.guild, 'name', name) await self.bot.message_guild( 'updated server name to: {}'.format(name), ctx.channel) else: raise commands.MissingPermissions
async def whitelist(self, ctx: commands.Context, has_whitelist: bool) -> None: """Change Minecraft server name for the guild Args: ctx (Context): context from command call has_whitelist (bool): if the server has a whitelist """ if is_admin(ctx.author) or self.bot.is_bot_admin(ctx.author): self.db.set(ctx.guild, 'has_whitelist', has_whitelist) await self.bot.message_guild( 'updated server whitelist to: {}'.format(has_whitelist), ctx.channel) else: raise commands.MissingPermissions
async def admin(self, ctx: commands.Context, member: discord.Member) -> None: """Change Minecraft server name for the guild The "admin" is the guild member that will be mentioned for contact if there is a whitelist on the server. Args: ctx (Context): context from command call member (Member): member to set as Minecraft server admin """ if is_admin(ctx.author) or self.bot.is_bot_admin(ctx.author): self.db.set(ctx.guild, 'admin_id', member.id) await self.bot.message_guild( 'updated server admin to: {}'.format(member.mention), ctx.channel) else: raise commands.MissingPermissions
async def add(self, ctx: commands.Context, name: str) -> None: """Add a new game to the guild Sends a message to `ctx.channel` on success or failure. Args: ctx (Context): context from command call name (str): title of game to add """ if not (is_admin(ctx.message.author) or self.bot.is_bot_admin(ctx.message.author)): raise commands.MissingPermissions games = self._get_games(ctx.guild) if name not in games: games.append(name) self._set_games(ctx.guild, games) await self.bot.message_guild('added {}'.format(name), ctx.channel) else: await self.bot.message_guild('{} already in list'.format(name), ctx.channel)
async def remove(self, ctx: commands.Context, name: str) -> None: """Remove a game from the guild Sends a message to `ctx.channel` on success or failure. Args: ctx (Context): context from command call name (str): title of game to remove """ if not (is_admin(ctx.message.author) or self.bot.is_bot_admin(ctx.message.author)): raise commands.MissingPermissions games = self._get_games(ctx.guild) if name in games: games.remove(name) self._set_games(ctx.guild, games) await self.bot.message_guild('removed {}'.format(name), ctx.channel) else: await self.bot.message_guild('{} not in list'.format(name), ctx.channel)
def remove(self, guild: discord.Guild, member: discord.Member, name: str) -> None: """Remove a sound Requires bot admin permissions. Args: guild (Guild): guild sound is in member (Member): member issuing command name (str): name of the sound Raises: SoundNotFoundException: if the sound cannot be found MissingPermissions: if calling user lacks permissions """ if not (is_admin(member) or self.bot.is_bot_admin(member)): raise commands.MissingPermissions if name not in self.sounds(guild): raise SoundNotFoundException(f'Unable to find sound {name}') self.db.clear(guild, name)
async def kick(self, member: discord.Member, channel: discord.TextChannel, guild: discord.Guild, message: str = None) -> bool: """Kick member from guild Args: member (Member): member to kick channel (Channel): channel to send notification messages to guild (Guild): guild member belongs to to be kicked from message (str): optional message to sent to channel when the member is kicked Returns: `True` if kick was successful """ if is_admin(member): if message is None: message = '' message += ('Failed to kick {}. Your cognizance is highly ' 'acknowledged.'.format(member.mention)) await self.bot.message_guild(message, channel) return False try: await guild.kick(member) except Exception as e: logger.warning('Failed to kick {}. Caught exception: ' '{}'.format(member, e)) return False if message is not None: message += 'Press F to pay respects.' await self.bot.message_guild(message, channel, react=F_EMOTE) return True
async def yeet(self, ctx: commands.Context, member: discord.Member) -> None: """Kicks `member` from `ctx.guild` The caller of the command (i.e. `ctx.message.author`) must have kick permission in the guild. Args: ctx (Context): context from command call member (Member): member to yeet """ if not ctx.message.author.guild_permissions.administrator: raise commands.MissingPermissions elif member.bot: msg = '{}, you cannot yeet a bot.'.format( ctx.message.author.mention) await self.bot.message_guild(msg, ctx.channel) else: if is_admin(member): msg = ('Failed to kick {}. Your cognizance is highly ' 'acknowledged.'.format(member.mention)) await self.bot.message_guild(msg, ctx.channel) else: await ctx.guild.kick(member)