示例#1
0
class ActionConverter(commands.Converter):
    valid_actions = ', '.join('`{0}`'.format(act.name)
                              for act in SecurityAction)

    async def convert(self, ctx, action):
        try:
            value = SecurityAction[action.upper()]
        except KeyError:
            raise commands.BadArgument(
                '\'{0}\' is not a valid action. Valid actions are {1}'.format(
                    action, self.valid_actions))

        return value


reason_converter = MaxLengthConverter(1024)
count_converter = RangeConverter(8, 24)
interval_converter = RangeConverter(8, 24)


class Moderation(AceMixin, commands.Cog):
    '''Moderation commands to make your life simpler.'''
    def __init__(self, bot):
        super().__init__(bot)

        self.config = ConfigTable(bot,
                                  'mod_config',
                                  'guild_id',
                                  record_class=SecurityConfigRecord)
        self.event_timer = EventTimer(bot, 'event_complete')
示例#2
0
文件: roles.py 项目: spiiralol/AceBot
                MOVEUP_EMOJI, MOVEDOWN_EMOJI, EDIT_EMOJI, DEL_EMOJI,
                ABORT_EMOJI, SAVE_EMOJI)


class SelectorEmojiConverter(EmojiConverter):
    async def convert(self, ctx, argument):
        argument = await super().convert(ctx, argument)

        if argument in (role.emoji for role in ctx.head.selector.roles):
            raise commands.CommandError(
                'This emoji already exists in this selector.')

        return argument


role_title_converter = MaxLengthConverter(199)
role_desc_converter = MaxLengthConverter(1024)
selector_title_converter = MaxLengthConverter(256)
selector_desc_converter = MaxLengthConverter(1024)


class SelectorInlineConverter(commands.Converter):
    async def convert(self, ctx, argument):
        lowered = argument.lower()
        if lowered in ('yes', 'y', 'true', 't', '1', 'enable', 'on'):
            return True
        elif lowered in ('no', 'n', 'false', 'f', '0', 'disable', 'off'):
            return False
        else:
            raise commands.CommandError(
                'Input could not be interpreted as boolean.')