当前位置: 首页>>代码示例>>Python>>正文


Python adminlog.AdminLogManager类代码示例

本文整理汇总了Python中pajbot.managers.adminlog.AdminLogManager的典型用法代码示例。如果您正苦于以下问题:Python AdminLogManager类的具体用法?Python AdminLogManager怎么用?Python AdminLogManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AdminLogManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

    def post(self, row_id, **options):
        args = self.post_parser.parse_args()

        try:
            new_state = int(args['new_state'])
        except (ValueError, KeyError):
            return {'error': 'Invalid `new_state` parameter.'}, 400

        with DBManager.create_session_scope() as db_session:
            row = db_session.query(Module).filter_by(id=row_id).one_or_none()

            if not row:
                return {
                        'error': 'Module with this ID not found'
                        }, 404

            if validate_module(row_id) is False:
                return {'error': 'cannot modify module'}, 400

            row.enabled = True if new_state == 1 else False
            db_session.commit()
            payload = {
                    'id': row.id,
                    'new_state': row.enabled,
                    }
            AdminLogManager.post('Module toggled',
                    options['user'],
                    'Enabled' if row.enabled else 'Disabled',
                    row.id)
            SocketClientManager.send('module.update', payload)
            return {'success': 'successful toggle', 'new_state': new_state}
开发者ID:Neclord9,项目名称:pajbot,代码行数:31,代码来源:modules.py

示例2: remove_link_whitelist

    def remove_link_whitelist(self, **options):
        message = options['message']
        bot = options['bot']
        source = options['source']

        if message:
            id = None
            try:
                id = int(message)
            except ValueError:
                pass

            link = self.db_session.query(WhitelistedLink).filter_by(id=id).one_or_none()

            if link:
                self.whitelisted_links.remove(link)
                self.db_session.delete(link)
                self.db_session.commit()
            else:
                bot.whisper(source.username, 'No link with the given id found')
                return False

            AdminLogManager.post('Whitelist link removed', source, link.domain)
            bot.whisper(source.username, 'Successfully removed whitelisted link with id {0}'.format(link.id))
        else:
            bot.whisper(source.username, 'Usage: !remove link whitelist ID')
            return False
开发者ID:Neclord9,项目名称:pajbot,代码行数:27,代码来源:linkchecker.py

示例3: level

    def level(self, **options):
        message = options['message']
        bot = options['bot']
        source = options['source']

        if message:
            msg_args = message.split(' ')
            if len(msg_args) > 1:
                username = msg_args[0].lower()
                new_level = int(msg_args[1])
                if new_level >= source.level:
                    bot.whisper(source.username, 'You cannot promote someone to the same or higher level as you ({0}).'.format(source.level))
                    return False

                # We create the user if the user didn't already exist in the database.
                with bot.users.get_user_context(username) as user:
                    old_level = user.level
                    user.level = new_level

                    log_msg = '{}\'s user level changed from {} to {}'.format(
                            user.username_raw,
                            old_level,
                            new_level)

                    bot.whisper(source.username, log_msg)

                    AdminLogManager.add_entry('Userlevel edited', source, log_msg)

                    return True

        bot.whisper(source.username, 'Usage: !level USERNAME NEW_LEVEL')
        return False
开发者ID:Neclord9,项目名称:pajbot,代码行数:32,代码来源:admincommands.py

