Skip to content

Commit

Permalink
feat: 增加表情表态事件
Browse files Browse the repository at this point in the history
  • Loading branch information
DaiJiChen authored and hwygithub committed Feb 15, 2022
1 parent 903abfa commit aca04f6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions qqbot/core/network/ws/dto/enum_intents.py
Expand Up @@ -19,6 +19,10 @@ class Intents(Enum):

INTENT_GUILD_MESSAGES = 1 << 9

INTENT_MESSAGE_REACTION = 1 << 10
# - MESSAGE_REACTION_ADD // 为消息添加表情表态
# - MESSAGE_REACTION_REMOVE // 为消息删除表情表态

INTENT_DIRECT_MESSAGE = 1 << 12
# - DIRECT_MESSAGE_CREATE // 当收到用户发给机器人的私信消息时

Expand Down
5 changes: 5 additions & 0 deletions qqbot/core/network/ws/ws_event.py
Expand Up @@ -24,6 +24,9 @@ class WsEvent:
EventAudioOnMic = "AUDIO_ON_MIC"
EventAudioOffMic = "AUDIO_OFF_MIC"

EventMessageReactionAdd = "MESSAGE_REACTION_ADD"
EventMessageReactionRemove = "MESSAGE_REACTION_REMOVE"

# 事件map
event_dirt = {
EventGuildCreate: Intents.INTENT_GUILDS,
Expand All @@ -42,6 +45,8 @@ class WsEvent:
EventAudioFinish: Intents.INTENT_AUDIO,
EventAudioOnMic: Intents.INTENT_AUDIO,
EventAudioOffMic: Intents.INTENT_AUDIO,
EventMessageReactionAdd: Intents.INTENT_MESSAGE_REACTION,
EventMessageReactionRemove: Intents.INTENT_MESSAGE_REACTION,
}

@staticmethod
Expand Down
1 change: 1 addition & 0 deletions qqbot/core/network/ws/ws_handler.py
Expand Up @@ -11,3 +11,4 @@ class DefaultHandler:
at_message = None
direct_message = None
audio = None
message_reaction = None
11 changes: 11 additions & 0 deletions qqbot/core/network/ws/ws_intents_handler.py
Expand Up @@ -87,6 +87,15 @@ def direct_message_event_handler(callback, intent):
return intent


def message_reactions_event_handler(callback, intent):
DefaultHandler.message_reaction = callback
intent = intent | WsEvent.event_to_intent(
WsEvent.EventMessageReactionAdd,
WsEvent.EventMessageReactionRemove,
)
return intent


class HandlerType(Enum):
PLAIN_EVENT_HANDLER = 0
GUILD_EVENT_HANDLER = 1
Expand All @@ -96,6 +105,7 @@ class HandlerType(Enum):
AT_MESSAGE_EVENT_HANDLER = 5
DIRECT_MESSAGE_EVENT_HANDLER = 6
AUDIO_EVENT_HANDLER = 7
MESSAGE_REACTIONS_EVENT_HANDLER = 8


intent_handler_dict = {
Expand All @@ -107,4 +117,5 @@ class HandlerType(Enum):
HandlerType.AT_MESSAGE_EVENT_HANDLER.value: at_message_event_handler,
HandlerType.DIRECT_MESSAGE_EVENT_HANDLER.value: direct_message_event_handler,
HandlerType.AUDIO_EVENT_HANDLER.value: audio_event_handler,
HandlerType.MESSAGE_REACTIONS_EVENT_HANDLER.value: message_reactions_event_handler,
}

0 comments on commit aca04f6

Please sign in to comment.