From e31ccdbd697db28460d24104688b13066d1aaaf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Fri, 3 Jun 2022 00:27:11 +0800 Subject: [PATCH] add only private --- rules.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rules.go b/rules.go index dc1fad5..fe0e4a3 100644 --- a/rules.go +++ b/rules.go @@ -199,6 +199,15 @@ 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 { // 确保无空 + return false + } + return msg.Chat.Type == "private" +} + // SuperUserPermission only triggered by the bot's owner func SuperUserPermission(ctx *Ctx) bool { msg, ok := ctx.Value.(*tgba.Message)