コード例 #1
0
ファイル: help_controller.py プロジェクト: Nepherius/Mangopie
    def help_list_cmd(self, channel, sender, reply, args):
        data = self.db.client['command_config'].find().sort([('module', 1),
                                                             ('command', 1)])
        blob = ""
        current_group = ""
        current_module = ""
        current_command = ""
        access_level = self.access_manager.get_access_level(sender.char_id)
        for row in data:
            if access_level[
                    "level"] > self.access_manager.get_access_level_by_label(
                        row['access_level'])["level"]:
                continue
            parts = row['module'].split(".")
            group = parts[0]
            module = parts[1]

            if group != current_group:
                current_group = group
                blob += "\n\n<header2>" + current_group + "<end>"

            if module != current_module:
                current_module = module
                blob += "\n" + module + ":"

            if row['command'] != current_command:
                current_command = row['command']
                blob += " " + self.text.make_chatcmd(
                    row['command'], "/tell <myname> help " + row['command'])

        reply(ChatBlob("Help (main)", blob))
コード例 #2
0
    def config_cmd_show_cmd(self, channel, sender, reply, args):
        cmd_name = args[1].lower()
        command_str, sub_command_str = self.command_manager.get_command_key_parts(
            cmd_name)

        blob = ""
        for command_channel, channel_label in self.command_manager.channels.items(
        ):
            cmds = self.command_manager.get_command_configs(
                command=command_str,
                sub_command=sub_command_str,
                channel=command_channel,
                enabled=None)
            cmd_configs = list(cmds)
            if len(cmd_configs) > 0:
                cmd_config = cmd_configs[0]
                if cmd_config['enabled'] == 1:
                    status = "<green>Enabled<end>"
                else:
                    status = "<red>Disabled<end>"

                blob += "<header2>%s<end> %s (Access Level: %s)\n" % (
                    channel_label, status,
                    cmd_config['access_level'].capitalize())

                # show status config
                blob += "Status:"
                enable_link = self.text.make_chatcmd(
                    "Enable", "/tell <myname> config cmd %s enable %s" %
                    (cmd_name, command_channel))
                disable_link = self.text.make_chatcmd(
                    "Disable", "/tell <myname> config cmd %s disable %s" %
                    (cmd_name, command_channel))

                blob += "  " + enable_link + "  " + disable_link

                # show access level config
                blob += "\nAccess Level:"
                for access_level in self.access_manager.access_levels:
                    # skip "None" access level
                    if access_level["level"] == 0:
                        continue

                    label = access_level["label"]
                    link = self.text.make_chatcmd(
                        label.capitalize(),
                        "/tell <myname> config cmd %s access_level %s %s" %
                        (cmd_name, command_channel, label))
                    blob += "  " + link
                blob += "\n"
            blob += "\n\n"

        if blob:
            # include help text
            blob += "\n\n".join(
                map(lambda handler: handler["help"],
                    self.command_manager.get_handlers(cmd_name)))

        reply(ChatBlob("Command (%s)" % cmd_name, blob))
コード例 #3
0
    def alias_list_cmd(self, channel, sender, reply, args):
        blob = ""
        data = self.command_alias_manager.get_enabled_aliases()
        count = 0
        for row in data:
            count += 1
            blob += row['alias'] + " - " + row['command'] + "\n"

        reply(ChatBlob("Aliases (%d)" % count, blob))
