added proper logging to most of the code
This commit is contained in:
parent
65c6020e49
commit
7d4c9c5ab9
21 changed files with 218 additions and 283 deletions
2
TODO.md
2
TODO.md
|
@ -11,3 +11,5 @@
|
|||
- user, time, codec, etc
|
||||
- seperate sql from gaypoints
|
||||
- prepare SQL queries in functions and send them to sql
|
||||
- move SQL logs from sql to other
|
||||
-
|
6
bot.go
6
bot.go
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"github.com/rs/zerolog/log"
|
||||
"time"
|
||||
"watn3y/bloaterbotv3/botIO"
|
||||
"watn3y/bloaterbotv3/commands"
|
||||
|
@ -17,7 +17,9 @@ func bot() {
|
|||
if update.Message == nil || update.Message.Time().UTC().Unix() < now.UTC().Unix() {
|
||||
continue
|
||||
}
|
||||
log.Printf("[bot] Recieved Message: [%s] %s", update.Message.From.FirstName, update.Message.Text)
|
||||
|
||||
log.Info().Int64("user", update.Message.From.ID).Int64("chat", update.Message.Chat.ID).Str("msg", update.Message.Text).Msg("Recieved update:")
|
||||
log.Debug().Interface("update", update).Msg("")
|
||||
|
||||
if update.Message.IsCommand() {
|
||||
commands.Commands(update, bot)
|
||||
|
|
|
@ -2,7 +2,7 @@ package botIO
|
|||
|
||||
import (
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
"log"
|
||||
"github.com/rs/zerolog/log"
|
||||
"watn3y/bloaterbotv3/config"
|
||||
)
|
||||
|
||||
|
@ -11,14 +11,15 @@ func Authenticate() (tgbotapi.UpdatesChannel, *tgbotapi.BotAPI) {
|
|||
b, err := tgbotapi.NewBotAPI(config.BotConfig.APIToken)
|
||||
|
||||
if err != nil {
|
||||
log.Panicf("Failed to connect Bot to Telegram: %v\n", err)
|
||||
log.Panic().Err(err).Msg("Failed to authorize bot")
|
||||
}
|
||||
|
||||
b.Debug = config.BotConfig.DebugMode
|
||||
|
||||
u := tgbotapi.NewUpdate(0)
|
||||
u.Timeout = 60
|
||||
log.Printf("[bot] Authorized on account %s", b.Self.UserName)
|
||||
|
||||
log.Info().Int64("ID", b.Self.ID).Str("username", b.Self.UserName).Msg("Successfully authorized bot")
|
||||
|
||||
return b.GetUpdatesChan(u), b
|
||||
}
|
||||
|
|
|
@ -2,55 +2,70 @@ package botIO
|
|||
|
||||
import (
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
"log"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func SendMessage(message tgbotapi.MessageConfig, bot *tgbotapi.BotAPI) (result tgbotapi.Message) {
|
||||
result, err := bot.Send(message)
|
||||
if err != nil {
|
||||
log.Printf("Failed to send message: %v\n", err)
|
||||
log.Error().Err(err).Msg("Failed to send message")
|
||||
return
|
||||
}
|
||||
log.Printf("[bot] Sent Message: %s", message.Text)
|
||||
|
||||
log.Info().Int64("chat", result.Chat.ID).Str("msg", result.Text).Msg("Sent message")
|
||||
log.Debug().Interface("msg", result).Msg("")
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func EditMessage(message tgbotapi.EditMessageTextConfig, bot *tgbotapi.BotAPI) (result tgbotapi.Message) {
|
||||
result, err := bot.Send(message)
|
||||
if err != nil {
|
||||
log.Printf("Failed to send message: %v\n", err)
|
||||
log.Error().Err(err).Msg("Failed to edit message")
|
||||
return
|
||||
}
|
||||
log.Printf("[bot] Edited Message: %s", message.Text)
|
||||
|
||||
log.Info().Int64("chat", result.Chat.ID).Str("msg", result.Text).Msg("Edited message")
|
||||
log.Debug().Interface("msg", result).Msg("")
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func SendVideo(message tgbotapi.VideoConfig, bot *tgbotapi.BotAPI) (result tgbotapi.Message) {
|
||||
result, err := bot.Send(message)
|
||||
if err != nil {
|
||||
log.Printf("Failed to send message: %v\n", err)
|
||||
log.Error().Err(err).Msg("Failed to send video")
|
||||
return
|
||||
}
|
||||
log.Printf("[bot] Sent Video: %s", message.File)
|
||||
|
||||
log.Info().Int64("chat", result.Chat.ID).Msg("Sent video")
|
||||
log.Debug().Interface("video", result).Msg("")
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func SendPhoto(message tgbotapi.PhotoConfig, bot *tgbotapi.BotAPI) (result tgbotapi.Message) {
|
||||
result, err := bot.Send(message)
|
||||
if err != nil {
|
||||
log.Printf("Failed to send message: %v\n", err)
|
||||
log.Error().Err(err).Msg("Failed to send photo")
|
||||
return
|
||||
}
|
||||
log.Printf("[bot] Sent Photo: %s", message.File)
|
||||
|
||||
log.Info().Int64("chat", result.Chat.ID).Msg("Sent photo")
|
||||
log.Debug().Interface("photo", result).Msg("")
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func SendSticker(sticker tgbotapi.StickerConfig, bot *tgbotapi.BotAPI) (result tgbotapi.Message) {
|
||||
result, err := bot.Send(sticker)
|
||||
func SendSticker(message tgbotapi.StickerConfig, bot *tgbotapi.BotAPI) (result tgbotapi.Message) {
|
||||
result, err := bot.Send(message)
|
||||
if err != nil {
|
||||
log.Printf("Failed to send Sticker: %v\n", err)
|
||||
log.Error().Err(err).Msg("Failed to send sticker")
|
||||
return
|
||||
}
|
||||
log.Printf("[bot] Sent Sticker")
|
||||
|
||||
log.Info().Int64("chat", result.Chat.ID).Msg("Sent sticker")
|
||||
log.Debug().Interface("sticker", result).Msg("")
|
||||
|
||||
return result
|
||||
}
|
||||
|
|
10
build.sh
10
build.sh
|
@ -1,4 +1,10 @@
|
|||
###!/usr/bin/env bash
|
||||
docker login
|
||||
|
||||
read -p 'Tag: ' tag
|
||||
|
||||
|
||||
docker buildx create --name bloaterbuilder --use --bootstrap
|
||||
docker buildx build --push --platform linux/amd64,linux/arm64 --tag watn3y/bloaterbot:$(git log -1 --pretty=%h) --tag watn3y/bloaterbot:$tag --build-arg=COMMIT=$(git log -1 --pretty=%h) .
|
||||
|
||||
|
||||
HASH=$(git log -1 --pretty=%h)
|
||||
docker build -t bloaterbot:latest -t bloaterbot:$HASH --build-arg=COMMIT=$(git log -1 --pretty=%h) .
|
|
@ -2,7 +2,7 @@ package commands
|
|||
|
||||
import (
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
"log"
|
||||
"github.com/rs/zerolog/log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -18,6 +18,8 @@ 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 "shutup":
|
||||
shutup(update, bot)
|
||||
|
@ -46,7 +48,7 @@ func shutup(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
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))
|
||||
log.Info().Int64("chat", update.Message.Chat.ID).Msg("Shutting up")
|
||||
|
||||
botIO.SendMessage(msg, bot)
|
||||
|
||||
|
|
|
@ -3,8 +3,9 @@ package download
|
|||
import (
|
||||
"errors"
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
"github.com/rs/zerolog/log"
|
||||
"io"
|
||||
"log"
|
||||
log2 "log"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
@ -22,7 +23,7 @@ import (
|
|||
|
||||
func Download(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
||||
|
||||
log.Println("[download] Downloading URL " + update.Message.CommandArguments() + " for " + strconv.FormatInt(update.Message.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10))
|
||||
log.Debug().Int64("chat", update.Message.Chat.ID).Int64("user", update.Message.From.ID).Msg("starting download")
|
||||
|
||||
commandArgs := strings.Fields(update.Message.CommandArguments())
|
||||
|
||||
|
@ -36,7 +37,7 @@ func Download(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
//TODO distinguish
|
||||
//service := matchURL(commandArgs[0])
|
||||
} else {
|
||||
log.Println("[download] Failed to download URL " + update.Message.CommandArguments() + " NO URL")
|
||||
log.Error().Int64("chat", update.Message.Chat.ID).Int64("user", update.Message.From.ID).Str("args", update.Message.CommandArguments()).Msg("failed to download. empty arg")
|
||||
message := tgbotapi.EditMessageTextConfig{
|
||||
BaseEdit: tgbotapi.BaseEdit{ChatID: workingMessage.Chat.ID, MessageID: workingMessage.MessageID},
|
||||
Text: "Please specify a valid YouTube URL to download something.",
|
||||
|
@ -61,7 +62,7 @@ func Download(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
files, err := os.ReadDir("./videos/" + downloadTarget)
|
||||
|
||||
if err != nil {
|
||||
log.Println("[download] Failed to process URL "+update.Message.CommandArguments(), " FAILED TO READ DIRECTORY: ", err.Error())
|
||||
log.Error().Err(err).Msg("failed to download. unable to read target directory")
|
||||
|
||||
message := tgbotapi.EditMessageTextConfig{
|
||||
BaseEdit: tgbotapi.BaseEdit{ChatID: workingMessage.Chat.ID, MessageID: workingMessage.MessageID},
|
||||
|
@ -72,7 +73,7 @@ func Download(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
}
|
||||
|
||||
if len(files) > 1 {
|
||||
log.Println("[download] Failed to process URL "+update.Message.CommandArguments(), " TOO MANY FILES")
|
||||
log.Error().Err(err).Msg("failed to download. too many files")
|
||||
message := tgbotapi.EditMessageTextConfig{
|
||||
BaseEdit: tgbotapi.BaseEdit{ChatID: workingMessage.Chat.ID, MessageID: workingMessage.MessageID},
|
||||
Text: "Something went wrong while downloading your media :(",
|
||||
|
@ -88,10 +89,11 @@ func Download(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
botIO.EditMessage(message, bot)
|
||||
|
||||
serveMedia(update, bot, downloadTarget, files[0].Name())
|
||||
log.Println("[download] Served URL " + update.Message.CommandArguments() + " for " + strconv.FormatInt(update.Message.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10))
|
||||
log2.Println("[download] Served URL " + update.Message.CommandArguments() + " for " + strconv.FormatInt(update.Message.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10))
|
||||
|
||||
time.Sleep(10 * time.Second)
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
log.Info().Msg("downloaded file")
|
||||
bot.Send(tgbotapi.NewDeleteMessage(workingMessage.Chat.ID, workingMessage.MessageID))
|
||||
|
||||
}
|
||||
|
@ -117,19 +119,19 @@ func runYTDL(URL string, targetDir string) (success bool) {
|
|||
)
|
||||
|
||||
if errors.As(err, &ee) {
|
||||
log.Println("[download.ytdl] Failed to download URL "+URL, " NON ZERO EXIT CODE: ", ee.ExitCode())
|
||||
log2.Println("[download.ytdl] Failed to download URL "+URL, " NON ZERO EXIT CODE: ", ee.ExitCode())
|
||||
success = false
|
||||
|
||||
} else if errors.As(err, &pe) {
|
||||
log.Println("[download.ytdl] Failed to download URL "+URL, " OS PATH ERROR: ", pe.Error())
|
||||
log2.Println("[download.ytdl] Failed to download URL "+URL, " OS PATH ERROR: ", pe.Error())
|
||||
success = false
|
||||
|
||||
} else if err != nil {
|
||||
log.Println("[download.ytdl] Failed to download URL "+URL, " GENERAL ERROR: ", err.Error())
|
||||
log2.Println("[download.ytdl] Failed to download URL "+URL, " GENERAL ERROR: ", err.Error())
|
||||
success = false
|
||||
|
||||
} else {
|
||||
log.Println("[download.ytdl] Downloaded URL " + URL)
|
||||
log2.Println("[download.ytdl] Downloaded URL " + URL)
|
||||
success = true
|
||||
}
|
||||
|
||||
|
@ -143,7 +145,7 @@ func runYTDL(URL string, targetDir string) (success bool) {
|
|||
func matchURL(URL string) (matchedURL string) {
|
||||
parsedURL, err := url.Parse(URL)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log2.Fatal(err)
|
||||
|
||||
}
|
||||
|
||||
|
@ -162,7 +164,7 @@ func matchURL(URL string) (matchedURL string) {
|
|||
func shortURL(URL string) (shorturl string) {
|
||||
resp, err := http.Get(config.BotConfig.Download.Yourls.APIPath + "?signature=" + config.BotConfig.Download.Yourls.Signature + "&action=shorturl&format=simple&url=" + URL)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log2.Fatal(err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
@ -170,7 +172,7 @@ func shortURL(URL string) (shorturl string) {
|
|||
body, err := io.ReadAll(resp.Body)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log2.Fatal(err)
|
||||
}
|
||||
|
||||
return string(body)
|
||||
|
|
|
@ -2,7 +2,7 @@ package gaypoints
|
|||
|
||||
import (
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
"log"
|
||||
"github.com/rs/zerolog/log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"watn3y/bloaterbotv3/botIO"
|
||||
|
@ -12,12 +12,15 @@ import (
|
|||
|
||||
func GetGP(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
||||
|
||||
log.Debug().Int64("chat", update.Message.Chat.ID).Int64("user", update.Message.From.ID).Msg("getting gaypoints")
|
||||
|
||||
if !commonlogic.ContainsInt64(config.BotConfig.GayPoints.EnabledChats, update.Message.Chat.ID) {
|
||||
log.Debug().Int64("chat", update.Message.Chat.ID).Ints64("enabledChats", config.BotConfig.GayPoints.EnabledChats).Msg("not getting gaypoints, chat not enabled")
|
||||
return
|
||||
}
|
||||
|
||||
if update.Message.ReplyToMessage != nil {
|
||||
log.Println("[gaypoints] Looking for gaypoints for user " + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10))
|
||||
log.Debug().Msg("ReplyToMessage not empty, getting gaypoints for individual user")
|
||||
points := sqlGetGP(update.Message.Chat.ID, update.Message.ReplyToMessage.From.ID)
|
||||
|
||||
errorGettingUser, currentUser := botIO.GetUserByID(tgbotapi.ChatConfigWithUser{ChatID: update.Message.Chat.ID, UserID: update.Message.ReplyToMessage.From.ID}, bot)
|
||||
|
@ -27,10 +30,17 @@ func GetGP(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
if currentUser.User.UserName != "" {
|
||||
currentName = currentUser.User.UserName
|
||||
}
|
||||
messagetext = `<a href="` + `tg://user?id=` + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + `">` + currentName + `</a>` + ` currently has ` + `<b>` + strconv.FormatInt(points, 10) + `</b>` + ` gaypoints` + "\n"
|
||||
log.Debug().Int64("user", update.Message.ReplyToMessage.From.ID).Int64("chat", update.Message.Chat.ID).Int64("gp", points).Msg("got details for user")
|
||||
if points == -1 {
|
||||
messagetext = `<a href="` + `tg://user?id=` + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + `">` + currentName + `</a>` + ` currently has no gaypoints` + "\n"
|
||||
|
||||
} else {
|
||||
messagetext = "Something went wrong :("
|
||||
messagetext = `<a href="` + `tg://user?id=` + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + `">` + currentName + `</a>` + ` currently has ` + `<b>` + strconv.FormatInt(points, 10) + `</b>` + ` gaypoints` + "\n"
|
||||
}
|
||||
|
||||
} else {
|
||||
log.Error().Int64("user", update.Message.ReplyToMessage.From.ID).Int64("chat", update.Message.Chat.ID).Msg("error getting details for user")
|
||||
messagetext = "Something went wrong :( Forward me a message from the user and try again. This might fix it."
|
||||
}
|
||||
|
||||
message := tgbotapi.MessageConfig{
|
||||
|
@ -43,20 +53,22 @@ func GetGP(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
botIO.SendMessage(message, bot)
|
||||
return
|
||||
}
|
||||
log.Debug().Msg("ReplyToMessage is empty, getting gaypoints for whole chat")
|
||||
|
||||
log.Println("[gaypoints] Looking for gaypoints for chat " + strconv.FormatInt(update.Message.Chat.ID, 10))
|
||||
gps := sqlGetAllGP(update.Message.Chat.ID)
|
||||
|
||||
var messagetext string
|
||||
for _, gaypointInfo := range gps {
|
||||
errorGettingUser, currentUser := botIO.GetUserByID(tgbotapi.ChatConfigWithUser{ChatID: update.Message.Chat.ID, UserID: gaypointInfo.userID}, bot)
|
||||
if errorGettingUser {
|
||||
log.Error().Int64("user", update.Message.ReplyToMessage.From.ID).Int64("chat", update.Message.Chat.ID).Msg("error getting details for user")
|
||||
continue
|
||||
}
|
||||
currentName := currentUser.User.FirstName
|
||||
if currentUser.User.UserName != "" {
|
||||
currentName = currentUser.User.UserName
|
||||
}
|
||||
log.Debug().Int64("user", gaypointInfo.userID).Int64("chat", update.Message.Chat.ID).Int64("gp", gaypointInfo.gaypoints).Msg("got details for user")
|
||||
text := `<a href="` + `tg://user?id=` + strconv.FormatInt(gaypointInfo.userID, 10) + `">` + currentName + `</a>` + ` currently has ` + `<b>` + strconv.FormatInt(gaypointInfo.gaypoints, 10) + `</b>` + ` gaypoints` + "\n"
|
||||
|
||||
messagetext = messagetext + text
|
||||
|
@ -74,15 +86,19 @@ func GetGP(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
}
|
||||
|
||||
func SetGP(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
||||
log.Debug().Int64("chat", update.Message.Chat.ID).Str("text", update.Message.Text).Msg("setting gaypoints")
|
||||
if !commonlogic.ContainsInt64(config.BotConfig.GayPoints.EnabledChats, update.Message.Chat.ID) {
|
||||
log.Debug().Int64("chat", update.Message.Chat.ID).Ints64("enabledChats", config.BotConfig.GayPoints.EnabledChats).Msg("not setting gaypoints, chat not enabled")
|
||||
return
|
||||
}
|
||||
|
||||
if !commonlogic.ContainsInt64(config.BotConfig.GayPoints.ModifyUsers, update.Message.From.ID) {
|
||||
log.Debug().Int64("chat", update.Message.Chat.ID).Ints64("enabledChats", config.BotConfig.GayPoints.ModifyUsers).Msg("not setting gaypoints, user not authorised")
|
||||
sticker := tgbotapi.StickerConfig{BaseFile: tgbotapi.BaseFile{
|
||||
BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID},
|
||||
File: tgbotapi.FilePath("bloater.webp"),
|
||||
}}
|
||||
|
||||
botIO.SendSticker(sticker, bot)
|
||||
return
|
||||
|
||||
|
@ -98,41 +114,41 @@ func SetGP(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
} else {
|
||||
arg = ""
|
||||
}
|
||||
log.Println("[gaypoints] Trying to modify gaypoints for user " + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10))
|
||||
|
||||
if update.Message.ReplyToMessage == nil {
|
||||
log.Error().Int64("chat", update.Message.Chat.ID).Msg("failed to set gaypoints for user, ReplyToMessage not present")
|
||||
message := tgbotapi.MessageConfig{
|
||||
BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID},
|
||||
ParseMode: "html",
|
||||
DisableWebPagePreview: false,
|
||||
Text: "Please reply to a message to set gaypoints",
|
||||
}
|
||||
log.Println("[gaypoints] Failed to set gaypoints for user " + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10))
|
||||
botIO.SendMessage(message, bot)
|
||||
return
|
||||
}
|
||||
|
||||
if arg == "" {
|
||||
log.Error().Int64("chat", update.Message.Chat.ID).Msg("failed to set gaypoints for user, empty value")
|
||||
message := tgbotapi.MessageConfig{
|
||||
BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID},
|
||||
ParseMode: "html",
|
||||
DisableWebPagePreview: false,
|
||||
Text: "Please specify a valid gaypoint value",
|
||||
Text: "Please specify a valid gaypoint value. Your current value seems to be empty.",
|
||||
}
|
||||
log.Println("[gaypoints] Failed to set gaypoints for user " + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10))
|
||||
botIO.SendMessage(message, bot)
|
||||
return
|
||||
}
|
||||
|
||||
newPoints, err := strconv.ParseInt(arg, 10, 64)
|
||||
if err != nil || newPoints <= 0 {
|
||||
log.Error().Int64("chat", update.Message.Chat.ID).Msg("failed to set gaypoints for user, invalid value or value <= 0")
|
||||
message := tgbotapi.MessageConfig{
|
||||
BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID},
|
||||
ParseMode: "html",
|
||||
DisableWebPagePreview: false,
|
||||
Text: "Please specify a valid gaypoint value",
|
||||
Text: "Please specify a valid gaypoint value. Your current value was either too low or I was not able to parse it correctly.",
|
||||
}
|
||||
log.Println("[gaypoints] Failed to set gaypoints for user " + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10))
|
||||
|
||||
botIO.SendMessage(message, bot)
|
||||
return
|
||||
}
|
||||
|
@ -142,7 +158,7 @@ func SetGP(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
|
||||
if cmd == "addgp" {
|
||||
currentPoints = sqlGetGP(update.Message.Chat.ID, update.Message.ReplyToMessage.From.ID)
|
||||
if currentPoints <= -1 {
|
||||
if currentPoints <= 0 {
|
||||
finalgp = newPoints
|
||||
} else {
|
||||
finalgp = currentPoints + newPoints
|
||||
|
@ -150,15 +166,15 @@ func SetGP(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
}
|
||||
|
||||
if cmd == "subtractgp" {
|
||||
log.Error().Int64("chat", update.Message.Chat.ID).Msg("failed to set gaypoints for user, new value is < 0")
|
||||
currentPoints = sqlGetGP(update.Message.Chat.ID, update.Message.ReplyToMessage.From.ID)
|
||||
if currentPoints <= 0 {
|
||||
if currentPoints-newPoints < 0 {
|
||||
message := tgbotapi.MessageConfig{
|
||||
BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID},
|
||||
ParseMode: "html",
|
||||
DisableWebPagePreview: false,
|
||||
Text: "Please specify a valid gaypoint value",
|
||||
Text: "Please specify a valid gaypoint value. After subtracting your current value from the users current gaypoints, they would have < 0 gaypoints. This is not allowed.",
|
||||
}
|
||||
log.Println("[gaypoints] Failed to subtrackt gaypoints for user " + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10))
|
||||
|
||||
botIO.SendMessage(message, bot)
|
||||
return
|
||||
} else {
|
||||
|
@ -174,11 +190,11 @@ func SetGP(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
if currentUser.User.UserName != "" {
|
||||
currentName = currentUser.User.UserName
|
||||
}
|
||||
log.Debug().Int64("user", update.Message.ReplyToMessage.From.ID).Int64("chat", update.Message.Chat.ID).Msg("got details for user")
|
||||
messagetext = `<a href="` + `tg://user?id=` + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + `">` + currentName + `</a>` + ` now has ` + `<b>` + strconv.FormatInt(finalgp, 10) + `</b>` + ` gaypoints` + "\n"
|
||||
} else {
|
||||
messagetext = "Something went wrong :("
|
||||
log.Println("[gaypoints] Failed to change gaypoints " + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10) + " from " + strconv.FormatInt(currentPoints, 10) + " to " + strconv.FormatInt(finalgp, 10))
|
||||
|
||||
log.Error().Int64("user", update.Message.ReplyToMessage.From.ID).Int64("chat", update.Message.Chat.ID).Msg("error getting details for user")
|
||||
messagetext = "Something went wrong :( Forward me a message from the user and try again. This might fix it."
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -189,7 +205,7 @@ func SetGP(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
Text: messagetext,
|
||||
}
|
||||
|
||||
log.Println("[gaypoints] Changing gaypoints " + strconv.FormatInt(update.Message.ReplyToMessage.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10) + " from " + strconv.FormatInt(currentPoints, 10) + " to " + strconv.FormatInt(finalgp, 10))
|
||||
log.Info().Int64("oldGP", currentPoints).Int64("newGP", finalgp).Int64("user", update.Message.ReplyToMessage.From.ID).Int64("chat", update.Message.Chat.ID).Int64("changedBy", update.Message.From.ID).Msg("setting gaypoints")
|
||||
|
||||
sqlSetGP(update.Message.Chat.ID, update.Message.ReplyToMessage.From.ID, finalgp)
|
||||
botIO.SendMessage(message, bot)
|
||||
|
|
|
@ -3,8 +3,7 @@ package gaypoints
|
|||
import (
|
||||
"database/sql"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"log"
|
||||
"strconv"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var gpSelectUser *sql.Stmt
|
||||
|
@ -16,7 +15,8 @@ var gpSet *sql.Stmt
|
|||
func sqlGetAllGP(chatid int64) (gaypoints []gaypointShortDetails) {
|
||||
rows, err := gpSelectChat.Query(chatid)
|
||||
if err != nil {
|
||||
log.Panicf("Failed to query gaypoints: %v\n", err)
|
||||
log.Error().Err(err).Msg("failed to execute SQL to get get gaypoints for chat")
|
||||
return
|
||||
}
|
||||
|
||||
var c int64
|
||||
|
@ -29,10 +29,11 @@ func sqlGetAllGP(chatid int64) (gaypoints []gaypointShortDetails) {
|
|||
gaypoints: b,
|
||||
})
|
||||
default:
|
||||
log.Panicf("Failed to query gaypoints: %v\n", err)
|
||||
log.Error().Err(err).Msg("failed to parse SQL to get get gaypoints for chat")
|
||||
return
|
||||
|
||||
}
|
||||
log.Println("[gaypoints.sql] Got gaypoints for " + strconv.FormatInt(c, 10) + " in chat " + strconv.FormatInt(chatid, 10) + ". Value is " + strconv.FormatInt(b, 10))
|
||||
log.Debug().Msg("executed SQL to get gaypoints for chat")
|
||||
}
|
||||
|
||||
return gaypoints
|
||||
|
@ -48,50 +49,53 @@ func sqlGetGP(chatid int64, userid int64) (gaypoints int64) {
|
|||
case nil:
|
||||
break
|
||||
default:
|
||||
log.Panicf("Failed to query gaypoints: %v\n", err)
|
||||
log.Error().Err(err).Msg("failed to execute SQL to get get gaypoints for user")
|
||||
return
|
||||
|
||||
}
|
||||
log.Println("[gaypoints.sql] Got gaypoints for " + strconv.FormatInt(userid, 10) + " in chat " + strconv.FormatInt(chatid, 10) + ". Value is " + strconv.FormatInt(gaypoints, 10))
|
||||
log.Debug().Msg("executed SQL to get gaypoints for user")
|
||||
return gaypoints
|
||||
}
|
||||
|
||||
func sqlSetGP(chatid int64, userid int64, gaypoints int64) {
|
||||
_, err := gpSet.Exec(chatid, userid, gaypoints)
|
||||
if err != nil {
|
||||
log.Panicf("Failed to set gaypoints: %v\n", err)
|
||||
log.Error().Err(err).Msg("failed to execute SQL to get set gaypoints for user")
|
||||
return
|
||||
}
|
||||
log.Println("[gaypoints.sql] Set gaypoints for " + strconv.FormatInt(userid, 10) + " in chat " + strconv.FormatInt(chatid, 10) + " to " + strconv.FormatInt(gaypoints, 10))
|
||||
log.Debug().Msg("executed SQL to set gaypoints for user")
|
||||
}
|
||||
|
||||
func InitDB() {
|
||||
const dbPath string = "./bloater.db"
|
||||
log.Info().Str("dbpath", dbPath).Msg("init database")
|
||||
db, err := sql.Open("sqlite3", dbPath)
|
||||
if err != nil {
|
||||
log.Panicf("Failed to open sqlite database: %v\n", err)
|
||||
log.Panic().Err(err).Msg("failed to open sqlite database")
|
||||
}
|
||||
|
||||
_, err = db.Exec("CREATE TABLE IF NOT EXISTS gaypoints (chatid bigint, userid bigint,gaypoints bigint,UNIQUE(chatid,userid))")
|
||||
if err != nil {
|
||||
log.Panicf("Failed to create table: %v\n", err)
|
||||
log.Panic().Err(err).Msg("failed to create table")
|
||||
}
|
||||
log.Println("[gaypoints.sql] Created sqlite table in database at " + dbPath)
|
||||
|
||||
gpSelectUser, err = db.Prepare("SELECT gaypoints FROM gaypoints WHERE chatid = ? AND userid = ?")
|
||||
|
||||
if err != nil {
|
||||
log.Panicf("Failed to prepare sql select: %v\n", err)
|
||||
log.Panic().Err(err).Msg("failed to create sql statement")
|
||||
}
|
||||
|
||||
gpSelectChat, err = db.Prepare("SELECT userid,gaypoints FROM gaypoints WHERE chatid = ? ORDER BY gaypoints DESC")
|
||||
|
||||
if err != nil {
|
||||
log.Panicf("Failed to prepare sql select: %v\n", err)
|
||||
log.Panic().Err(err).Msg("failed to create sql statement")
|
||||
}
|
||||
|
||||
gpSet, err = db.Prepare("INSERT OR REPLACE INTO gaypoints (chatid, userid, gaypoints) values (?,?,?)")
|
||||
|
||||
if err != nil {
|
||||
log.Panicf("Failed to prepare sql insert: %v\n", err)
|
||||
log.Panic().Err(err).Msg("failed to create sql statement")
|
||||
}
|
||||
|
||||
log.Info().Msg("init database: done")
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package notify
|
|||
|
||||
import (
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
"log"
|
||||
"github.com/rs/zerolog/log"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -11,6 +11,7 @@ import (
|
|||
)
|
||||
|
||||
func Reminder(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
||||
log.Debug().Str("args", update.Message.CommandArguments()).Msg("parsing new reminder")
|
||||
commandArgs := strings.Fields(update.Message.CommandArguments())
|
||||
|
||||
var timeArg string
|
||||
|
@ -20,6 +21,7 @@ func Reminder(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
timeArg = strings.ToLower(commandArgs[0])
|
||||
textArg = strings.Replace(update.Message.CommandArguments(), timeArg, "", 1)
|
||||
} else {
|
||||
log.Error().Str("args", update.Message.CommandArguments()).Msg("invalid new reminder")
|
||||
message := tgbotapi.MessageConfig{
|
||||
BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID},
|
||||
ParseMode: "html",
|
||||
|
@ -30,11 +32,10 @@ func Reminder(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
return
|
||||
}
|
||||
|
||||
log.Println("[notify] Attempting to set reminder for user " + strconv.FormatInt(update.Message.From.ID, 10) + " in chat " + strconv.FormatInt(update.Message.Chat.ID, 10) + " with arguments " + timeArg)
|
||||
|
||||
isValidFormat := regexp.MustCompile(`(?m)^\d{1,3}[mhd]$`)
|
||||
|
||||
if !isValidFormat.MatchString(timeArg) {
|
||||
log.Error().Str("args", update.Message.CommandArguments()).Msg("invalid new reminder")
|
||||
message := tgbotapi.MessageConfig{
|
||||
BaseChat: tgbotapi.BaseChat{ChatID: update.Message.Chat.ID, ReplyToMessageID: update.Message.MessageID},
|
||||
ParseMode: "html",
|
||||
|
@ -64,9 +65,7 @@ func Reminder(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
|
||||
notifyTime := time.Now().UTC().Add(time.Duration(number) * modifyTime)
|
||||
|
||||
var reminder reminderConfig
|
||||
|
||||
reminder = reminderConfig{
|
||||
reminder := reminderConfig{
|
||||
updateID: update.UpdateID,
|
||||
notifyTime: notifyTime.Unix(),
|
||||
chatID: update.Message.Chat.ID,
|
||||
|
@ -75,6 +74,8 @@ func Reminder(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
reminderText: textArg,
|
||||
}
|
||||
|
||||
log.Info().Int("ID", reminder.updateID).Int64("chat", reminder.chatID).Int64("user", reminder.userID).Int64("time", reminder.notifyTime).Msg("adding new reminder")
|
||||
|
||||
sqlAddReminder(reminder)
|
||||
|
||||
message := tgbotapi.MessageConfig{
|
||||
|
@ -95,17 +96,19 @@ func NotifyHandler(bot *tgbotapi.BotAPI) {
|
|||
|
||||
for updateID, reminderTime := range reminders {
|
||||
if reminderTime <= time.Now().UTC().Unix() {
|
||||
log.Info().Int("ID", updateID).Msg("reminder is due")
|
||||
details := sqlGetReminderDetails(updateID)
|
||||
|
||||
message := tgbotapi.MessageConfig{
|
||||
BaseChat: tgbotapi.BaseChat{ChatID: details.chatID, ReplyToMessageID: details.messageToReplyToID},
|
||||
ParseMode: "html",
|
||||
DisableWebPagePreview: false,
|
||||
|
||||
Text: details.reminderText,
|
||||
Text: "Reminder: " + details.reminderText,
|
||||
}
|
||||
log.Info().Int64("chat", details.chatID).Int64("user", details.userID).Str("text", details.reminderText).Msg("sent reminder")
|
||||
|
||||
botIO.SendMessage(message, bot)
|
||||
|
||||
sqlDeleteReminder(updateID)
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,7 @@ package notify
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"strconv"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var notifySetReminder *sql.Stmt
|
||||
|
@ -13,61 +12,69 @@ var notifyDeleteReminder *sql.Stmt
|
|||
|
||||
func InitDB() {
|
||||
const dbPath string = "./bloater.db"
|
||||
log.Info().Str("dbpath", dbPath).Msg("init database")
|
||||
db, err := sql.Open("sqlite3", dbPath)
|
||||
if err != nil {
|
||||
log.Panicf("Failed to open sqlite database: %v\n", err)
|
||||
log.Panic().Err(err).Msg("failed to open sqlite database")
|
||||
}
|
||||
|
||||
_, err = db.Exec("CREATE TABLE IF NOT EXISTS notify (updateID INTEGER,notifyTime INTEGER,chatID INTEGER, userID INTEGER,messageToReplyToID INTEGER,notifyText TEXT)")
|
||||
if err != nil {
|
||||
log.Panicf("Failed to create table: %v\n", err)
|
||||
log.Panic().Err(err).Msg("failed to create table")
|
||||
}
|
||||
log.Println("[notify.sql] Created sqlite table in database at " + dbPath)
|
||||
|
||||
notifySetReminder, err = db.Prepare("INSERT OR REPLACE INTO notify (updateID,notifyTime,chatID, userID,messageToReplyToID,notifyText) values (?,?,?,?,?,?)")
|
||||
|
||||
if err != nil {
|
||||
log.Panicf("Failed to prepare sql insert: %v\n", err)
|
||||
log.Panic().Err(err).Msg("failed to create sql statement")
|
||||
}
|
||||
|
||||
notifyGetReminders, err = db.Prepare("SELECT updateID,notifyTime FROM notify")
|
||||
|
||||
if err != nil {
|
||||
log.Panicf("Failed to prepare sql select: %v\n", err)
|
||||
log.Panic().Err(err).Msg("failed to create sql statement")
|
||||
}
|
||||
|
||||
notifyGetReminderDetails, err = db.Prepare("SELECT chatID, userID,messageToReplyToID,notifyText FROM notify WHERE updateID=?")
|
||||
|
||||
if err != nil {
|
||||
log.Panicf("Failed to prepare sql select: %v\n", err)
|
||||
log.Panic().Err(err).Msg("failed to create sql statement")
|
||||
}
|
||||
|
||||
notifyDeleteReminder, err = db.Prepare("DELETE FROM notify WHERE updateID=?")
|
||||
|
||||
if err != nil {
|
||||
log.Panicf("Failed to prepare sql select: %v\n", err)
|
||||
log.Panic().Err(err).Msg("failed to create sql statement")
|
||||
}
|
||||
|
||||
log.Info().Msg("init database: done")
|
||||
}
|
||||
|
||||
func sqlDeleteReminder(updateID int) {
|
||||
_, err := notifyDeleteReminder.Exec(updateID)
|
||||
if err != nil {
|
||||
log.Panicf("Failed to delete reminder: %v\n", err)
|
||||
log.Error().Err(err).Msg("failed to execute SQL to delete reminder")
|
||||
return
|
||||
}
|
||||
|
||||
log.Debug().Msg("executed SQL to delete reminder")
|
||||
}
|
||||
|
||||
func sqlAddReminder(reminder reminderConfig) {
|
||||
_, err := notifySetReminder.Exec(reminder.updateID, reminder.notifyTime, reminder.chatID, reminder.userID, reminder.messageToReplyToID, reminder.reminderText)
|
||||
if err != nil {
|
||||
log.Panicf("Failed to set add reminder: %v\n", err)
|
||||
log.Error().Err(err).Msg("failed to execute SQL to add reminder")
|
||||
return
|
||||
}
|
||||
log.Println("[notify.sql] Set new reminder for " + strconv.FormatInt(reminder.userID, 10) + " in chat " + strconv.FormatInt(reminder.chatID, 10))
|
||||
|
||||
log.Debug().Msg("executed SQL to add reminder")
|
||||
}
|
||||
|
||||
func sqlGetReminders() (reminders map[int]int64) {
|
||||
rows, err := notifyGetReminders.Query()
|
||||
if err != nil {
|
||||
log.Panicf("Failed to query reminders: %v\n", err)
|
||||
log.Error().Err(err).Msg("failed to execute SQL to get reminder")
|
||||
return
|
||||
}
|
||||
|
||||
reminders = make(map[int]int64)
|
||||
|
@ -78,11 +85,13 @@ func sqlGetReminders() (reminders map[int]int64) {
|
|||
case nil:
|
||||
reminders[c] = b
|
||||
default:
|
||||
log.Panicf("Failed to query gaypoints: %v\n", err)
|
||||
log.Error().Err(err).Msg("failed to parse SQL to get reminder")
|
||||
return
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
log.Debug().Msg("executed SQL to get reminders")
|
||||
return reminders
|
||||
}
|
||||
|
||||
|
@ -93,9 +102,10 @@ func sqlGetReminderDetails(updateID int) (reminder reminderConfig) {
|
|||
case nil:
|
||||
break
|
||||
default:
|
||||
log.Panicf("Failed to get reminder details: %v\n", err)
|
||||
log.Error().Err(err).Msg("failed to execute SQL to get reminder details")
|
||||
return
|
||||
|
||||
}
|
||||
log.Println("[notify.sql] Got reminder details for update ID" + string(rune(updateID)))
|
||||
log.Debug().Msg("executed SQL to get reminder details")
|
||||
return reminder
|
||||
}
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
APIToken = "073fv3b07tvrudgbdf"
|
||||
DebugMode = true
|
||||
PrivilegedUsers = [1212121212]
|
||||
|
||||
[Nhentai]
|
||||
APIEndpoint = "0.0.0.0"
|
||||
Domain = "https://nhentai.net"
|
||||
EnabledChats = [-00000,-111111,-22222]
|
||||
|
||||
[Balonlyl]
|
||||
EnabledChats = [-1001462089309]
|
||||
BalonlylAT = "@Balonlyl"
|
||||
TriggerWords = ["french","france","baguette","casque bleu"]
|
||||
|
||||
|
||||
[GayPoints]
|
||||
EnabledChats = [-00000,-111111,-22222]
|
||||
ModifyUsers = [-00000,-111111,-22222]
|
||||
|
||||
[Download]
|
||||
Prefix = "http://192.168.0.10:3556"
|
||||
[Download.Yourls]
|
||||
APIPath = "https://yourl.tld/yourls-api.php"
|
||||
Signature = "u8zibfd876sfvb"
|
||||
|
|
@ -2,7 +2,7 @@ package config
|
|||
|
||||
import (
|
||||
"github.com/BurntSushi/toml"
|
||||
"log"
|
||||
"github.com/rs/zerolog/log"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
@ -12,11 +12,6 @@ type config struct {
|
|||
DebugMode bool
|
||||
PrivilegedUsers []int64
|
||||
Shutup map[int64]time.Time
|
||||
Nhentai struct {
|
||||
EnabledChats []int64
|
||||
APIEndpoint string
|
||||
Domain string
|
||||
}
|
||||
Balonlyl struct {
|
||||
EnabledChats []int64
|
||||
BalonlylAT string
|
||||
|
@ -38,17 +33,20 @@ type config struct {
|
|||
var BotConfig config
|
||||
|
||||
func LoadConfig() {
|
||||
|
||||
configFile, err := os.ReadFile("config.toml")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Panic().Err(err).Msg("rror opening config file")
|
||||
}
|
||||
|
||||
_, err = toml.Decode(string(configFile), &BotConfig)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Panic().Err(err).Msg("error decoding config file")
|
||||
}
|
||||
|
||||
BotConfig.Shutup = make(map[int64]time.Time)
|
||||
|
||||
log.Printf("[config] Config loaded as: %+v\n", BotConfig)
|
||||
log.Info().Msg("loaded config file")
|
||||
log.Debug().Interface("config", BotConfig).Msg("")
|
||||
|
||||
}
|
||||
|
|
4
go.mod
4
go.mod
|
@ -6,4 +6,8 @@ require (
|
|||
github.com/BurntSushi/toml v1.3.2
|
||||
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1
|
||||
github.com/mattn/go-sqlite3 v1.14.17
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/rs/zerolog v1.30.0
|
||||
golang.org/x/sys v0.12.0 // indirect
|
||||
)
|
||||
|
|
19
go.sum
19
go.sum
|
@ -1,6 +1,25 @@
|
|||
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
|
||||
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
|
||||
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
|
||||
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c=
|
||||
github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
|
15
main.go
15
main.go
|
@ -1,6 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"os"
|
||||
"time"
|
||||
"watn3y/bloaterbotv3/commands/gaypoints"
|
||||
"watn3y/bloaterbotv3/commands/notify"
|
||||
"watn3y/bloaterbotv3/config"
|
||||
|
@ -8,6 +13,9 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Starting bloaterbot...")
|
||||
|
||||
configureLogger()
|
||||
config.LoadConfig()
|
||||
gaypoints.InitDB()
|
||||
notify.InitDB()
|
||||
|
@ -15,3 +23,10 @@ func main() {
|
|||
bot()
|
||||
|
||||
}
|
||||
|
||||
func configureLogger() {
|
||||
output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.DateTime}
|
||||
log.Logger = zerolog.New(output).With().Timestamp().Caller().Logger()
|
||||
zerolog.SetGlobalLevel(zerolog.TraceLevel)
|
||||
log.Info().Msg("Started zerolog logger")
|
||||
}
|
||||
|
|
|
@ -2,27 +2,17 @@ package balonlyl
|
|||
|
||||
import (
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
"log"
|
||||
"strconv"
|
||||
"watn3y/bloaterbotv3/botIO"
|
||||
"watn3y/bloaterbotv3/config"
|
||||
)
|
||||
|
||||
func Balonlyl(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
||||
|
||||
/*balonlylLines := [4]string{
|
||||
balonlylAT + " they're talking about you",
|
||||
"Bitch " + balonlylAT + " they're shittalking you again",
|
||||
"Bruh wtf " + balonlylAT + ", again",
|
||||
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",
|
||||
DisableWebPagePreview: true,
|
||||
//Text: balonlylLines[rand.Intn(len(balonlylLines))],
|
||||
|
||||
Text: config.BotConfig.Balonlyl.BalonlylAT,
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package text
|
|||
|
||||
import (
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
"github.com/rs/zerolog/log"
|
||||
"strings"
|
||||
"time"
|
||||
"watn3y/bloaterbotv3/commonlogic"
|
||||
|
@ -11,11 +12,14 @@ import (
|
|||
|
||||
func Matcher(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
||||
|
||||
log.Debug().Str("text", update.Message.Text).Int64("chat", update.Message.Chat.ID).Msg("Starting text matcher")
|
||||
|
||||
if time.Since(config.BotConfig.Shutup[update.Message.Chat.ID]) <= time.Minute*60 {
|
||||
log.Debug().Str("text", update.Message.Text).Int64("chat", update.Message.Chat.ID).Msg("Aborting due to shut-up")
|
||||
return
|
||||
}
|
||||
//balonlyl
|
||||
var isBalonlyl bool = false
|
||||
var isBalonlyl = false
|
||||
for _, word := range config.BotConfig.Balonlyl.TriggerWords {
|
||||
if strings.Contains(strings.ToLower(update.Message.Text), word) && (commonlogic.ContainsInt64(config.BotConfig.Balonlyl.EnabledChats, update.Message.Chat.ID)) {
|
||||
isBalonlyl = true
|
||||
|
@ -23,6 +27,7 @@ func Matcher(update tgbotapi.Update, bot *tgbotapi.BotAPI) {
|
|||
}
|
||||
}
|
||||
if isBalonlyl {
|
||||
log.Debug().Str("text", update.Message.Text).Int64("chat", update.Message.Chat.ID).Msg("Matched Balonlyl meme")
|
||||
go balonlyl.Balonlyl(update, bot)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
package nhentai
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"watn3y/bloaterbotv3/config"
|
||||
)
|
||||
|
||||
func doAPIRequest(hentaiID string) (exists bool, Details nhentaiResponse) {
|
||||
|
||||
client := &http.Client{}
|
||||
|
||||
req, err := http.NewRequest("GET", config.BotConfig.Nhentai.APIEndpoint+"/gallery/"+hentaiID, nil)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
req.Header.Set("User-Agent", "Golang_Spider_Bot/3.0")
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
if resp.StatusCode == 404 {
|
||||
return false, nhentaiResponse{}
|
||||
} else if resp.StatusCode != 200 {
|
||||
return false, nhentaiResponse{}
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
var hentai nhentaiResponse
|
||||
if err := json.Unmarshal(body, &hentai); err != nil { // Parse []byte to the go struct pointer
|
||||
fmt.Println("Can not unmarshal JSON")
|
||||
}
|
||||
|
||||
return true, hentai
|
||||
|
||||
}
|
||||
|
||||
func parseAPIResponse(rawHentai nhentaiResponse) (formattedHentai hentai) {
|
||||
var hentai = hentai{
|
||||
ID: rawHentai.ID,
|
||||
Title: rawHentai.Title.Pretty,
|
||||
UploadDate: rawHentai.UploadDate,
|
||||
}
|
||||
|
||||
for _, tag := range rawHentai.Tags {
|
||||
if tag.Type == "tag" {
|
||||
hentai.Tags = append(hentai.Tags, struct {
|
||||
Name string
|
||||
URL string
|
||||
}{Name: tag.Name, URL: tag.URL})
|
||||
|
||||
} /* else if tag.Type == "parody" {
|
||||
|
||||
} else if tag.Type == "character" {
|
||||
|
||||
} else if tag.Type == "language" {
|
||||
|
||||
} else if tag.Type == "group" {
|
||||
|
||||
} else if tag.Type == "artist" {
|
||||
|
||||
} else if tag.Type == "category" {
|
||||
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
return hentai
|
||||
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
package nhentai
|
||||
|
||||
type nhentaiResponse struct {
|
||||
ID int `json:"id"`
|
||||
Title struct {
|
||||
English string `json:"english,omitempty"`
|
||||
Chinese string `json:"chinese,omitempty"`
|
||||
Japanese string `json:"japanese,omitempty"`
|
||||
Pretty string `json:"pretty,omitempty"`
|
||||
} `json:"title,omitempty"`
|
||||
UploadDate int `json:"upload_date"`
|
||||
Tags []struct {
|
||||
Type string `json:"type"`
|
||||
Name string `json:"name"`
|
||||
URL string `json:"url"`
|
||||
} `json:"tags"`
|
||||
}
|
||||
|
||||
type hentai struct {
|
||||
ID int
|
||||
Title string
|
||||
UploadDate int
|
||||
/*
|
||||
Language struct { //since there can be multiple languages I won't implement this shit
|
||||
Name string
|
||||
URL string
|
||||
}
|
||||
Artist struct {
|
||||
Name string
|
||||
URL string
|
||||
}
|
||||
Group struct {
|
||||
Name string
|
||||
URL string
|
||||
}
|
||||
Category struct {
|
||||
Name string
|
||||
URL string
|
||||
}
|
||||
|
||||
Character struct {
|
||||
Name string
|
||||
URL string
|
||||
}
|
||||
|
||||
Parody struct {
|
||||
Name string
|
||||
URL string
|
||||
}
|
||||
*/
|
||||
|
||||
Tags []struct {
|
||||
Name string
|
||||
URL string
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package webserver
|
||||
|
||||
import (
|
||||
"log"
|
||||
"github.com/rs/zerolog/log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
@ -9,9 +9,12 @@ func RunWeb() {
|
|||
fs := http.FileServer(http.Dir("./videos"))
|
||||
http.Handle("/", fs)
|
||||
|
||||
log.Print("Listening on :3556...")
|
||||
log.Info().Str("port", "3556").Str("path", "./videos").Msg("Starting webserver")
|
||||
|
||||
err := http.ListenAndServe(":3556", nil)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Panic().Err(err).Msg("Failed to start webserver")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue