Skip to content

Commit

Permalink
feat: 将频道 BotID 与群组 BotID 进行区分
Browse files Browse the repository at this point in the history
  • Loading branch information
WindowsSov8forUs committed Oct 10, 2024
1 parent 233c04e commit 9d9a00e
Show file tree
Hide file tree
Showing 19 changed files with 45 additions and 35 deletions.
28 changes: 16 additions & 12 deletions processor/event_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ func ReadyHandler(p *Processor) event.ReadyHandler {
// 构建 qq 事件
id := SaveEventID(data.SessionID)

bot := GetBot("qq")
satoriEvent := &operation.Event{
Id: id,
Type: operation.EventTypeLoginUpdated,
Platform: "qq",
SelfId: SelfId,
SelfId: bot.Id,
Timestamp: time.Now().UnixMilli(),
Login: &login.Login{
User: GetBot("qq"),
SelfId: SelfId,
User: bot,
SelfId: bot.Id,
Platform: "qq",
Status: GetStatus("qq"),
},
Expand All @@ -39,15 +40,16 @@ func ReadyHandler(p *Processor) event.ReadyHandler {
// 构建 qqguild 事件
id = SaveEventID(data.SessionID)

bot = GetBot("qqguild")
satoriEvent = &operation.Event{
Id: id,
Type: operation.EventTypeLoginUpdated,
Platform: "qqguild",
SelfId: SelfId,
SelfId: bot.Id,
Timestamp: time.Now().UnixMilli(),
Login: &login.Login{
User: GetBot("qqguild"),
SelfId: SelfId,
User: bot,
SelfId: bot.Id,
Platform: "qqguild",
Status: GetStatus("qqguild"),
},
Expand All @@ -67,15 +69,16 @@ func ErrorNotifyHandler(p *Processor) event.ErrorNotifyHandler {
// 构建 qq 事件
id := SaveEventID(err.Error())

bot := GetBot("qq")
satoriEvent := &operation.Event{
Id: id,
Type: operation.EventTypeLoginUpdated,
Platform: "qq",
SelfId: SelfId,
SelfId: bot.Id,
Timestamp: time.Now().UnixMilli(),
Login: &login.Login{
User: GetBot("qq"),
SelfId: SelfId,
User: bot,
SelfId: bot.Id,
Platform: "qq",
Status: GetStatus("qq"),
},
Expand All @@ -86,15 +89,16 @@ func ErrorNotifyHandler(p *Processor) event.ErrorNotifyHandler {
// 构建 qqguild 事件
id = SaveEventID(err.Error())

bot = GetBot("qqguild")
satoriEvent = &operation.Event{
Id: id,
Type: operation.EventTypeLoginUpdated,
Platform: "qqguild",
SelfId: SelfId,
SelfId: bot.Id,
Timestamp: time.Now().UnixMilli(),
Login: &login.Login{
User: GetBot("qqguild"),
SelfId: SelfId,
User: bot,
SelfId: bot.Id,
Platform: "qqguild",
Status: GetStatus("qqguild"),
},
Expand Down
14 changes: 10 additions & 4 deletions processor/login_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,23 @@ func getBotMe(api openapi.OpenAPI, ctx context.Context, conf *config.Config) (*d
if err != nil {
return nil, err
}
bot := &user.User{
qqBot := &user.User{
Id: strconv.Itoa(int(conf.Account.BotID)),
Name: me.Username,
Avatar: me.Avatar,
IsBot: me.Bot,
}
SetBot("qq", bot)
SetBot("qqguild", bot)
qqGuildBot := &user.User{
Id: strconv.Itoa(int(conf.Account.AppID)),
Name: me.Username,
Avatar: me.Avatar,
IsBot: me.Bot,
}
SetBot("qq", qqBot)
SetBot("qqguild", qqGuildBot)
SetStatus("qq", login.StatusOnline)
SetStatus("qqguild", login.StatusOnline)
SelfId = strconv.Itoa(int(conf.Account.BotID))
SelfId = me.ID
return me, nil
}

Expand Down
2 changes: 1 addition & 1 deletion processor/process_c2c_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (p *Processor) ProcessC2CMessage(payload *dto.WSPayload, data *dto.WSC2CMes
Id: id,
Type: operation.EventTypeMessageCreated,
Platform: "qq",
SelfId: SelfId,
SelfId: GetBot("qq").Id,
Timestamp: t.UnixMilli(),
Channel: channel,
Message: message,
Expand Down
2 changes: 1 addition & 1 deletion processor/process_channel_direct_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (p *Processor) ProcessChannelDirectMessage(payload *dto.WSPayload, data *dt
Id: id,
Type: operation.EventTypeMessageCreated,
Platform: "qqguild",
SelfId: SelfId,
SelfId: GetBot("qqguild").Id,
Timestamp: t.UnixMilli(),
Channel: channel,
Guild: guild,
Expand Down
2 changes: 1 addition & 1 deletion processor/process_channel_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (p *Processor) ProcessChannelEvent(payload *dto.WSPayload, data *dto.WSChan
Id: id,
Type: operation.EventTypeInternal,
Platform: "qqguild",
SelfId: SelfId,
SelfId: GetBot("qqguild").Id,
Timestamp: t,
Type_: string(payload.Type),
Data_: data,
Expand Down
2 changes: 1 addition & 1 deletion processor/process_group_add_robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (p *Processor) ProcessGroupAddRobot(payload *dto.WSPayload, data *dto.Group
Id: id,
Type: operation.EventTypeGuildAdded,
Platform: "qq",
SelfId: SelfId,
SelfId: GetBot("qq").Id,
Timestamp: data.Timestamp,
Channel: channel,
Guild: guild,
Expand Down
2 changes: 1 addition & 1 deletion processor/process_group_del_robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (p *Processor) ProcessGroupDelRobot(payload *dto.WSPayload, data *dto.Group
Id: id,
Type: operation.EventTypeGuildRemoved,
Platform: "qq",
SelfId: SelfId,
SelfId: GetBot("qq").Id,
Timestamp: data.Timestamp,
Channel: channel,
Guild: guild,
Expand Down
2 changes: 1 addition & 1 deletion processor/process_group_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (p *Processor) ProcessGroupMessage(payload *dto.WSPayload, data *dto.WSGrou
Id: id,
Type: operation.EventTypeMessageCreated,
Platform: "qq",
SelfId: SelfId,
SelfId: GetBot("qq").Id,
Timestamp: t.UnixMilli(),
Channel: channel,
Guild: guild,
Expand Down
2 changes: 1 addition & 1 deletion processor/process_guild_at_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (p *Processor) ProcessGuildATMessage(payload *dto.WSPayload, data *dto.WSAT
Id: id,
Type: operation.EventTypeMessageCreated,
Platform: "qqguild",
SelfId: SelfId,
SelfId: GetBot("qqguild").Id,
Timestamp: t.UnixMilli(),
Channel: channel,
Guild: guild,
Expand Down
2 changes: 1 addition & 1 deletion processor/process_guild_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (p *Processor) ProcessGuildEvent(payload *dto.WSPayload, data *dto.WSGuildD
Id: id,
Type: eventType,
Platform: "qqguild",
SelfId: SelfId,
SelfId: GetBot("qqguild").Id,
Timestamp: t.UnixMilli(),
Guild: guild,
Operator: operator,
Expand Down
2 changes: 1 addition & 1 deletion processor/process_guild_normal_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (p *Processor) ProcessGuildNormalMessage(payload *dto.WSPayload, data *dto.
Id: id,
Type: operation.EventTypeMessageCreated,
Platform: "qqguild",
SelfId: SelfId,
SelfId: GetBot("qqguild").Id,
Timestamp: t.UnixMilli(),
Channel: channel,
Guild: guild,
Expand Down
6 changes: 3 additions & 3 deletions processor/process_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (p *Processor) ProcessQQInternal(payload *dto.WSPayload, data interface{})
Id: id,
Type: operation.EventTypeInternal,
Platform: "qq",
SelfId: SelfId,
SelfId: GetBot("qq").Id,
Timestamp: t,
Type_: string(payload.Type),
Data_: data_,
Expand Down Expand Up @@ -68,7 +68,7 @@ func (p *Processor) ProcessQQGuildInternal(payload *dto.WSPayload, data interfac
Id: id,
Type: operation.EventTypeInternal,
Platform: "qqguild",
SelfId: SelfId,
SelfId: GetBot("qqguild").Id,
Timestamp: t,
Type_: string(payload.Type),
Data_: data_,
Expand Down Expand Up @@ -103,7 +103,7 @@ func (p *Processor) ProcessInteractionEvent(data *dto.WSInteractionData) error {
Id: id,
Type: operation.EventTypeInternal,
Platform: platform,
SelfId: SelfId,
SelfId: GetBot(platform).Id,
Timestamp: t,
Type_: string(dto.EventInteractionCreate),
Data_: data,
Expand Down
2 changes: 1 addition & 1 deletion processor/process_member_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (p *Processor) ProcessMemberEvent(payload *dto.WSPayload, data *dto.WSGuild
Id: id,
Type: eventType,
Platform: "qqguild",
SelfId: SelfId,
SelfId: GetBot("qqguild").Id,
Timestamp: t.UnixMilli(),
Guild: guild,
Member: member,
Expand Down
2 changes: 1 addition & 1 deletion processor/process_message_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (p *Processor) ProcessMessageDelete(payload *dto.WSPayload, data interface{
Id: id,
Type: operation.EventTypeMessageDeleted,
Platform: "qqguild",
SelfId: SelfId,
SelfId: GetBot("qqguild").Id,
Timestamp: t,
Channel: channel,
Guild: guild,
Expand Down
2 changes: 1 addition & 1 deletion processor/process_message_reaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (p *Processor) ProcessMessageReaction(payload *dto.WSPayload, data *dto.WSM
Id: id,
Type: eventType,
Platform: "qqguild",
SelfId: SelfId,
SelfId: GetBot("qqguild").Id,
Timestamp: t,
Channel: channel,
Guild: guild,
Expand Down
2 changes: 1 addition & 1 deletion processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func GetReadyBody() *operation.ReadyBody {
for platform, bot := range GetBots() {
login := &login.Login{
User: bot,
SelfId: SelfId,
SelfId: GetBot(platform).Id,
Platform: platform,
Status: GetStatus(platform),
Features: Features(),
Expand Down
2 changes: 1 addition & 1 deletion server/httpapi/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func HandlerLoginList(message *AdminActionMessage) (any, APIError) {
for platform, bot := range bots {
login := login.Login{
User: bot,
SelfId: processor.SelfId,
SelfId: bot.Id,
Platform: platform,
Status: processor.GetStatus(platform),
}
Expand Down
2 changes: 1 addition & 1 deletion server/httpapi/httpapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func BotValidateMiddleware() gin.HandlerFunc {
c.Abort()
return
}
if xSelfID != processor.SelfId {
if xSelfID != bot.Id {
c.String(http.StatusBadRequest, `unknown self id "%s"`, xSelfID)
c.Abort()
return
Expand Down
2 changes: 1 addition & 1 deletion server/httpapi/login_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func HandleLoginGet(api, apiv2 openapi.OpenAPI, message *ActionMessage) (any, AP

// 构建机器人对象
bot := &user.User{
Id: me.ID,
Id: processor.GetBot(message.Platform).Id,
Name: me.Username,
Avatar: me.Avatar,
IsBot: me.Bot,
Expand Down

0 comments on commit 9d9a00e

Please sign in to comment.