From a78802a7dd5d01117efc1c62b6501265e275c21e Mon Sep 17 00:00:00 2001 From: Yiyang Kang Date: Mon, 21 Nov 2022 13:22:22 +0800 Subject: [PATCH] refactor: use Sender() instead of Update() to get user info --- bot.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/bot.go b/bot.go index 5b0a49c..5142d73 100644 --- a/bot.go +++ b/bot.go @@ -11,12 +11,12 @@ import ( "git.gensokyo.cafe/kkyy/tgbot_misaka_5882f7/stats" ) -func isFromAdmin(upd tele.Update) bool { - if upd.Message == nil || upd.Message.Sender == nil { +func isFromAdmin(sender *tele.User) bool { + if sender == nil { return false } - _, ok := config.AdminUIDs[upd.Message.Sender.ID] + _, ok := config.AdminUIDs[sender.ID] return ok } @@ -39,8 +39,7 @@ func initBot() (*tele.Bot, error) { } func handleStartCmd(c tele.Context) error { - upd := c.Update() - if !isFromAdmin(upd) { + if !isFromAdmin(c.Sender()) { return c.Send("Hello, stranger :)") } @@ -48,8 +47,7 @@ func handleStartCmd(c tele.Context) error { } func handleTrafficCmd(c tele.Context) error { - upd := c.Update() - if !isFromAdmin(upd) { + if !isFromAdmin(c.Sender()) { return nil }