async def config(self, ctx): """Print the baduser configuration.""" server = ctx.guild output = 'Punishment roles:\n' for role_id in self.settings.getPunishmentRoles(server.id): try: role = get_role_from_id(self.bot, server, role_id) output += '\t' + role.name + '\n' except Exception as e: pass # Role was deleted output += '\nPositive roles:\n' for role_id in self.settings.getPositiveRoles(server.id): try: role = get_role_from_id(self.bot, server, role_id) output += '\t' + role.name + '\n' except Exception as e: pass # Role was deleted output += '\nNeutral roles:\n' for role_id in self.settings.getNeutralRoles(server.id): try: role = get_role_from_id(self.bot, server, role_id) output += '\t' + role.name + '\n' except Exception as e: pass # Role was deleted output += '\nStrike contents are private' output += '\nStrike existence is ' + \ ('private' if self.settings.getStrikesPrivate(server.id) else 'public') await ctx.send(box(output))
async def checkCC(self, message): if len(message.content) < 2 or isinstance(message.channel, discord.abc.PrivateChannel): return guild = message.guild prefix = await self.get_prefix(message) if not prefix: return # MEME CODE role_id = self.settings.getPrivileged(guild.id) if role_id is not None: role = get_role_from_id(self.bot, guild, role_id) if role not in message.author.roles: return # MEME CODE if guild.id in self.c_commands and not message.author.bot: cmdlist = self.c_commands[guild.id] cmd = message.content[len(prefix):] if cmd in cmdlist.keys(): cmd = cmdlist[cmd] cmd = self.format_cc(cmd, message) await message.channel.send(cmd) elif cmd.lower() in cmdlist.keys(): cmd = cmdlist[cmd.lower()] cmd = self.format_cc(cmd, message) await message.channel.send(cmd)
def roles_and_amounts(self, server: discord.Guild, check_name: str): for role_id, role_config in self.settings.roles(server.id).items(): amount = role_config[check_name] try: role = rpadutils.get_role_from_id(self.bot, server, role_id) except: role = None yield role_id, role, amount
async def printconfig(self, ctx): """Print the configuration for the server.""" server = ctx.guild server_id = server.id msg = 'Config:' announce_channel = self.get_announce_channel(server_id) msg += '\n\tannounce_channel: {}'.format( announce_channel.name if announce_channel else '<unset>') msg += '\n\tauto_grant: {}'.format(self.settings.auto_grant(server_id)) msg += '\n\tmessage_cap: {}'.format( self.settings.message_cap(server_id)) msg += '\n\tserver_point_cap: {}'.format( self.settings.server_point_cap(server_id)) msg += '\n\tgrant_lookback: {}'.format( self.settings.grant_lookback(server_id)) msg += '\n\tremove_lookback: {}'.format( self.settings.remove_lookback(server_id)) msg += '\n\n' msg += 'Acceptability:' msg += '\n\tignore_commands: {}'.format( self.settings.ignore_commands(server_id)) msg += '\n\tignore_emoji: {}'.format( self.settings.ignore_emoji(server_id)) msg += '\n\tignore_mentions: {}'.format( self.settings.ignore_mentions(server_id)) msg += '\n\tignore_room_codes: {}'.format( self.settings.ignore_room_codes(server_id)) msg += '\n\tmin_length: {}'.format(self.settings.min_length(server_id)) msg += '\n\tmin_words: {}'.format(self.settings.min_words(server_id)) msg += '\n\n' msg += 'Ignored Users:' for user_id in self.settings.blacklist(server_id): member = server.get_member(int(user_id)) msg += '\n\t{} ({})'.format(member.name if member else 'unknown', user_id) msg += '\n\n' msg += 'Channels and max ppd:' for channel_id, config in self.settings.channels(server_id).items(): channel = self.bot.get_channel(int(channel_id)) msg += '\n\t{} : {}'.format( channel.name if channel else channel_id, config['max_ppd']) msg += '\n\n' msg += 'Roles:' for role_id, config in self.settings.roles(server_id).items(): try: role = rpadutils.get_role_from_id(self.bot, server, role_id) role_name = role.name except: role_name = role_id msg += '\n\t{}'.format(role_name) msg += '\n\t\tremove_amount : {}'.format(config['remove_amount']) msg += '\n\t\twarn_amount : {}'.format(config['warn_amount']) msg += '\n\t\tgrant_amount : {}'.format(config['grant_amount']) for page in pagify(msg): await ctx.send(box(page))
async def ensure_user_streaming_role(self, server, streamer_role_id: discord.Role, user: discord.Member): user_is_playing = self.is_playing(user) try: streamer_role = get_role_from_id(self.bot, server, streamer_role_id) user_has_streamer_role = streamer_role in user.roles if user_is_playing and not user_has_streamer_role: await user.add_roles(streamer_role) elif not user_is_playing and user_has_streamer_role: await user.remove_roles(streamer_role) except Exception as ex: pass
async def _on_voice_state_update(self, member, before, after): guild = member.guild guild_id = guild.id channel_id = (before.channel or after.channel).id channel_roles = self.settings.get_channel_roles(guild_id) if channel_id not in channel_roles: return role_id = channel_roles[channel_id] try: role = get_role_from_id(self.bot, guild, role_id) if member.voice: await member.add_roles(role) else: await member.remove_roles(role) except Exception as ex: print('voicerole failure {} {} {}'.format(guild_id, channel_id, role_id)) print(ex)