Compare commits

..

No commits in common. "b429137d20490304ec7770632dd789aa28e231cc" and "09f9b1ab687a0d2b914ecac604874d1f6f3948d0" have entirely different histories.

2 changed files with 9 additions and 66 deletions

View File

@ -5,9 +5,6 @@ pack: build
tar --owner root --group root -c tgbot_misaka_5882f7 | zstdmt -15v > tgbot_misaka_5882f7.tar.zst tar --owner root --group root -c tgbot_misaka_5882f7 | zstdmt -15v > tgbot_misaka_5882f7.tar.zst
send: pack send: pack
wh send tgbot_misaka_5882f7.tar.zst --force-relay wh send tgbot_misaka_5882f7.tar.zst
clean: .PHONY: build pack send
rm -f tgbot_misaka_5882f7 tgbot_misaka_5882f7.*
.PHONY: build pack send clean

68
bot.go
View File

@ -11,12 +11,12 @@ import (
"git.gensokyo.cafe/kkyy/tgbot_misaka_5882f7/stats" "git.gensokyo.cafe/kkyy/tgbot_misaka_5882f7/stats"
) )
func isFromAdmin(sender *tele.User) bool { func isFromAdmin(upd tele.Update) bool {
if sender == nil { if upd.Message == nil || upd.Message.Sender == nil {
return false return false
} }
_, ok := config.AdminUIDs[sender.ID] _, ok := config.AdminUIDs[upd.Message.Sender.ID]
return ok return ok
} }
@ -35,14 +35,12 @@ func initBot() (*tele.Bot, error) {
b.Handle("/start", handleStartCmd) b.Handle("/start", handleStartCmd)
b.Handle("/traffic", handleTrafficCmd) b.Handle("/traffic", handleTrafficCmd)
b.Handle("/me", handleUserInfoCmd)
b.Handle("/chat", handleChatInfoCmd)
return b, nil return b, nil
} }
func handleStartCmd(c tele.Context) error { func handleStartCmd(c tele.Context) error {
if !isFromAdmin(c.Sender()) { upd := c.Update()
if !isFromAdmin(upd) {
return c.Send("Hello, stranger :)") return c.Send("Hello, stranger :)")
} }
@ -50,7 +48,8 @@ func handleStartCmd(c tele.Context) error {
} }
func handleTrafficCmd(c tele.Context) error { func handleTrafficCmd(c tele.Context) error {
if !isFromAdmin(c.Sender()) { upd := c.Update()
if !isFromAdmin(upd) {
return nil return nil
} }
@ -121,56 +120,3 @@ func fmtTraffic(r stats.VnstatTrafficRecord) string {
return fmt.Sprintf("%.2f GiB", float64(biggest)/1024/1024/1024) return fmt.Sprintf("%.2f GiB", float64(biggest)/1024/1024/1024)
} }
func handleUserInfoCmd(c tele.Context) error {
u := c.Sender()
if u == nil {
return c.Reply("Unknown.")
}
replyText := []string{
`*User Info*`,
"```",
fmt.Sprintf(`ID: %d`, u.ID),
fmt.Sprintf(`Username: %s`, u.Username),
fmt.Sprintf(`FirstName: %s`, u.FirstName),
fmt.Sprintf(`LastName: %s`, u.LastName),
fmt.Sprintf(`LanguageCode: %s`, u.LanguageCode),
fmt.Sprintf(`IsBot: %t`, u.IsBot),
fmt.Sprintf(`IsPremium: %t`, u.IsPremium),
"```",
}
return c.Reply(strings.Join(replyText, "\n"), &tele.SendOptions{ParseMode: tele.ModeMarkdown})
}
func handleChatInfoCmd(c tele.Context) error {
chat := c.Chat()
if chat == nil {
return c.Reply("Unknown.")
}
loc := ""
if chat.ChatLocation != nil {
loc = chat.ChatLocation.Address
}
replyText := []string{
`*Chat Info*`,
"```",
fmt.Sprintf(`ID: %d`, chat.ID),
fmt.Sprintf(`Type: %s`, chat.Type),
fmt.Sprintf(`Title: %s`, chat.Title),
fmt.Sprintf(`FirstName: %s`, chat.FirstName),
fmt.Sprintf(`LastName: %s`, chat.LastName),
fmt.Sprintf(`Username: %s`, chat.Username),
fmt.Sprintf(`SlowMode: %d`, chat.SlowMode),
fmt.Sprintf(`StickerSet: %s`, chat.StickerSet),
fmt.Sprintf(`CanSetStickerSet: %t`, chat.CanSetStickerSet),
fmt.Sprintf(`LinkedChatID: %d`, chat.LinkedChatID),
fmt.Sprintf(`ChatLocation: %s`, loc),
fmt.Sprintf(`Private: %t`, chat.Private),
fmt.Sprintf(`Protected: %t`, chat.Protected),
fmt.Sprintf(`NoVoiceAndVideo: %t`, chat.NoVoiceAndVideo),
"```",
}
return c.Reply(strings.Join(replyText, "\n"), &tele.SendOptions{ParseMode: tele.ModeMarkdown})
}