github.com/fumiama/NanoBot@v0.0.0-20231122134259-c22d8183efca/handler.go (about) 1 package nano 2 3 import ( 4 "reflect" 5 "unsafe" 6 ) 7 8 // generalHandleType 作为通用的 handler 函数调用约定使用 9 type generalHandleType func(uint32, *Bot, unsafe.Pointer) 10 11 // eventHandlerType 一个事件函数调用的必须信息 12 type eventHandlerType struct { 13 h generalHandleType 14 t reflect.Type 15 } 16 17 var types map[string]reflect.Type // types 便于反射初始化的 types 18 19 func init() { 20 h := reflect.ValueOf(&Handler{}).Elem() 21 t := h.Type() 22 types = make(map[string]reflect.Type, h.NumField()*4) 23 for i := 0; i < h.NumField(); i++ { 24 tp := t.Field(i).Name[2:] // skip On 25 types[tp] = t.Field(i).Type.In(2).Elem() 26 } 27 } 28 29 // Handler 事件订阅 30 // 31 // https://bot.q.qq.com/wiki/develop/api/gateway/intents.html 32 type Handler struct { 33 // GUILDS (1 << 0) 34 35 OnGuildCreate func(s uint32, bot *Bot, d *Guild) 36 OnGuildUpdate func(s uint32, bot *Bot, d *Guild) 37 OnGuildDelete func(s uint32, bot *Bot, d *Guild) 38 OnChannelCreate func(s uint32, bot *Bot, d *Channel) 39 OnChannelUpdate func(s uint32, bot *Bot, d *Channel) 40 OnChannelDelete func(s uint32, bot *Bot, d *Channel) 41 // GUILD_MEMBERS (1 << 1) 42 43 OnGuildMemberAdd func(s uint32, bot *Bot, d *Member) 44 OnGuildMemberUpdate func(s uint32, bot *Bot, d *Member) 45 OnGuildMemberRemove func(s uint32, bot *Bot, d *Member) 46 // GUILD_MESSAGES (1 << 9) // 消息事件,仅 *私域* 机器人能够设置此 intents。 47 48 OnMessageCreate func(s uint32, bot *Bot, d *Message) 49 OnMessageDelete func(s uint32, bot *Bot, d *MessageDelete) 50 // GUILD_MESSAGE_REACTIONS (1 << 10) 51 52 OnMessageReactionAdd func(s uint32, bot *Bot, d *MessageReaction) 53 OnMessageReactionRemove func(s uint32, bot *Bot, d *MessageReaction) 54 // DIRECT_MESSAGE (1 << 12) 55 56 OnDirectMessageCreate func(s uint32, bot *Bot, d *Message) 57 OnDirectMessageDelete func(s uint32, bot *Bot, d *MessageDelete) 58 // OPEN_FORUMS_EVENT (1 << 18) // 论坛事件, 此为公域的论坛事件 59 60 OnOpenForumThreadCreate func(s uint32, bot *Bot, d *Thread) 61 OnOpenForumThreadUpdate func(s uint32, bot *Bot, d *Thread) 62 OnOpenForumThreadDelete func(s uint32, bot *Bot, d *Thread) 63 OnOpenForumPostCreate func(s uint32, bot *Bot, d *Post) 64 OnOpenForumPostDelete func(s uint32, bot *Bot, d *Post) 65 OnOpenForumReplyCreate func(s uint32, bot *Bot, d *Reply) 66 OnOpenForumReplyDelete func(s uint32, bot *Bot, d *Reply) 67 // AUDIO_OR_LIVE_CHANNEL_MEMBER (1 << 19) // 音视频/直播子频道成员进出事件 68 69 OnAudioOrLiveChannelMemberEnter func(s uint32, bot *Bot, d *AudioLiveChannelUsersChange) 70 OnAudioOrLiveChannelMemberExit func(s uint32, bot *Bot, d *AudioLiveChannelUsersChange) 71 // QQ (1<<25) QQ 的一堆事件 72 73 OnC2cMessageCreate func(s uint32, bot *Bot, d *Message) 74 OnGroupAtMessageCreate func(s uint32, bot *Bot, d *Message) 75 OnGroupAddRobot func(s uint32, bot *Bot, d *QQRobotStatus) 76 OnGroupDelRobot func(s uint32, bot *Bot, d *QQRobotStatus) 77 OnGroupMsgReject func(s uint32, bot *Bot, d *QQRobotStatus) 78 OnGroupMsgReceive func(s uint32, bot *Bot, d *QQRobotStatus) 79 OnFriendAdd func(s uint32, bot *Bot, d *QQRobotStatus) 80 OnFriendDel func(s uint32, bot *Bot, d *QQRobotStatus) 81 OnC2cMsgReject func(s uint32, bot *Bot, d *QQRobotStatus) 82 OnC2cMsgReceive func(s uint32, bot *Bot, d *QQRobotStatus) 83 84 // INTERACTION (1 << 26) 事件结构不明 85 86 // MESSAGE_AUDIT (1 << 27) 87 88 OnMessageAuditPass func(s uint32, bot *Bot, d *MessageAudited) 89 OnMessageAuditReject func(s uint32, bot *Bot, d *MessageAudited) 90 // FORUMS_EVENT (1 << 28) // 论坛事件,仅 *私域* 机器人能够设置此 intents。 91 92 OnForumThreadCreate func(s uint32, bot *Bot, d *Thread) 93 OnForumThreadUpdate func(s uint32, bot *Bot, d *Thread) 94 OnForumThreadDelete func(s uint32, bot *Bot, d *Thread) 95 OnForumPostCreate func(s uint32, bot *Bot, d *Post) 96 OnForumPostDelete func(s uint32, bot *Bot, d *Post) 97 OnForumReplyCreate func(s uint32, bot *Bot, d *Reply) 98 OnForumReplyDelete func(s uint32, bot *Bot, d *Reply) 99 OnForumPublishAuditResult func(s uint32, bot *Bot, d *AuditResult) 100 // AUDIO_ACTION (1 << 29) 101 102 OnAudioStart func(s uint32, bot *Bot, d *AudioAction) 103 OnAudioFinish func(s uint32, bot *Bot, d *AudioAction) 104 OnAudioOnMic func(s uint32, bot *Bot, d *AudioAction) 105 OnAudioOffMic func(s uint32, bot *Bot, d *AudioAction) 106 // PUBLIC_GUILD_MESSAGES (1 << 30) // 消息事件,此为公域的消息事件 107 108 OnAtMessageCreate func(s uint32, bot *Bot, d *Message) 109 OnPublicMessageDelete func(s uint32, bot *Bot, d *MessageDelete) 110 }