示例4: modules_edit

    def modules_edit(module_id, **options):
        module_manager = ModuleManager(None).load(do_reload=False)
        current_module = find(lambda m: m.ID == module_id, module_manager.all_modules)

        if current_module is None:
            return render_template('admin/module_404.html'), 404

        sub_modules = []
        for module in module_manager.all_modules:
            module.db_module = None

        with DBManager.create_session_scope() as db_session:
            for db_module in db_session.query(Module):
                module = find(lambda m: m.ID == db_module.id, module_manager.all_modules)
                if module:
                    module.db_module = db_module
                    if module.PARENT_MODULE == current_module.__class__:
                        sub_modules.append(module)

            if current_module.db_module is None:
                return render_template('admin/module_404.html'), 404

            if request.method == 'POST':
                form_values = {key: value for key, value in request.form.items()}
                res = current_module.parse_settings(**form_values)
                if res is False:
                    return render_template('admin/module_404.html'), 404

                current_module.db_module.settings = json.dumps(res)
                db_session.commit()

                settings = None
                try:
                    settings = json.loads(current_module.db_module.settings)
                except (TypeError, ValueError):
                    pass
                current_module.load(settings=settings)

                payload = {
                        'id': current_module.db_module.id,
                        }

                SocketClientManager.send('module.update', payload)

                AdminLogManager.post('Module edited', options['user'], current_module.NAME)

                return render_template('admin/configure_module.html',
                        module=current_module,
                        sub_modules=sub_modules)
            else:
                settings = None
                try:
                    settings = json.loads(current_module.db_module.settings)
                except (TypeError, ValueError):
                    pass
                current_module.load(settings=settings)

                return render_template('admin/configure_module.html',
                        module=current_module,
                        sub_modules=sub_modules)
开发者ID:jardg,项目名称:pajbot,代码行数:60,代码来源:modules.py

示例5: set_title

    def set_title(bot, source, message, event, args):
        # XXX: This should be a module
        if message:
            bot.twitchapi.set_title(bot.streamer, message)
            log_msg = '{0} updated the title to "{1}"'.format(source.username_raw, message)
            bot.say(log_msg)

            AdminLogManager.add_entry('Title set', source, log_msg)
开发者ID:Neclord9,项目名称:pajbot,代码行数:8,代码来源:dispatch.py

示例6: add_command

    def add_command(bot, source, message, event, args):
        """Dispatch method for creating commands.
        Usage: !add command ALIAS [options] RESPONSE
        Multiple options available:
        --whisper/--no-whisper
        --reply/--no-reply
        --modonly/--no-modonly
        --cd CD
        --usercd USERCD
        --level LEVEL
        --cost COST
        """

        if message:
            # Make sure we got both an alias and a response
            message_parts = message.split()
            if len(message_parts) < 2:
                bot.whisper(source.username, 'Usage: !add command ALIAS [options] RESPONSE')
                return False

            options, response = bot.commands.parse_command_arguments(message_parts[1:])

            options['added_by'] = source.id

            if options is False:
                bot.whisper(source.username, 'Invalid command')
                return False

            alias_str = message_parts[0].replace('!', '').lower()
            type = 'say'
            if options['whisper'] is True:
                type = 'whisper'
            elif options['reply'] is True:
                type = 'reply'
            elif response.startswith('/me') or response.startswith('.me'):
                type = 'me'
                response = ' '.join(response.split(' ')[1:])
            elif options['whisper'] is False or options['reply'] is False:
                type = 'say'
            action = {
                'type': type,
                'message': response,
            }

            command, new_command, alias_matched = bot.commands.create_command(alias_str, action=action, **options)
            if new_command is True:
                bot.whisper(source.username, 'Added your command (ID: {command.id})'.format(command=command))

                log_msg = 'The !{} command has been created'.format(command.command.split('|')[0])
                AdminLogManager.add_entry('Command created',
                        source,
                        log_msg)
                return True

            # At least one alias is already in use, notify the user to use !edit command instead
            bot.whisper(source.username, 'The alias {} is already in use. To edit that command, use !edit command instead of !add command.'.format(alias_matched))
            return False
开发者ID:Neclord9,项目名称:pajbot,代码行数:57,代码来源:dispatch.py

示例7: get

 def get(self, banphrase_id, **options):
     with DBManager.create_session_scope() as db_session:
         banphrase = db_session.query(Banphrase).filter_by(id=banphrase_id).one_or_none()
         if banphrase is None:
             return {'error': 'Invalid banphrase ID'}, 404
         AdminLogManager.post('Banphrase removed', options['user'], banphrase.phrase)
         db_session.delete(banphrase)
         db_session.delete(banphrase.data)
         SocketClientManager.send('banphrase.remove', {'id': banphrase.id})
         return {'success': 'good job'}, 200
开发者ID:jardg,项目名称:pajbot,代码行数:10,代码来源:banphrases.py

示例8: add_link_whitelist

    def add_link_whitelist(self, **options):
        bot = options['bot']
        message = options['message']
        source = options['source']

        parts = message.split(' ')
        try:
            for link in parts:
                self.whitelist_url(link)
                AdminLogManager.post('Whitelist link added', source, link)
        except:
            log.exception('Unhandled exception in add_link')
            bot.whisper(source.username, 'Some error occurred white adding your links')
            return False

        bot.whisper(source.username, 'Successfully added your links')
开发者ID:Neclord9,项目名称:pajbot,代码行数:16,代码来源:linkchecker.py

示例9: remove_alias

    def remove_alias(bot, source, message, event, args):
        """Dispatch method for removing aliases from a command.
        Usage: !remove alias EXISTING_ALIAS_1 EXISTING_ALIAS_2"""
        if message:
            aliases = re.split('\|| ', message.lower())
            log.info(aliases)
            if len(aliases) < 1:
                bot.whisper(source.username, 'Usage: !remove alias EXISTINGALIAS')
                return False

            num_removed = 0
            commands_not_found = []
            for alias in aliases:
                if alias not in bot.commands:
                    commands_not_found.append(alias)
                    continue

                command = bot.commands[alias]

                current_aliases = command.command.split('|')
                current_aliases.remove(alias)

                if len(current_aliases) == 0:
                    bot.whisper(source.username, "{0} is the only remaining alias for this command and can't be removed.".format(alias))
                    continue

                new_aliases = '|'.join(current_aliases)
                bot.commands.edit_command(command, command=new_aliases)

                num_removed += 1
                del bot.commands[alias]
                log_msg = 'The alias {0} has been removed from {1}'.format(alias, new_aliases.split('|')[0])
                AdminLogManager.add_entry('Alias removed',
                        source,
                        log_msg)

            whisper_str = ''
            if num_removed > 0:
                whisper_str = 'Successfully removed {0} aliases.'.format(num_removed)
            if len(commands_not_found) > 0:
                whisper_str += ' Aliases {0} not found'.format(', '.join(commands_not_found))
            if len(whisper_str) > 0:
                bot.whisper(source.username, whisper_str)
        else:
            bot.whisper(source.username, 'Usage: !remove alias EXISTINGALIAS')
开发者ID:Neclord9,项目名称:pajbot,代码行数:45,代码来源:dispatch.py

示例10: permaban_command

    def permaban_command(self, **options):
        message = options['message']
        bot = options['bot']
        source = options['source']

        if message:
            username = message.split(' ')[0].strip().lower()
            with bot.users.get_user_context(username) as user:
                if user.banned:
                    bot.whisper(source.username, 'User is already permabanned.')
                    return False

                user.banned = True
                message = message.lower()
                log_msg = '{} has been permabanned'.format(user.username_raw)
                bot.whisper(source.username, log_msg)

                AdminLogManager.add_entry('Permaban added', source, log_msg)
开发者ID:Neclord9,项目名称:pajbot,代码行数:18,代码来源:permaban.py

示例11: get

    def get(self, command_id, **options):
        with DBManager.create_session_scope() as db_session:
            command = db_session.query(Command).filter_by(id=command_id).one_or_none()
            if command is None:
                return {'error': 'Invalid command ID'}, 404
            if command.level > options['user'].level:
                return {'error': 'Unauthorized'}, 403
            log_msg = 'The !{} command has been removed'.format(command.command.split('|')[0])
            AdminLogManager.add_entry('Command removed',
                    options['user'],
                    log_msg)
            db_session.delete(command.data)
            db_session.delete(command)

        if SocketClientManager.send('command.remove', {'command_id': command_id}) is True:
            return {'success': 'good job'}, 200
        else:
            return {'error': 'could not push update'}, 500
开发者ID:jardg,项目名称:pajbot,代码行数:18,代码来源:commands.py

示例12: add_alias

    def add_alias(bot, source, message, event, args):
        """Dispatch method for adding aliases to already-existing commands.
        Usage: !add alias EXISTING_ALIAS NEW_ALIAS_1 NEW_ALIAS_2 ...
        """

        if message:
            message = message.replace('!', '').lower()
            # Make sure we got both an existing alias and at least one new alias
            message_parts = message.split()
            if len(message_parts) < 2:
                bot.whisper(source.username, 'Usage: !add alias existingalias newalias')
                return False

            existing_alias = message_parts[0]
            new_aliases = re.split('\|| ', ' '.join(message_parts[1:]))
            added_aliases = []
            already_used_aliases = []

            if existing_alias not in bot.commands:
                bot.whisper(source.username, 'No command called "{0}" found'.format(existing_alias))
                return False

            command = bot.commands[existing_alias]

            for alias in set(new_aliases):
                if alias in bot.commands:
                    already_used_aliases.append(alias)
                else:
                    added_aliases.append(alias)
                    bot.commands[alias] = command

            if len(added_aliases) > 0:
                new_aliases = '{}|{}'.format(command.command, '|'.join(added_aliases))
                bot.commands.edit_command(command, command=new_aliases)

                bot.whisper(source.username, 'Successfully added the aliases {0} to {1}'.format(', '.join(added_aliases), existing_alias))
                log_msg = 'The aliases {0} has been added to {1}'.format(', '.join(added_aliases), existing_alias)
                AdminLogManager.add_entry('Alias added',
                        source,
                        log_msg)
            if len(already_used_aliases) > 0:
                bot.whisper(source.username, 'The following aliases were already in use: {0}'.format(', '.join(already_used_aliases)))
        else:
            bot.whisper(source.username, 'Usage: !add alias existingalias newalias')
开发者ID:Neclord9,项目名称:pajbot,代码行数:44,代码来源:dispatch.py

示例13: home

    def home(**options):
        latest_logs_raw = AdminLogManager.get_entries()
        cached_users = {}
        with DBManager.create_session_scope() as db_session:
            latest_logs = []
            for log in latest_logs_raw:
                log['user'] = cached_users[log['user_id']] if log['user_id'] in cached_users else db_session.query(User).filter_by(id=log['user_id']).one_or_none()
                latest_logs.append(log)

            return render_template('admin/home.html',
                    latest_logs=latest_logs)
开发者ID:Neclord9,项目名称:pajbot,代码行数:11,代码来源:home.py

示例14: remove_command

    def remove_command(bot, source, message, event, args):
        if message:
            id = None
            command = None
            try:
                id = int(message)
            except Exception:
                pass

            if id is None:
                potential_cmd = ''.join(message.split(' ')[:1]).lower().replace('!', '')
                if potential_cmd in bot.commands:
                    command = bot.commands[potential_cmd]
                    log.info('got command: {0}'.format(command))
            else:
                for key, check_command in bot.commands.items():
                    if check_command.id == id:
                        command = check_command
                        break

            if command is None:
                bot.whisper(source.username, 'No command with the given parameters found')
                return False

            if command.id == -1:
                bot.whisper(source.username, 'That command is an internal command, it cannot be removed.')
                return False

            if source.level < 2000:
                if command.action is not None and not command.action.type == 'message':
                    bot.whisper(source.username, 'That command is not a normal command, it cannot be removed by you.')
                    return False

            bot.whisper(source.username, 'Successfully removed command with id {0}'.format(command.id))
            log_msg = 'The !{} command has been removed'.format(command.command.split('|')[0])
            AdminLogManager.add_entry('Command removed',
                    source,
                    log_msg)
            bot.commands.remove_command(command)
        else:
            bot.whisper(source.username, 'Usage: !remove command (COMMAND_ID|COMMAND_ALIAS)')
开发者ID:Neclord9,项目名称:pajbot,代码行数:41,代码来源:dispatch.py

示例15: unpermaban_command

    def unpermaban_command(self, **options):
        message = options['message']
        bot = options['bot']
        source = options['source']

        if message:
            username = message.split(' ')[0].strip().lower()
            with bot.users.find_context(username) as user:
                if not user:
                    bot.whisper(source.username, 'No user with that name found.')
                    return False

                if user.banned is False:
                    bot.whisper(source.username, 'User is not permabanned.')
                    return False

                user.banned = False
                message = message.lower()
                log_msg = '{} is no longer permabanned'.format(user.username_raw)
                bot.whisper(source.username, log_msg)

                AdminLogManager.add_entry('Permaban remove', source, log_msg)
开发者ID:Neclord9,项目名称:pajbot,代码行数:22,代码来源:permaban.py


注:本文中的pajbot.managers.adminlog.AdminLogManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。