feat: add /me and /chat command

This commit is contained in:
Yiyang Kang 2022-11-21 13:43:00 +08:00
parent a78802a7dd
commit a42cb2db32
1 changed files with 56 additions and 0 deletions

56
bot.go
View File

@ -35,6 +35,9 @@ func initBot() (*tele.Bot, error) {
b.Handle("/start", handleStartCmd)
b.Handle("/traffic", handleTrafficCmd)
b.Handle("/me", handleUserInfoCmd)
b.Handle("/chat", handleChatInfoCmd)
return b, nil
}
@ -118,3 +121,56 @@ func fmtTraffic(r stats.VnstatTrafficRecord) string {
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})
}