refactor: move functions
This commit is contained in:
parent
658a041ff8
commit
522d253410
5 changed files with 163 additions and 147 deletions
84
botcmd_misc.go
Normal file
84
botcmd_misc.go
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
tele "gopkg.in/telebot.v3"
|
||||
)
|
||||
|
||||
func handleStartCmd(c tele.Context) error {
|
||||
if !isFromAdmin(c.Sender()) {
|
||||
return c.Send("Hello, stranger :)")
|
||||
}
|
||||
|
||||
return c.Send("Hi :)")
|
||||
}
|
||||
|
||||
func handleUserInfoCmd(c tele.Context) error {
|
||||
u := c.Sender()
|
||||
if u == nil {
|
||||
return c.Reply("Unknown.", tele.Silent)
|
||||
}
|
||||
|
||||
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}, tele.Silent)
|
||||
}
|
||||
|
||||
func handleChatInfoCmd(c tele.Context) error {
|
||||
chat := c.Chat()
|
||||
if chat == nil {
|
||||
return c.Reply("Unknown.", tele.Silent)
|
||||
}
|
||||
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}, tele.Silent)
|
||||
}
|
||||
|
||||
func handleYearProgressCmd(c tele.Context) error {
|
||||
yearStart := time.Date(time.Now().Year(), 1, 1, 0, 0, 0, 0, time.Local)
|
||||
yearEnd := yearStart.AddDate(1, 0, 0)
|
||||
yearDur := yearEnd.Sub(yearStart)
|
||||
elapsed := time.Since(yearStart)
|
||||
ratio := float64(elapsed) / float64(yearDur)
|
||||
|
||||
replyText := fmt.Sprintf(
|
||||
"\n%d is <b>%2.0f%%</b> complete.\n<pre>%s</pre>",
|
||||
time.Now().Year(), ratio*100, drawBar(ratio, 20),
|
||||
)
|
||||
return c.Reply(replyText, &tele.SendOptions{ParseMode: tele.ModeHTML}, tele.Silent)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue