diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..86d6f0b --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,19 @@ + + + + \ No newline at end of file diff --git a/context.go b/context.go index 91bff33..ce1f3ea 100644 --- a/context.go +++ b/context.go @@ -67,7 +67,7 @@ func (ctx *Ctx) CheckSession() Rule { msg := ctx.Value.(*tgba.Message) return func(ctx2 *Ctx) bool { msg2, ok := ctx.Value.(*tgba.Message) - if !ok || msg.From == nil || msg.Chat == nil || msg2.From == nil || msg2.Chat == nil { // 确保无空 + if !ok || msg.From == nil || msg.Chat.ID == 0 || msg2.From == nil || msg2.Chat.ID == 0 { // 确保无空 return false } return msg.From.ID == msg2.From.ID && msg.Chat.ID == msg2.Chat.ID @@ -93,7 +93,7 @@ func (ctx *Ctx) Send(replytosender bool, c tgba.Chattable) (tgba.Message, error) func (ctx *Ctx) SendPlainMessage(replytosender bool, printable ...any) (tgba.Message, error) { msg := tgba.NewMessage(ctx.Message.Chat.ID, fmt.Sprint(printable...)) if replytosender { - msg.ReplyToMessageID = ctx.Message.MessageID + msg.ReplyParameters.MessageID = ctx.Message.MessageID } return ctx.Caller.Send(&msg) } @@ -102,13 +102,13 @@ func (ctx *Ctx) SendPlainMessage(replytosender bool, printable ...any) (tgba.Mes func (ctx *Ctx) SendMessage(replytosender bool, text string, entities ...tgba.MessageEntity) (tgba.Message, error) { msg := &tgba.MessageConfig{ BaseChat: tgba.BaseChat{ - ChatID: ctx.Message.Chat.ID, + ChatConfig: tgba.ChatConfig{ChatID: ctx.Message.Chat.ID}, }, Text: text, Entities: entities, } if replytosender { - msg.ReplyToMessageID = ctx.Message.MessageID + msg.ReplyParameters.MessageID = ctx.Message.MessageID } return ctx.Caller.Send(msg) } @@ -118,7 +118,7 @@ func (ctx *Ctx) SendPhoto(file tgba.RequestFileData, replytosender bool, caption msg := &tgba.PhotoConfig{ BaseFile: tgba.BaseFile{ BaseChat: tgba.BaseChat{ - ChatID: ctx.Message.Chat.ID, + ChatConfig: tgba.ChatConfig{ChatID: ctx.Message.Chat.ID}, }, File: file, }, @@ -126,7 +126,7 @@ func (ctx *Ctx) SendPhoto(file tgba.RequestFileData, replytosender bool, caption CaptionEntities: captionentities, } if replytosender { - msg.ReplyToMessageID = ctx.Message.MessageID + msg.ReplyParameters.MessageID = ctx.Message.MessageID } return ctx.Caller.Send(msg) } @@ -136,7 +136,7 @@ func (ctx *Ctx) SendAudio(file tgba.RequestFileData, replytosender bool, caption msg := tgba.AudioConfig{ BaseFile: tgba.BaseFile{ BaseChat: tgba.BaseChat{ - ChatID: ctx.Message.Chat.ID, + ChatConfig: tgba.ChatConfig{ChatID: ctx.Message.Chat.ID}, }, File: file, }, @@ -144,7 +144,7 @@ func (ctx *Ctx) SendAudio(file tgba.RequestFileData, replytosender bool, caption CaptionEntities: captionentities, } if replytosender { - msg.ReplyToMessageID = ctx.Message.MessageID + msg.ReplyParameters.MessageID = ctx.Message.MessageID } return ctx.Caller.Send(&msg) } @@ -154,7 +154,7 @@ func (ctx *Ctx) Block() { ctx.ma.SetBlock(true) } -// Block 在 pre, rules, mid 阶段阻止后续触发 +// Break Block 在 pre, rules, mid 阶段阻止后续触发 func (ctx *Ctx) Break() { ctx.ma.Break = true } diff --git a/rule.go b/rule.go index f161203..0cf1f5e 100644 --- a/rule.go +++ b/rule.go @@ -189,7 +189,7 @@ func init() { service.Permit(uid, grp) msg += "\n+ 已允许" + usr } else { - member, err := ctx.Caller.GetChatMember(tgba.GetChatMemberConfig{ChatConfigWithUser: tgba.ChatConfigWithUser{ChatID: ctx.Message.Chat.ID, UserID: uid}}) + member, err := ctx.Caller.GetChatMember(tgba.GetChatMemberConfig{ChatConfigWithUser: tgba.ChatConfigWithUser{ChatConfig: tgba.ChatConfig{ChatID: ctx.Message.Chat.ID}, UserID: uid}}) if err == nil && !member.HasLeft() && !member.WasKicked() { service.Permit(uid, grp) msg += "\n+ 已允许" + usr @@ -207,7 +207,7 @@ func init() { service.Ban(uid, grp) msg += "\n- 已禁止" + usr } else { - member, err := ctx.Caller.GetChatMember(tgba.GetChatMemberConfig{ChatConfigWithUser: tgba.ChatConfigWithUser{ChatID: ctx.Message.Chat.ID, UserID: uid}}) + member, err := ctx.Caller.GetChatMember(tgba.GetChatMemberConfig{ChatConfigWithUser: tgba.ChatConfigWithUser{ChatConfig: tgba.ChatConfig{ChatID: ctx.Message.Chat.ID}, UserID: uid}}) if err == nil && !member.HasLeft() && !member.WasKicked() { service.Ban(uid, grp) msg += "\n- 已禁止" + usr diff --git a/rules.go b/rules.go index 657dbd6..6e74faf 100644 --- a/rules.go +++ b/rules.go @@ -314,7 +314,7 @@ func CheckChat(chatId ...int64) Rule { return func(ctx *Ctx) bool { switch msg := ctx.Value.(type) { case *tgba.Message: - if msg.Chat == nil { // 确保无空 + if msg.Chat.ID == 0 { // 确保无空 return false } for _, cid := range chatId { @@ -324,7 +324,7 @@ func CheckChat(chatId ...int64) Rule { } return false case *tgba.CallbackQuery: - if msg.Message == nil || msg.Message.Chat == nil { + if msg.Message == nil || msg.Message.Chat.ID == 0 { return false } for _, cid := range chatId { @@ -342,7 +342,7 @@ func CheckChat(chatId ...int64) Rule { // OnlyPrivate requires that the ctx.Event is private message func OnlyPrivate(ctx *Ctx) bool { msg, ok := ctx.Value.(*tgba.Message) - if !ok || msg.Chat == nil { // 确保无空 + if !ok || msg.Chat.ID == 0 { // 确保无空 return false } return msg.Chat.Type == "private" @@ -351,7 +351,7 @@ func OnlyPrivate(ctx *Ctx) bool { // OnlyGroup requires that the ctx.Event is group message func OnlyGroup(ctx *Ctx) bool { msg, ok := ctx.Value.(*tgba.Message) - if !ok || msg.Chat == nil { // 确保无空 + if !ok || msg.Chat.ID == 0 { // 确保无空 return false } return msg.Chat.Type == "group" @@ -360,7 +360,7 @@ func OnlyGroup(ctx *Ctx) bool { // OnlyGroupOrSuperGroup Tips: many groups use supergroup and only a few groups use Group Type. func OnlyGroupOrSuperGroup(ctx *Ctx) bool { msg, ok := ctx.Value.(*tgba.Message) - if !ok || msg.Chat == nil { // 确保无空 + if !ok || msg.Chat.ID == 0 { // 确保无空 return false } return msg.Chat.Type == "group" || msg.Chat.Type == "supergroup" @@ -369,7 +369,7 @@ func OnlyGroupOrSuperGroup(ctx *Ctx) bool { // OnlySuperGroup requires that the ctx.Event is supergroup message func OnlySuperGroup(ctx *Ctx) bool { msg, ok := ctx.Value.(*tgba.Message) - if !ok || msg.Chat == nil { // 确保无空 + if !ok || msg.Chat.ID == 0 { // 确保无空 return false } return msg.Chat.Type == "supergroup" @@ -378,7 +378,7 @@ func OnlySuperGroup(ctx *Ctx) bool { // OnlyPublic requires that the ctx.Event is group or supergroup message func OnlyPublic(ctx *Ctx) bool { msg, ok := ctx.Value.(*tgba.Message) - if !ok || msg.Chat == nil { // 确保无空 + if !ok || msg.Chat.ID == 0 { // 确保无空 return false } return msg.Chat.Type == "supergroup" || msg.Chat.Type == "group" @@ -387,7 +387,7 @@ func OnlyPublic(ctx *Ctx) bool { // OnlyChannel requires that the ctx.Event is channel message func OnlyChannel(ctx *Ctx) bool { msg, ok := ctx.Value.(*tgba.Message) - if !ok || msg.Chat == nil { // 确保无空 + if !ok || msg.Chat.ID == 0 { // 确保无空 return false } return msg.Chat.Type == "channel" @@ -428,14 +428,14 @@ func CreaterPermission(ctx *Ctx) bool { } switch msg := ctx.Value.(type) { case *tgba.Message: - if msg.From == nil || msg.Chat == nil { // 确保无空 + if msg.From == nil || msg.Chat.ID == 0 { // 确保无空 return false } m, err := ctx.Caller.GetChatMember( tgba.GetChatMemberConfig{ ChatConfigWithUser: tgba.ChatConfigWithUser{ - ChatID: msg.Chat.ID, - UserID: msg.From.ID, + ChatConfig: tgba.ChatConfig{ChatID: msg.Chat.ID}, + UserID: msg.From.ID, }, }, ) @@ -444,14 +444,14 @@ func CreaterPermission(ctx *Ctx) bool { } return m.IsCreator() case *tgba.CallbackQuery: - if msg.From == nil || msg.Message == nil || msg.Message.Chat == nil { + if msg.From == nil || msg.Message == nil || msg.Message.Chat.ID == 0 { return false } m, err := ctx.Caller.GetChatMember( tgba.GetChatMemberConfig{ ChatConfigWithUser: tgba.ChatConfigWithUser{ - ChatID: msg.Message.Chat.ID, - UserID: msg.From.ID, + ChatConfig: tgba.ChatConfig{ChatID: msg.Message.Chat.ID}, + UserID: msg.From.ID, }, }, ) @@ -471,14 +471,14 @@ func AdminPermission(ctx *Ctx) bool { } switch msg := ctx.Value.(type) { case *tgba.Message: - if msg.From == nil || msg.Chat == nil { // 确保无空 + if msg.From == nil || msg.Chat.ID == 0 { // 确保无空 return false } m, err := ctx.Caller.GetChatMember( tgba.GetChatMemberConfig{ ChatConfigWithUser: tgba.ChatConfigWithUser{ - ChatID: msg.Chat.ID, - UserID: msg.From.ID, + ChatConfig: tgba.ChatConfig{ChatID: msg.Chat.ID}, + UserID: msg.From.ID, }, }, ) @@ -487,14 +487,14 @@ func AdminPermission(ctx *Ctx) bool { } return m.IsCreator() || m.IsAdministrator() case *tgba.CallbackQuery: - if msg.From == nil || msg.Message == nil || msg.Message.Chat == nil { + if msg.From == nil || msg.Message == nil || msg.Message.Chat.ID == 0 { return false } m, err := ctx.Caller.GetChatMember( tgba.GetChatMemberConfig{ ChatConfigWithUser: tgba.ChatConfigWithUser{ - ChatID: msg.Message.Chat.ID, - UserID: msg.From.ID, + ChatConfig: tgba.ChatConfig{ChatID: msg.Message.Chat.ID}, + UserID: msg.From.ID, }, }, )