コード例 #4
0
    def config_module_list_cmd(self, channel, sender, reply, args):
        module = args[1].lower()

        blob = ""

        data = self.db.client['settings'].find({
            'module': module
        }).sort('name', 1)
        data = list(data)
        if data:
            blob += "<header2>Settings<end>\n"
            for row in data:
                setting = self.setting_manager.get(row['name'])
                blob += setting.get_description(
                ) + ": " + self.text.make_chatcmd(
                    setting.get_display_value(),
                    "/tell <myname> config setting " + row['name']) + "\n"

        data = self.db.client['command_config'].find({
            'module': module
        }, {
            '_id': 0,
            'channel': 0
        }).sort('command', 1)
        d = list(data)
        data = [i for n, i in enumerate(d) if i not in d[n + 1:]]
        if data:
            blob += "\n<header2>Commands<end>\n"
            for row in data:
                command_key = self.command_manager.get_command_key(
                    row['command'], row['sub_command'])
                blob += self.text.make_chatcmd(
                    command_key,
                    "/tell <myname> config cmd " + command_key) + "\n"

        data = self.db.client['event_config'].find({
            'module': module
        }).sort([('event_type', 1), ('handler', 1)])
        data = list(data)
        if data:
            blob += "\n<header2>Events<end>\n"
            for row in data:
                event_type_key = self.event_manager.get_event_type_key(
                    row['event_type'], row['event_sub_type'])
                blob += row['event_type'] + " - " + row['description']
                blob += " " + self.text.make_chatcmd(
                    "On", "/tell <myname> config event " + event_type_key +
                    " " + row['handler'] + " enable")
                blob += " " + self.text.make_chatcmd(
                    "Off", "/tell <myname> config event " + event_type_key +
                    " " + row['handler'] + " disable")
                blob += "\n"

        if blob:
            reply(ChatBlob("Module (" + module + ")", blob))
        else:
            reply("Could not find module <highlight>%s<end>" % module)
コード例 #5
0
ファイル: alts_controller.py プロジェクト: Nepherius/Mangopie
    def alts_list_cmd(self, channel, sender, reply, args):
        count = 0
        alts = self.alts_manager.get_alts(sender.char_id)
        blob = ""

        for alt in alts:
            count += 1
            blob += "<highlight>%s<end> (%s/<green>%s<end>) %s %s%s\n" % (
                alt['char'][0]['name'], alt['char'][0]['level'], alt['char'][0]['ai_level'], alt['char'][0]['faction'],
                alt['char'][0]['profession'], self.get_alt_status(alt["status"]))

        reply(ChatBlob("Alts for %s (%d)" % (sender.name, count), blob))
コード例 #6
0
    def config_setting_show_cmd(self, channel, sender, reply, args):
        setting_name = args[1].lower()

        blob = ""

        setting = self.setting_manager.get(setting_name)

        if setting:
            blob += "Current Value: <highlight>%s<end>\n" % str(
                setting.get_display_value())
            blob += "Description: <highlight>%s<end>\n\n" % setting.get_description(
            )
            blob += setting.get_display()
            reply(ChatBlob("Setting (%s)" % setting_name, blob))
        else:
            reply("Could not find setting <highlight>%s<end>." % setting_name)
コード例 #7
0
ファイル: alts_controller.py プロジェクト: Nepherius/Mangopie
    def alts_list_other_cmd(self, channel, sender, reply, args):
        name = args[0].capitalize()
        char_id = self.character_manager.resolve_char_to_id(name)
        if not char_id:
            reply("Could not find character <highlight>%s<end>." % name)
            return

        alts = self.alts_manager.get_alts(char_id)
        count = 0
        blob = ""
        for alt in alts:
            count += 1
            blob += "<highlight>%s<end> (%d/<green>%d<end>) %s %s\n" % (
                alt['char'][0]['name'], alt['char'][0]['level'], alt['char'][0]['ai_level'], alt['char'][0]['faction'],
                alt['char'][0]['profession'])

        reply(ChatBlob("Alts for %s (%d)" % (name, count), blob))
コード例 #8
0
    def whois_cmd(self, channel, sender, reply, args):
        char_name = args[1].capitalize()
        char_info = self.pork_manager.get_character_info(char_name)
        char_id = self.character_manager.resolve_char_to_id(char_name)
        if char_info:
            blob = "Name: %s\n" % self.get_full_name(char_info)
            blob += "Profession: %s\n" % char_info['profession']
            blob += "Faction: %s\n" % char_info['faction']
            blob += "Breed: %s\n" % char_info['breed']
            blob += "Gender: %s\n" % char_info['gender']
            blob += "Level: %d\n" % char_info['level']
            blob += "AI Level: %d\n" % char_info['ai_level']
            if char_info['org_id']:
                blob += "Org: %s (%d)\n" % (char_info['org_name'],
                                            char_info['org_id'])
                blob += "Org Rank: %s (%d)\n" % (char_info['org_rank_name'],
                                                 char_info['org_rank_id'])
            else:
                blob += "Org: &lt;None&gt;\n"
                blob += "Org Rank: &lt;None&gt;\n"
            blob += "Head Id: %d\n" % char_info['head_id']
            blob += "PVP Rating: %d\n" % char_info['pvp_rating']
            blob += "PVP Title: %s\n" % char_info['pvp_title']
            blob += "Character Id: %d\n" % char_info['char_id']
            blob += "Source: %s\n" % char_info['source']
            more_info = self.text.paginate("More Info", blob, 5000, 1)[0]

            msg = self.format_char_info(char_info) + " " + more_info
            reply(msg)
        elif char_id:
            blob = "<notice>Note: Could not retrieve detailed info for character.<end>\n\n"
            blob += "Name: <highlight>%s<end>\n" % char_name
            blob += "Character ID: <highlight>%d<end>" % char_id
            reply(ChatBlob("Basic Info for %s" % char_name, blob))
        else:
            reply("Could not find info for character <highlight>%s<end>." %
                  char_name)
コード例 #9
0
 def format_help_text(self, topic, help_text):
     return ChatBlob("Help (" + topic + ")", help_text)
コード例 #10
0
    def config_list_cmd(self, channel, sender, reply, args):
        pipeline = [{
            '$project': {
                'module': 1,
                'count_enabled': {
                    '$cond': {
                        'if': {
                            '$eq': ['$enabled', 1]
                        },
                        'then': 1,
                        'else': 0
                    }
                },
                'count_disabled': {
                    '$cond': {
                        'if': {
                            '$eq': ['$enabled', 0]
                        },
                        'then': 1,
                        'else': 0
                    }
                }
            }
        }, {
            '$group': {
                '_id': '$module',
                'count_enabled': {
                    '$sum': '$count_enabled'
                },
                'count_disabled': {
                    '$sum': '$count_disabled'
                }
            }
        }, {
            '$sort': {
                '_id': 1
            }
        }]
        cmd_config = self.db.client['command_config'].aggregate(pipeline)
        event_config = self.db.client['event_config'].aggregate(pipeline)
        settings = self.db.client['settings'].aggregate(pipeline)

        final_list = []
        lists = [cmd_config, event_config, settings]
        for lst in lists:
            for dct in lst:
                id_to_lookup = dct['_id']
                found_duplicate_flag = 0
                for final_dict in final_list:
                    if final_dict['_id'] == id_to_lookup:
                        found_duplicate_flag = 1
                        final_dict['count_enabled'] += dct['count_enabled']
                        final_dict['count_disabled'] += dct['count_disabled']
                        break
                if found_duplicate_flag == 0:
                    final_list.append(dct)
        count = 0
        blob = ""
        current_group = ""
        for row in sorted(final_list, key=itemgetter('_id')):
            count += 1
            parts = row['_id'].split(".")
            group = parts[0]
            module = parts[1]
            if group != current_group:
                current_group = group
                blob += "\n<header2>" + current_group + "<end>\n"

            blob += self.text.make_chatcmd(
                module, "/tell <myname> config mod " + row['_id']) + " "
            if row['count_enabled'] > 0 and row['count_disabled'] > 0:
                blob += "<yellow>Partial<end>"
            elif row['count_disabled'] == 0:
                blob += "<green>Enabled<end>"
            else:
                blob += "<red>Disabled<end>"
            blob += "\n"

        reply(ChatBlob("Config (%d)" % count, blob))