Compare commits

...

1 commit

Author SHA1 Message Date
c52070ddd9
add some changes 2024-10-29 11:15:55 +01:00
3 changed files with 74 additions and 0 deletions

61
error/notifydiscord.go Normal file
View file

@ -0,0 +1,61 @@
/*
* Copyright (c) 2023 Laura Kalb <dev@lauka.net>
* The code of this project is available under the MIT license. See the LICENSE file for more info.
*
*/
package error
import (
"codeberg.org/lauralani/humble-bot/misc"
"codeberg.org/lauralani/humble-bot/models"
"encoding/json"
"fmt"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"io/ioutil"
"net/http"
"net/url"
)
func NotifyDiscord(message models.DiscordMessage) {
_, urlerr := url.ParseRequestURI(viper.GetString("errorhandling.discordhook"))
if urlerr != nil || message.Content == "" {
log.Error().Str("integration", "discord").Str("config", "errorhandling.discordhook").Msgf("Tried to send discord error message, but" +
"message was empty or discord hook url in config is invalid. Message: %q", message.Content)
return
}
url := "https://discord.com/api/webhooks/1146044096029405226/GJ-KfB7NIgAhuf8soP_DvxbOui5E8yLrR4hzAZDgL6BLTxlqymsGTA0Q1weM90fMjLUa"
method := "POST"
payload, err := json.Marshal(message)
if err != nil {
log.Error().Str("func", "NotifyDiscord").Msgf("Can't marshal disocrd message: %q", err)
}
client := misc.CustomHttpClient()
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Cookie", "__cfruid=52458531a20bc4c09fc012c806f897199e3e5bed-1693308636; __dcfduid=797cba3c465f11ee9d809a4b39b1053e; __sdcfduid=797cba3c465f11ee9d809a4b39b1053e004a6a0e48439b5049639654379f965153994920b12b1713669e63cabceb2f7a; _cfuvid=OdkJt_LIxefbXs_wHs.2k94vJD0kWpNzWTxAGVu2tjQ-1693308636963-0-604800000")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
}

View file

@ -322,6 +322,8 @@ type Games struct {
CsrfFormKey string `json:"csrfFormKey"` CsrfFormKey string `json:"csrfFormKey"`
} }
const test := Software.UserOptions.IsLoggedIn
type Software struct { type Software struct {
UserOptions struct { UserOptions struct {
IsLoggedIn bool `json:"is_logged_in"` IsLoggedIn bool `json:"is_logged_in"`

11
models/discord.go Normal file
View file

@ -0,0 +1,11 @@
/*
* Copyright (c) 2023 Laura Kalb <dev@lauka.net>
* The code of this project is available under the MIT license. See the LICENSE file for more info.
*
*/
package models
type DiscordMessage struct {
Content string `json:"content"`
}