insurgency.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:BigBrotherBot-For-UrT43 作者: ptitbigorneau 项目源码 文件源码
def patch_b3_admin_plugin(self):
        """
        Monkey patches the admin plugin
        """
        def parse_map_parameters(this, data, client):
            """
            Method that parses a command parameters to extract map and gamemode.
            Expecting one or two parameters separated by a space.
            <map> <gamemode>
            """
            parts = data.split()
            if len(parts) < 2:
                gamemode_data = ''
            else:
                gamemode_data = parts[1]
            map_data = parts[0]

            return map_data, gamemode_data

        # Monkey patch the cmd_map method of the loaded AdminPlugin instance
        # to require 2nd parameter which is the game mode
        def new_cmd_map(this, data, client, cmd=None):
            """
            <map> <gamemode> - switch current map. Specify a gamemode by separating
            them from the map name with a space
            """
            if not data:
                allavailablemaps = this.console.getAllAvailableMaps()
                maplist = ''
                for m in allavailablemaps:
                    maplist = maplist + ', ' + m
                client.message("Full list of maps on the server" + maplist)
                client.message("PVP Gametypes are: ambush, firefight, flashpoint, infiltrate, occupy, push, skirmish, "
                               "strike")
                client.message("Coop Gametypes are: checkpoint, outpost, hunt, survival")
                client.message('For more help, type !help map')
                return

            parsed_data = this.parse_map_parameters(data, client)
            map_id, gamemode_id = parsed_data

            suggestions = this.console.changeMap(map_id, gamemode_id)
            if type(suggestions) == list:
                client.message('do you mean : %s ?' % ', '.join(suggestions))

        adminPlugin = self.getPlugin('admin')
        adminPlugin.parse_map_parameters = new.instancemethod(parse_map_parameters, adminPlugin)
        command = adminPlugin._commands['map']
        command.func = new.instancemethod(new_cmd_map, adminPlugin)
        command.help = new_cmd_map.__doc__.strip()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号