Set build hash and pipeline link through LDFlags

Add custom command values to config
This commit is contained in:
Michał Gdula 2025-04-24 19:32:32 +01:00
parent eb50802d1e
commit a0bb37fc06
5 changed files with 36 additions and 21 deletions

View file

@ -5,7 +5,6 @@ import (
"runtime"
"runtime/debug"
"strings"
"time"
"github.com/Fluffy-Bean/lynxie/app"
"github.com/Fluffy-Bean/lynxie/utils"
@ -21,7 +20,8 @@ func registerDebug(a *app.App) app.Callback {
buildTags := "-"
goVersion := strings.TrimPrefix(runtime.Version(), "go")
gcCount := runtime.MemStats{}.NumGC
localTime := time.Now().Local().Format("2006-01-02 15:04:05")
buildHash, _ := a.Config.CommandExtras["debug_build-hash"]
buildPipeline, _ := a.Config.CommandExtras["debug_build-pipeline"]
latency := h.Session.HeartbeatLatency().Milliseconds()
info, _ := debug.ReadBuildInfo()
@ -57,8 +57,8 @@ func registerDebug(a *app.App) app.Callback {
Inline: false,
},
{
Name: "Local Time",
Value: localTime,
Name: "Build Hash",
Value: fmt.Sprintf("[%s](%s)", buildHash, buildPipeline),
Inline: false,
},
{

View file

@ -6,7 +6,6 @@ import (
"fmt"
"log"
"net/http"
"os"
"strings"
"time"
@ -18,8 +17,6 @@ import (
var client = http.Client{
Timeout: 10 * time.Second,
}
var username = os.Getenv("E621_USERNAME")
var password = os.Getenv("E621_PASSWORD")
type post struct {
Id int `json:"id"`
@ -57,13 +54,18 @@ type post struct {
}
func RegisterPorbCommands(a *app.App) {
if username != "" && password != "" {
a.RegisterCommand("e621", registerE621(a))
username, _ := a.Config.CommandExtras["e621_username"]
password, _ := a.Config.CommandExtras["e621_password"]
a.RegisterCommandAlias("porb", "e621")
} else {
if username == "" || password == "" {
log.Println("Not registering e621 command...")
return
}
a.RegisterCommand("e621", registerE621(a))
a.RegisterCommandAlias("porb", "e621")
}
func registerE621(a *app.App) app.Callback {
@ -99,6 +101,9 @@ func registerE621(a *app.App) app.Callback {
}
}
username, _ := a.Config.CommandExtras["e621_username"]
password, _ := a.Config.CommandExtras["e621_password"]
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("User-Agent", fmt.Sprintf("Lynxie/2.0 (by %s on e621)", username))