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,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
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue