1
0
mirror of https://github.com/fumiama/NanoBot.git synced 2026-06-08 20:20:23 +08:00

优化API报错消息 & onlyprivate

This commit is contained in:
源文雨
2023-10-17 22:43:01 +09:00
parent 95a2bec150
commit 2afbe5c83d
2 changed files with 44 additions and 18 deletions

View File

@@ -289,18 +289,24 @@ func CheckGuild(guildID ...string) Rule {
// OnlyPrivate requires that the ctx.Event is direct message
func OnlyPrivate(ctx *Ctx) bool {
if ctx.Type == "" { // 确保无空
return false
if ctx.Message != nil {
return ctx.Message.SrcGuildID != ""
}
return strings.HasPrefix(ctx.Type, "Direct")
if ctx.Type != "" {
return strings.HasPrefix(ctx.Type, "Direct")
}
return false
}
// OnlyPublic requires that the ctx.Event is channel message
func OnlyPublic(ctx *Ctx) bool {
if ctx.Type == "" { // 确保无空
return false
if ctx.Message != nil {
return ctx.Message.SrcGuildID == ""
}
return !strings.HasPrefix(ctx.Type, "Direct")
if ctx.Type != "" {
return !strings.HasPrefix(ctx.Type, "Direct")
}
return false
}
// OnlyChannel requires that the ctx.Event is channel message