Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
2mf8 committed Aug 9, 2022
1 parent cb5d097 commit b6cbadb
Show file tree
Hide file tree
Showing 5 changed files with 1,316 additions and 1,020 deletions.
1 change: 1 addition & 0 deletions pkg/gmc/handler/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func init() {
//log.Infof("加载上报插件 Report")
plugin.AddPrivateMessagePlugin(plugins.ReportPrivateMessage)
plugin.AddGroupMessagePlugin(plugins.ReportGroupMessage)
plugin.AddGroupNotifyEventPlugin(plugins.ReportGroupNotify)
plugin.AddChannelMessagePlugin(plugins.ReportChannelMessage)
plugin.AddTempMessagePlugin(plugins.ReportTempMessage)
plugin.AddMemberPermissionChangedPlugin(plugins.ReportMemberPermissionChanged)
Expand Down
94 changes: 93 additions & 1 deletion pkg/gmc/plugins/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,4 +533,96 @@ func ReportOfflineFile(cli *client.QQClient, event *client.OfflineFileEvent) int
}
bot.HandleEventFrame(cli, eventProto)
return plugin.MessageIgnore
}
}

func ReportGroupNotify(cli *client.QQClient, event client.INotifyEvent) int32 {
group := cli.FindGroup(event.From())
switch notify := event.(type) {
case *client.GroupPokeNotifyEvent:
sender := group.FindMember(notify.Sender)
receiver := group.FindMember(notify.Receiver)
if sender == receiver {
log.Infof("群 %v(%v) 内 %v(%v) 戳了戳自己", group.Code, group.Name, sender.Uin, sender.Nickname)
} else {
log.Infof("群 %v(%v) 内 %v(%v) 戳了戳 %v(%v)", group.Code, group.Name, sender.Uin, sender.Nickname, receiver.Uin, receiver.Nickname)
}
eventProto := &onebot.Frame{
FrameType: onebot.Frame_TGroupNotifyEvent,
}
eventProto.Data = &onebot.Frame_GroupNotifyEvent{
GroupNotifyEvent: &onebot.GroupNotifyEvent{
Time: time.Now().Unix(),
SelfId: cli.Uin,
PostType: "notice",
NoticeType: "group_poke",
GroupId: group.Code,
GroupName: group.Name,
Sender: sender.Uin,
SenderCard: sender.Nickname,
TargetId: receiver.Uin,
TargetCard: receiver.Nickname,
},
}
bot.HandleEventFrame(cli, eventProto)
return plugin.MessageIgnore
case *client.GroupRedBagLuckyKingNotifyEvent:
sender := group.FindMember(notify.Sender)
luckyKing := group.FindMember(notify.LuckyKing)
log.Infof("群 %v(%v) 内 %v(%v) 的红包被抢完, %v(%v) 是运气王", group.Code, group.Name, sender.Uin, sender.Nickname, luckyKing.Uin, luckyKing.Nickname)
eventProto := &onebot.Frame{
FrameType: onebot.Frame_TGroupNotifyEvent,
}
eventProto.Data = &onebot.Frame_GroupNotifyEvent{
GroupNotifyEvent: &onebot.GroupNotifyEvent{
Time: time.Now().Unix(),
SelfId: cli.Uin,
PostType: "notice",
NoticeType: "group_red_bag_lucky_king",
GroupId: group.Code,
GroupName: group.Name,
Sender: sender.Uin,
SenderCard: sender.Nickname,
TargetId: luckyKing.Uin,
TargetCard: luckyKing.Nickname,
},
}
bot.HandleEventFrame(cli, eventProto)
return plugin.MessageIgnore
case *client.MemberHonorChangedNotifyEvent:
log.Info(notify.Content())
eventProto := &onebot.Frame{
FrameType: onebot.Frame_TGroupNotifyEvent,
}
eventProto.Data = &onebot.Frame_GroupNotifyEvent{
GroupNotifyEvent: &onebot.GroupNotifyEvent{
Time: time.Now().Unix(),
SelfId: cli.Uin,
PostType: "notice",
NoticeType: "member_honor_change",
GroupId: group.Code,
GroupName: group.Name,
TargetId: notify.Uin,
TargetCard: notify.Nick,
Honor: func() string {
switch notify.Honor {
case client.Talkative:
return "talkative"
case client.Performer:
return "performer"
case client.Emotion:
return "emotion"
case client.Legend:
return "legend"
case client.StrongNewbie:
return "strong_newbie"
default:
return "ERROR"
}
}(),
},
}
bot.HandleEventFrame(cli, eventProto)
return plugin.MessageIgnore
}
return plugin.MessageIgnore
}
17 changes: 17 additions & 0 deletions pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
type (
PrivateMessagePlugin = func(*client.QQClient, *message.PrivateMessage) int32
GroupMessagePlugin = func(*client.QQClient, *message.GroupMessage) int32
GroupNotifyEventPlugin = func(*client.QQClient, client.INotifyEvent) int32
ChannelMessagePlugin = func(*client.QQClient, *message.GuildChannelMessage) int32
TempMessagePlugin = func(*client.QQClient, *client.TempMessageEvent) int32
MemberJoinGroupPlugin = func(*client.QQClient, *client.MemberJoinGroupEvent) int32
Expand All @@ -33,6 +34,7 @@ const (

var PrivateMessagePluginList = make([]PrivateMessagePlugin, 0)
var GroupMessagePluginList = make([]GroupMessagePlugin, 0)
var GroupNotifyEventPluginList = make([]GroupNotifyEventPlugin, 0)
var ChannelMessagePluginList = make([]ChannelMessagePlugin, 0)
var TempMessagePluginList = make([]TempMessagePlugin, 0)
var MemberJoinGroupPluginList = make([]MemberJoinGroupPlugin, 0)
Expand Down Expand Up @@ -67,6 +69,7 @@ func Serve(cli *client.QQClient) {
cli.OfflineFileEvent.Subscribe(handleOfflineFile)
cli.GroupMuteEvent.Subscribe(handleGroupMute)
cli.GroupMemberPermissionChangedEvent.Subscribe(handleMemberPermissionChanged)
cli.GroupNotifyEvent.Subscribe(handleGroupNotifyEvent)
}

// 添加私聊消息插件
Expand All @@ -79,6 +82,10 @@ func AddGroupMessagePlugin(plugin GroupMessagePlugin) {
GroupMessagePluginList = append(GroupMessagePluginList, plugin)
}

func AddGroupNotifyEventPlugin(plugin GroupNotifyEventPlugin) {
GroupNotifyEventPluginList = append(GroupNotifyEventPluginList, plugin)
}

// 添加频道消息事件
func AddChannelMessagePlugin(plugin ChannelMessagePlugin) {
ChannelMessagePluginList = append(ChannelMessagePluginList, plugin)
Expand Down Expand Up @@ -323,3 +330,13 @@ func handleMemberPermissionChanged(cli *client.QQClient, event *client.MemberPer
}
})
}

func handleGroupNotifyEvent(cli *client.QQClient, event client.INotifyEvent) {
util.SafeGo(func() {
for _, plugin := range GroupNotifyEventPluginList {
if result := plugin(cli, event); result == MessageBlock {
break
}
}
})
}
Loading

0 comments on commit b6cbadb

Please sign in to comment.