feat(bot): Impl global dispatch over shardtalk.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import logging
|
||||
from typing import Optional
|
||||
from collections import defaultdict
|
||||
from weakref import WeakValueDictionary
|
||||
@@ -19,6 +20,8 @@ from .lion_member import MemberConfig
|
||||
from .lion_user import UserConfig
|
||||
from .hooks import HookedChannel
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class keydefaultdict(defaultdict):
|
||||
def __missing__(self, key):
|
||||
@@ -127,3 +130,7 @@ class CoreCog(LionCog):
|
||||
@log_wrap(action='Update shard guilds')
|
||||
async def shard_update_guilds(self, guild):
|
||||
await self.shard_data.update(guild_count=len(self.bot.guilds))
|
||||
|
||||
@LionCog.listener('on_ping')
|
||||
async def handle_ping(self, *args, **kwargs):
|
||||
logger.info(f"Received ping with args {args}, kwargs {kwargs}")
|
||||
|
||||
@@ -56,6 +56,14 @@ class LionBot(Bot):
|
||||
self._locks = WeakValueDictionary()
|
||||
self._running_events = set()
|
||||
|
||||
self._talk_global_dispatch = app_ipc.register_route('dispatch')(self._handle_global_dispatch)
|
||||
|
||||
async def _handle_global_dispatch(self, event_name: str, *args, **kwargs):
|
||||
self.dispatch(event_name, *args, **kwargs)
|
||||
|
||||
async def global_dispatch(self, event_name: str, *args, **kwargs):
|
||||
await self._talk_global_dispatch(event_name, *args, **kwargs).broadcast(except_self=False)
|
||||
|
||||
async def _monitor_status(self):
|
||||
if self.is_closed():
|
||||
level = StatusLevel.ERRORED
|
||||
|
||||
Reference in New Issue
Block a user