go_telegram/pkg/service/telegram/admin.go

37 lines
713 B
Go
Raw Permalink Normal View History

2020-05-17 06:25:29 +00:00
package telegram
import (
"strconv"
"github.com/yanzay/tbot/v2"
)
func (tb *Bot) myID(m *tbot.Message) {
if tb.adminCheck(m.From.ID, false) {
2020-05-17 06:25:29 +00:00
tb.Client.SendMessage(m.Chat.ID, strconv.Itoa(m.From.ID))
return
2020-05-17 06:25:29 +00:00
}
tb.Client.SendMessage(m.Chat.ID, "You are not an authorized admin.")
2020-05-17 06:25:29 +00:00
}
func (tb *Bot) chatID(m *tbot.Message) {
if tb.adminCheck(m.From.ID, false) {
tb.Client.SendMessage(m.Chat.ID, m.Chat.ID)
return
}
tb.Client.SendMessage(m.Chat.ID, "You are not an authorized admin.")
2020-05-17 06:25:29 +00:00
}
// adminCheck checks for valid bot admins.
func (tb *Bot) adminCheck(id int, callback bool) bool {
2020-05-17 06:25:29 +00:00
for _, admin := range tb.Config.Telegram.Admins {
if id == admin {
2020-05-17 06:25:29 +00:00
return true
}
}
2020-05-17 06:25:29 +00:00
return false
}