mirror of
https://github.com/watn3y/steamsalty.git
synced 2025-06-07 23:30:59 +02:00
v1.0
- Fixed SLEEPTIME not working (always 0) - Refined logging - Added metadata to /info command - Bot now automatically sets own commands for autocompletion
This commit is contained in:
parent
eb0482b8e0
commit
6be403fc58
14 changed files with 116 additions and 53 deletions
|
@ -2,7 +2,10 @@ package commands
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"watn3y/steamsalty/botIO"
|
||||
"watn3y/steamsalty/config"
|
||||
"watn3y/steamsalty/steam"
|
||||
|
@ -11,26 +14,41 @@ import (
|
|||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func SetBotCommands(bot *tgbotapi.BotAPI) {
|
||||
github := tgbotapi.BotCommand{Command: "github", Description: "Source GitHub repo"}
|
||||
info := tgbotapi.BotCommand{Command: "info", Description: "Summary of watched profiles"}
|
||||
|
||||
commands := tgbotapi.NewSetMyCommands(github, info)
|
||||
|
||||
result, err := bot.Request(commands)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to set own commands")
|
||||
return
|
||||
}
|
||||
|
||||
log.Debug().Interface("commands", result).Msg("Set own commands")
|
||||
}
|
||||
|
||||
func Commands(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
||||
|
||||
cmd := strings.ToLower(update.Message.Command())
|
||||
|
||||
log.Debug().Str("cmd", cmd).Msg("Matching command")
|
||||
|
||||
switch cmd {
|
||||
case "start":
|
||||
start(update, bot)
|
||||
startGithub(update, bot)
|
||||
case "github":
|
||||
startGithub(update, bot)
|
||||
case "info":
|
||||
info(update, bot)
|
||||
}
|
||||
}
|
||||
|
||||
func start(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
||||
func startGithub(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
||||
message := tgbotapi.MessageConfig{
|
||||
BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID},
|
||||
ParseMode: "html",
|
||||
DisableWebPagePreview: false,
|
||||
Text: "https://github.com/watn3y/steamsalty",
|
||||
Text: "Check out: https://github.com/watn3y/steamsalty",
|
||||
}
|
||||
botIO.SendMessage(message, bot)
|
||||
}
|
||||
|
@ -44,9 +62,16 @@ func info(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
|
||||
for _, steamID := range config.BotConfig.Watchers {
|
||||
profile := steam.GetPlayerDetails(steamID)
|
||||
comments := steam.GetComments(steamID, 0, 0)
|
||||
|
||||
textInfo += fmt.Sprintf(`- <a href="%s">%s</a>`, profile.ProfileURL, profile.PersonaName) + "\n"
|
||||
lastComment := "never :("
|
||||
if comments.TimeLastPost > 0 {
|
||||
lastComment = time.Unix(comments.TimeLastPost, 0).Format(time.RFC1123)
|
||||
}
|
||||
|
||||
textInfo += fmt.Sprintf(`<b><a href="%s">%s</a></b>:`, profile.ProfileURL, profile.PersonaName) + "\n" +
|
||||
fmt.Sprintf(`Last Comment: %s`, lastComment) + "\n" +
|
||||
fmt.Sprintf(`Number of Comments: %s`, strconv.Itoa(comments.TotalCount)) + "\n\n"
|
||||
}
|
||||
|
||||
message := tgbotapi.MessageConfig{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue