pubsub: remove flags from dispatchers

This commit is contained in:
Luna 2021-07-14 15:51:36 -03:00
parent f3af9b5f11
commit 7757c837d0
2 changed files with 4 additions and 21 deletions

View File

@ -18,14 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
from typing import List from typing import List
from dataclasses import dataclass
from quart import current_app as app from quart import current_app as app
from logbook import Logger from logbook import Logger
from litecord.enums import ChannelType, EVENTS_TO_INTENTS from litecord.enums import ChannelType, EVENTS_TO_INTENTS
from litecord.utils import index_by_func from litecord.utils import index_by_func
from .dispatcher import DispatcherWithFlags, GatewayEvent from .dispatcher import DispatcherWithState, GatewayEvent
log = Logger(__name__) log = Logger(__name__)
@ -44,14 +43,7 @@ def gdm_recipient_view(orig: dict, user_id: int) -> dict:
return data return data
@dataclass class ChannelDispatcher(DispatcherWithState[int, str, GatewayEvent, List[str]]):
class ChannelFlags:
typing: bool
class ChannelDispatcher(
DispatcherWithFlags[int, str, GatewayEvent, List[str], ChannelFlags]
):
"""Main channel Pub/Sub logic. Handles both Guild, DM, and Group DM channels.""" """Main channel Pub/Sub logic. Handles both Guild, DM, and Group DM channels."""
async def dispatch(self, channel_id: int, event: GatewayEvent) -> List[str]: async def dispatch(self, channel_id: int, event: GatewayEvent) -> List[str]:

View File

@ -18,24 +18,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
from typing import List from typing import List
from dataclasses import dataclass
from quart import current_app as app from quart import current_app as app
from logbook import Logger from logbook import Logger
from .dispatcher import DispatcherWithFlags, GatewayEvent from .dispatcher import DispatcherWithState, GatewayEvent
from .channel import ChannelFlags
from litecord.gateway.state import GatewayState from litecord.gateway.state import GatewayState
from litecord.enums import EVENTS_TO_INTENTS from litecord.enums import EVENTS_TO_INTENTS
log = Logger(__name__) log = Logger(__name__)
@dataclass
class GuildFlags(ChannelFlags):
presence: bool
def can_dispatch(event_type, event_data, state) -> bool: def can_dispatch(event_type, event_data, state) -> bool:
# If we're sending to the same user for this kind of event, # If we're sending to the same user for this kind of event,
# bypass event logic (always send) # bypass event logic (always send)
@ -52,9 +45,7 @@ def can_dispatch(event_type, event_data, state) -> bool:
return state_has_intent return state_has_intent
class GuildDispatcher( class GuildDispatcher(DispatcherWithState[int, str, GatewayEvent, List[str]]):
DispatcherWithFlags[int, str, GatewayEvent, List[str], GuildFlags]
):
"""Guild backend for Pub/Sub.""" """Guild backend for Pub/Sub."""
async def sub_user(self, guild_id: int, user_id: int) -> List[GatewayState]: async def sub_user(self, guild_id: int, user_id: int) -> List[GatewayState]: