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


Python PluginManager.get_all方法代码示例

本文整理汇总了Python中plugin_manager.PluginManager.get_all方法的典型用法代码示例。如果您正苦于以下问题:Python PluginManager.get_all方法的具体用法?Python PluginManager.get_all怎么用?Python PluginManager.get_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在plugin_manager.PluginManager的用法示例。


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

示例1: Mee6

# 需要导入模块: from plugin_manager import PluginManager [as 别名]
# 或者: from plugin_manager.PluginManager import get_all [as 别名]
class Mee6(discord.Client):
    def __init__(self, *args, **kwargs):
        discord.Client.__init__(self, *args, **kwargs)
        self.redis_url = kwargs.get('redis_url')
        self.db = Db(self.redis_url)
        self.plugin_manager = PluginManager(self)
        self.plugin_manager.load_all()
        self.last_messages = []

    async def on_ready(self):
        with open('welcome_ascii.txt') as f:
            print(f.read())
        self.add_all_servers()
        discord.utils.create_task(self.heartbeat(5), loop=self.loop)
        discord.utils.create_task(self.update_stats(60), loop=self.loop)
        await self.change_status(game=discord.Game(name='http://mee6.xyz'))

    def add_all_servers(self):
        log.debug('Syncing servers and db')
        self.db.redis.delete('servers')
        for server in self.servers:
            log.debug('Adding server {}\'s id to db'.format(server.id))
            self.db.redis.sadd('servers', server.id)

    @asyncio.coroutine
    def send_message(self, *args, **kwargs):
        dest = args[0]
        if hasattr(args[0], 'server'):
            dest = args[0].server
        if isinstance(args[0], discord.Member):
            dest = args[0]
        log.info('[email protected]{} >> {}'.format(dest.name,args[1].replace('\n', '~')))
        yield from super().send_message(*args, **kwargs)

    @asyncio.coroutine
    def on_server_join(self, server):
        log.info('Joined {} server : {} !'.format(server.owner.name, server.name))
        log.debug('Adding server {}\'s id to db'.format(server.id))
        self.db.redis.sadd('servers', server.id)
        self.db.redis.set('server:{}:name'.format(server.id), server.name)
        if server.icon:
            self.db.redis.set('server:{}:icon'.format(server.id), server.icon)

    @asyncio.coroutine
    def on_server_remove(self, server):
        log.info('Leaving {} server : {} !'.format(server.owner.name, server.name))
        log.debug('Removing server {}\'s id from the db'.format(server.id))
        self.db.redis.srem('servers', server.id)

    @asyncio.coroutine
    def heartbeat(self, interval):
        while self.is_logged_in:
            self.db.redis.set('heartbeat', 1, ex=interval)
            yield from asyncio.sleep(0.9 * interval)

    @asyncio.coroutine
    def update_stats(self, interval):
        while self.is_logged_in:
            # Total members and online members
            members = list(self.get_all_members())
            online_members = filter(lambda m: m.status is discord.Status.online, members)
            online_members = list(online_members)
            self.db.redis.set('mee6:stats:online_members', len(online_members))
            self.db.redis.set('mee6:stats:members', len(members))

            # Last messages
            for index, timestamp in enumerate(self.last_messages):
                if timestamp + interval < time():
                    self.last_messages.pop(index)
            self.db.redis.set('mee6:stats:last_messages', len(self.last_messages))

            yield from asyncio.sleep(interval)

    @asyncio.coroutine
    def _run_plugin_event(self, plugin, event, *args, **kwargs):
        # A modified coro that is based on Client._run_event
        try:
            yield from getattr(plugin, event)(*args, **kwargs)
        except asyncio.CancelledError:
            pass
        except Exception:
            try:
                yield from self.on_error(event, *args, **kwargs)
            except asyncio.CancelledError:
                pass

    async def on_message(self, message):
        mee6_server_id = "159962941502783488"
        update_channel_id = "160784396679380992"
        if not hasattr(message, 'server'):
            return
        if (message.server.id, message.channel.id) == (mee6_server_id, update_channel_id):
            owners = set(server.owner for server in self.servers)
            for owner in owners:
                await self.send_message(
                    owner,
                    message.content
                )

    def dispatch(self, event, *args, **kwargs):
#.........这里部分代码省略.........
开发者ID:spongecattle,项目名称:mee6,代码行数:103,代码来源:mee6.py


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