logging improvements

This commit is contained in:
Watn3y 2023-03-05 05:45:36 +01:00
parent c63dbc666d
commit 6a31972ad0
8 changed files with 35 additions and 15 deletions

11
bot.go
View file

@ -1,14 +1,12 @@
package main
import (
"time"
"log"
"watn3y/bloaterbotv3/botIO"
"watn3y/bloaterbotv3/commands"
"watn3y/bloaterbotv3/text"
)
var shutuptime time.Time
func bot() {
updates, bot := botIO.Authenticate()
@ -17,13 +15,12 @@ func bot() {
continue
}
log.Printf("[bot] Recieved Message: [%s] %s", update.Message.From.UserName, update.Message.Text)
if update.Message.IsCommand() {
commands.Commands(update, bot)
} else {
if time.Since(shutuptime).Minutes() >= 60 {
text.Matcher(update, bot)
}
text.Matcher(update, bot)
}
}

View file

@ -18,7 +18,7 @@ func Authenticate() (tgbotapi.UpdatesChannel, *tgbotapi.BotAPI) {
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
log.Printf("Authorized on account %s", b.Self.UserName)
log.Printf("[bot]Authorized on account %s", b.Self.UserName)
return b.GetUpdatesChan(u), b
}

View file

@ -10,4 +10,5 @@ func SendMessage(message tgbotapi.MessageConfig, bot *tgbotapi.BotAPI) {
if err != nil {
log.Printf("Failed to send message: %v\n", err)
}
log.Printf("[bot] Sent Message: %s", message.Text)
}

View file

@ -2,6 +2,8 @@ package commands
import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"log"
"strconv"
"strings"
"time"
"watn3y/bloaterbotv3/botIO"
@ -12,6 +14,9 @@ func Commands(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
if strings.ToLower(update.Message.Command()) == "shutup" || strings.ToLower(update.Message.Command()) == "shut" {
config.BotConfig.Shutup[update.Message.Chat.ID] = time.Now().UTC()
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Shutting up")
log.Println("Shutting up for Chat: " + strconv.FormatInt(update.Message.Chat.ID, 10))
botIO.SendMessage(msg, bot)
}
}

View file

@ -1,5 +1,11 @@
package commonlogic
import (
"reflect"
"runtime"
"strings"
)
func ContainsInt64(a []int64, b int64) bool {
for _, v := range a {
if v == b {
@ -9,3 +15,9 @@ func ContainsInt64(a []int64, b int64) bool {
return false
}
func GetPackageName(temp interface{}) string {
strs := strings.Split((runtime.FuncForPC(reflect.ValueOf(temp).Pointer()).Name()), ".")
strs = strings.Split(strs[len(strs)-2], "/")
return strs[len(strs)-1]
}

View file

@ -1,7 +1,6 @@
package config
import (
"fmt"
"github.com/BurntSushi/toml"
"log"
"os"
@ -38,10 +37,7 @@ func LoadConfig() {
log.Fatal(err)
}
if BotConfig.DebugMode {
fmt.Print("Loaded config from configfile: ")
fmt.Printf("%+v\n", BotConfig)
}
BotConfig.Shutup = make(map[int64]time.Time)
log.Printf("[config] Config loaded as: %+v\n", BotConfig)
}

View file

@ -2,6 +2,8 @@ package balonlyl
import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"log"
"strconv"
"watn3y/bloaterbotv3/botIO"
"watn3y/bloaterbotv3/config"
)
@ -15,6 +17,7 @@ func Balonlyl(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
balonlylAT + " look at these idiots",
}*/
log.Println("[balonlyl] French detected in Chat: " + strconv.FormatInt(update.Message.Chat.ID, 10))
message := tgbotapi.MessageConfig{
BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID},
ParseMode: "html",

View file

@ -2,6 +2,7 @@ package nhentai
import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"log"
"regexp"
"strconv"
"watn3y/bloaterbotv3/botIO"
@ -15,9 +16,12 @@ func Nhentai(regex string, update tgbotapi.Update, bot *tgbotapi.BotAPI) {
match := re.FindStringSubmatch(update.Message.Text)
hentainumber := getdigit.FindStringSubmatch(match[0])
log.Println("[nhentai] Looking for Hentai " + hentainumber[0] + " from Chat: " + strconv.FormatInt(update.Message.Chat.ID, 10))
hentaiExists, hentaiResponse := doAPIRequest(hentainumber[0])
if !hentaiExists {
log.Println("[nhentai] Dit not find Hentai " + hentainumber[0] + " from Chat: " + strconv.FormatInt(update.Message.Chat.ID, 10))
return
}
@ -27,9 +31,11 @@ func Nhentai(regex string, update tgbotapi.Update, bot *tgbotapi.BotAPI) {
for _, tag := range hentai.Tags {
tags = tags + `<a href="` + config.BotConfig.Nhentai.Domain + tag.URL + `">` + tag.Name + `</a>` + `, `
}
println(tags)
hentaitext := `<b>` + `<a href="` + config.BotConfig.Nhentai.Domain + `/g/` + strconv.Itoa(hentai.ID) + `">` + hentai.Title + `</a> ` + `</b>` + "\n\n" + tags
log.Println("[nhentai] Found Hentai " + hentai.Title + " in Chat: " + strconv.FormatInt(update.Message.Chat.ID, 10))
message := tgbotapi.MessageConfig{
BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID},
ParseMode: "html",