feat(bot): Impl global dispatch over shardtalk.

This commit is contained in:
2023-10-27 04:44:47 +03:00
parent be68c10f47
commit bbd00267fa
2 changed files with 15 additions and 0 deletions

View File

@@ -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}")

View File

@@ -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