mirror of https://gitlab.com/litecord/litecord.git
pubsub.guild: replace flags with intents checking
This commit is contained in:
parent
0119044a6c
commit
c03ed978ca
|
|
@ -26,6 +26,7 @@ from logbook import Logger
|
||||||
from .dispatcher import DispatcherWithFlags, GatewayEvent
|
from .dispatcher import DispatcherWithFlags, GatewayEvent
|
||||||
from .channel import ChannelFlags
|
from .channel import ChannelFlags
|
||||||
from litecord.gateway.state import GatewayState
|
from litecord.gateway.state import GatewayState
|
||||||
|
from litecord.enums import Intents
|
||||||
|
|
||||||
log = Logger(__name__)
|
log = Logger(__name__)
|
||||||
|
|
||||||
|
|
@ -35,6 +36,57 @@ class GuildFlags(ChannelFlags):
|
||||||
presence: bool
|
presence: bool
|
||||||
|
|
||||||
|
|
||||||
|
EVENTS_TO_INTENTS = {
|
||||||
|
"GUILD_CREATE": Intents.GUILDS,
|
||||||
|
"GUILD_UPDATE": Intents.GUILDS,
|
||||||
|
"GUILD_DELETE": Intents.GUILDS,
|
||||||
|
"GUILD_ROLE_CREATE": Intents.GUILDS,
|
||||||
|
"GUILD_ROLE_UPDATE": Intents.GUILDS,
|
||||||
|
"GUILD_ROLE_DELETE": Intents.GUILDS,
|
||||||
|
"CHANNEL_CREATE": Intents.GUILDS,
|
||||||
|
"CHANNEL_UPDATE": Intents.GUILDS,
|
||||||
|
"CHANNEL_DELETE": Intents.GUILDS,
|
||||||
|
"CHANNEL_PINS_UPDATE": Intents.GUILDS,
|
||||||
|
# --- threads not supported --
|
||||||
|
"THREAD_CREATE": Intents.GUILDS,
|
||||||
|
"THREAD_UPDATE": Intents.GUILDS,
|
||||||
|
"THREAD_DELETE": Intents.GUILDS,
|
||||||
|
"THREAD_LIST_SYNC": Intents.GUILDS,
|
||||||
|
"THREAD_MEMBER_UPDATE": Intents.GUILDS,
|
||||||
|
"THREAD_MEMBERS_UPDATE": Intents.GUILDS,
|
||||||
|
# --- stages not supported --
|
||||||
|
"STAGE_INSTANCE_CREATE": Intents.GUILDS,
|
||||||
|
"STAGE_INSTANCE_UPDATE": Intents.GUILDS,
|
||||||
|
"STAGE_INSTANCE_DELETE": Intents.GUILDS,
|
||||||
|
"GUILD_MEMBER_ADD": Intents.GUILD_MEMBERS,
|
||||||
|
"GUILD_MEMBER_UPDATE": Intents.GUILD_MEMBERS,
|
||||||
|
"GUILD_MEMBER_REMOVE": Intents.GUILD_MEMBERS,
|
||||||
|
# --- threads not supported --
|
||||||
|
"THREAD_MEMBERS_UPDATE ": Intents.GUILD_MEMBERS,
|
||||||
|
"GUILD_BAN_ADD": Intents.GUILD_BANS,
|
||||||
|
"GUILD_BAN_REMOVE": Intents.GUILD_BANS,
|
||||||
|
"GUILD_EMOJIS_UPDATE": Intents.GUILD_EMOJIS,
|
||||||
|
"GUILD_INTEGRATIONS_UPDATE": Intents.GUILD_INTEGRATIONS,
|
||||||
|
"INTEGRATION_CREATE": Intents.GUILD_INTEGRATIONS,
|
||||||
|
"INTEGRATION_UPDATE": Intents.GUILD_INTEGRATIONS,
|
||||||
|
"INTEGRATION_DELETE": Intents.GUILD_INTEGRATIONS,
|
||||||
|
"WEBHOOKS_UPDATE": Intents.GUILD_WEBHOOKS,
|
||||||
|
"INVITE_CREATE": Intents.GUILD_INVITES,
|
||||||
|
"INVITE_DELETE": Intents.GUILD_INVITES,
|
||||||
|
"VOICE_STATE_UPDATE": Intents.GUILD_VOICE_STATES,
|
||||||
|
"PRESENCE_UPDATE": Intents.GUILD_PRESENCES,
|
||||||
|
"MESSAGE_CREATE": Intents.GUILD_MESSAGES,
|
||||||
|
"MESSAGE_UPDATE": Intents.GUILD_MESSAGES,
|
||||||
|
"MESSAGE_DELETE": Intents.GUILD_MESSAGES,
|
||||||
|
"MESSAGE_DELETE_BULK": Intents.GUILD_MESSAGES,
|
||||||
|
"MESSAGE_REACTION_ADD": Intents.GUILD_MESSAGE_REACTIONS,
|
||||||
|
"MESSAGE_REACTION_REMOVE": Intents.GUILD_MESSAGE_REACTIONS,
|
||||||
|
"MESSAGE_REACTION_REMOVE_ALL": Intents.GUILD_MESSAGE_REACTIONS,
|
||||||
|
"MESSAGE_REACTION_REMOVE_EMOJI": Intents.GUILD_MESSAGE_REACTIONS,
|
||||||
|
"TYPING_START": Intents.GUILD_MESSAGE_TYPING,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class GuildDispatcher(
|
class GuildDispatcher(
|
||||||
DispatcherWithFlags[int, str, GatewayEvent, List[str], GuildFlags]
|
DispatcherWithFlags[int, str, GatewayEvent, List[str], GuildFlags]
|
||||||
):
|
):
|
||||||
|
|
@ -68,13 +120,9 @@ class GuildDispatcher(
|
||||||
await self.unsub(guild_id, session_id)
|
await self.unsub(guild_id, session_id)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
wanted_intent = EVENTS_TO_INTENTS[event_type]
|
||||||
flags = self.get_flags(guild_id, session_id)
|
state_has_intent = (state.intents & wanted_intent) == wanted_intent
|
||||||
except KeyError:
|
if not state_has_intent:
|
||||||
log.warning("no flags for {!r}, ignoring", session_id)
|
|
||||||
flags = GuildFlags(presence=True, typing=True)
|
|
||||||
|
|
||||||
if event_type.lower().startswith("presence_") and not flags.presence:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue