refactor: use Sender() instead of Update() to get user info

This commit is contained in:
Yiyang Kang 2022-11-21 13:22:22 +08:00
parent 09f9b1ab68
commit a78802a7dd
1 changed files with 5 additions and 7 deletions

12
bot.go
View File

@ -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
}