From 7757c837d0e5a4e240baf172604a2451136d39a6 Mon Sep 17 00:00:00 2001 From: Luna Date: Wed, 14 Jul 2021 15:51:36 -0300 Subject: [PATCH] pubsub: remove flags from dispatchers --- litecord/pubsub/channel.py | 12 ++---------- litecord/pubsub/guild.py | 13 ++----------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/litecord/pubsub/channel.py b/litecord/pubsub/channel.py index ff0b7c1..9db8d7b 100644 --- a/litecord/pubsub/channel.py +++ b/litecord/pubsub/channel.py @@ -18,14 +18,13 @@ along with this program. If not, see . """ from typing import List -from dataclasses import dataclass from quart import current_app as app from logbook import Logger from litecord.enums import ChannelType, EVENTS_TO_INTENTS from litecord.utils import index_by_func -from .dispatcher import DispatcherWithFlags, GatewayEvent +from .dispatcher import DispatcherWithState, GatewayEvent log = Logger(__name__) @@ -44,14 +43,7 @@ def gdm_recipient_view(orig: dict, user_id: int) -> dict: return data -@dataclass -class ChannelFlags: - typing: bool - - -class ChannelDispatcher( - DispatcherWithFlags[int, str, GatewayEvent, List[str], ChannelFlags] -): +class ChannelDispatcher(DispatcherWithState[int, str, GatewayEvent, List[str]]): """Main channel Pub/Sub logic. Handles both Guild, DM, and Group DM channels.""" async def dispatch(self, channel_id: int, event: GatewayEvent) -> List[str]: diff --git a/litecord/pubsub/guild.py b/litecord/pubsub/guild.py index af36417..995837f 100644 --- a/litecord/pubsub/guild.py +++ b/litecord/pubsub/guild.py @@ -18,24 +18,17 @@ along with this program. If not, see . """ from typing import List -from dataclasses import dataclass from quart import current_app as app from logbook import Logger -from .dispatcher import DispatcherWithFlags, GatewayEvent -from .channel import ChannelFlags +from .dispatcher import DispatcherWithState, GatewayEvent from litecord.gateway.state import GatewayState from litecord.enums import EVENTS_TO_INTENTS log = Logger(__name__) -@dataclass -class GuildFlags(ChannelFlags): - presence: bool - - def can_dispatch(event_type, event_data, state) -> bool: # If we're sending to the same user for this kind of event, # bypass event logic (always send) @@ -52,9 +45,7 @@ def can_dispatch(event_type, event_data, state) -> bool: return state_has_intent -class GuildDispatcher( - DispatcherWithFlags[int, str, GatewayEvent, List[str], GuildFlags] -): +class GuildDispatcher(DispatcherWithState[int, str, GatewayEvent, List[str]]): """Guild backend for Pub/Sub.""" async def sub_user(self, guild_id: int, user_id: int) -> List[GatewayState]: