added github links to logs
This commit is contained in:
25
custom/custom.go
Normal file
25
custom/custom.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package custom
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var color map[string]string = map[string]string{
|
||||||
|
"red": "#FF6B6B",
|
||||||
|
"yellow": "#FFD93D",
|
||||||
|
"green": "#6BCB77",
|
||||||
|
"blue": "#008DDA",
|
||||||
|
"primary": "#211951",
|
||||||
|
}
|
||||||
|
|
||||||
|
var Gh_url string = "https://github.com/vaporvee/acecore/blob/main/"
|
||||||
|
|
||||||
|
func GetColor(s string) int {
|
||||||
|
hexColor := strings.TrimPrefix(color[s], "#")
|
||||||
|
decimal, err := strconv.ParseInt(hexColor, 16, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return int(decimal)
|
||||||
|
}
|
2
go.mod
2
go.mod
@@ -15,3 +15,5 @@ require (
|
|||||||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
|
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
|
||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
|
replace github.com/vaporvee/acecore/custom => ./custom
|
||||||
|
@@ -6,7 +6,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/vaporvee/acecore/custom"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Log struct {
|
type Log struct {
|
||||||
@@ -23,6 +28,7 @@ type Message struct {
|
|||||||
type Embed struct {
|
type Embed struct {
|
||||||
Author Author `json:"author"`
|
Author Author `json:"author"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
|
URL string `json:"url"`
|
||||||
Color string `json:"color"`
|
Color string `json:"color"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Footer Footer `json:"footer"`
|
Footer Footer `json:"footer"`
|
||||||
@@ -43,6 +49,12 @@ func (cw *WebhookWriter) Write(p []byte) (n int, err error) {
|
|||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RootDir() string {
|
||||||
|
_, b, _, _ := runtime.Caller(0)
|
||||||
|
d := path.Join(path.Dir(b))
|
||||||
|
return filepath.Dir(d)
|
||||||
|
}
|
||||||
|
|
||||||
func webhook(p []byte) {
|
func webhook(p []byte) {
|
||||||
webhookURL := os.Getenv("LOG_WEBHOOK")
|
webhookURL := os.Getenv("LOG_WEBHOOK")
|
||||||
if webhookURL == "" || !strings.HasPrefix(webhookURL, "http://") && !strings.HasPrefix(webhookURL, "https://") {
|
if webhookURL == "" || !strings.HasPrefix(webhookURL, "http://") && !strings.HasPrefix(webhookURL, "https://") {
|
||||||
@@ -54,13 +66,15 @@ func webhook(p []byte) {
|
|||||||
if logJson.Level == "error" {
|
if logJson.Level == "error" {
|
||||||
color = "16739179"
|
color = "16739179"
|
||||||
}
|
}
|
||||||
|
fileArray := strings.Split(strings.TrimPrefix(logJson.File, RootDir()), ":")
|
||||||
m := Message{
|
m := Message{
|
||||||
Embeds: []Embed{
|
Embeds: []Embed{
|
||||||
{
|
{
|
||||||
Author: Author{
|
Author: Author{
|
||||||
Name: logJson.File,
|
Name: logJson.Function,
|
||||||
},
|
},
|
||||||
Title: logJson.Function,
|
Title: "\"" + fileArray[0] + "\" on line " + fileArray[1],
|
||||||
|
URL: strings.TrimSuffix(custom.Gh_url, "/") + fileArray[0] + "#L" + fileArray[1],
|
||||||
Color: color,
|
Color: color,
|
||||||
Description: logJson.Message,
|
Description: logJson.Message,
|
||||||
Footer: Footer{
|
Footer: Footer{
|
||||||
|
Reference in New Issue
Block a user