feat(controller): add init message for bot pipes
chore: move softwareInfo from main package to a individual global package
This commit is contained in:
@@ -5,21 +5,43 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"nukumizu-backend/global"
|
||||
"nukumizu-backend/internal/node"
|
||||
)
|
||||
|
||||
// Params holds all possible template parameters.
|
||||
type Params struct {
|
||||
Time string
|
||||
ServerName string
|
||||
ServerUUID string
|
||||
UpStatus string
|
||||
Event string
|
||||
Message string
|
||||
Command string
|
||||
Result string
|
||||
OnlineServers string // Pre-formatted multi-line list
|
||||
OfflineServers string // Pre-formatted multi-line list
|
||||
Time string
|
||||
ServerName string
|
||||
ServerUUID string
|
||||
UpStatus string
|
||||
Event string
|
||||
Message string
|
||||
Command string
|
||||
Result string
|
||||
OnlineServers string // Pre-formatted multi-line list
|
||||
OfflineServers string // Pre-formatted multi-line list
|
||||
SoftwareVersion string
|
||||
SoftwareBuildVer int16
|
||||
SoftwareCommitHash string
|
||||
SoftwareBuildType string
|
||||
SoftwareBuildTime string
|
||||
SoftwareDeveloper string
|
||||
SoftwareDescription string
|
||||
}
|
||||
|
||||
// BuildBotInitializationMsgParams creates template parameters for the bot initialization message.
|
||||
func BuildBotInitializationMsgParams() Params {
|
||||
return Params{
|
||||
Time: time.Now().Format("2006-01-02T15:04:05.000000000-07:00"),
|
||||
SoftwareVersion: global.SoftwareInfo.Version,
|
||||
SoftwareBuildVer: global.SoftwareInfo.BuildVer,
|
||||
SoftwareCommitHash: global.SoftwareInfo.CommitHash,
|
||||
SoftwareBuildType: global.SoftwareInfo.BuildType,
|
||||
SoftwareBuildTime: global.SoftwareInfo.BuildTime,
|
||||
SoftwareDeveloper: global.SoftwareInfo.Developer,
|
||||
SoftwareDescription: global.SoftwareInfo.Description,
|
||||
}
|
||||
}
|
||||
|
||||
// BuildParamsFromStatusChange creates template parameters from a status change event.
|
||||
@@ -70,6 +92,13 @@ func BuildParamsFromExecResult(serverName, serverUUID, command, result string) P
|
||||
// - {{ result }} — command execution result
|
||||
// - {{ list.onlineServers }} — multi-line online server list
|
||||
// - {{ list.offlineServers }} — multi-line offline server list
|
||||
// - {{ softwareVersion }} — software version
|
||||
// - {{ softwareBuildVer }} — software build version
|
||||
// - {{ softwareCommitHash }} — software commit hash
|
||||
// - {{ softwareBuildType }} — software build type (Debug/Release)
|
||||
// - {{ softwareBuildTime }} — software build time
|
||||
// - {{ softwareDeveloper }} — software developer
|
||||
// - {{ softwareDescription }} — software description
|
||||
func Render(tmpl string, params Params) string {
|
||||
result := tmpl
|
||||
|
||||
@@ -83,6 +112,13 @@ func Render(tmpl string, params Params) string {
|
||||
result = strings.ReplaceAll(result, "{{ result }}", params.Result)
|
||||
result = strings.ReplaceAll(result, "{{ list.onlineServers }}", params.OnlineServers)
|
||||
result = strings.ReplaceAll(result, "{{ list.offlineServers }}", params.OfflineServers)
|
||||
result = strings.ReplaceAll(result, "{{ softwareVersion }}", params.SoftwareVersion)
|
||||
result = strings.ReplaceAll(result, "{{ softwareBuildVer }}", fmt.Sprintf("%d", params.SoftwareBuildVer))
|
||||
result = strings.ReplaceAll(result, "{{ softwareCommitHash }}", params.SoftwareCommitHash)
|
||||
result = strings.ReplaceAll(result, "{{ softwareBuildType }}", params.SoftwareBuildType)
|
||||
result = strings.ReplaceAll(result, "{{ softwareBuildTime }}", params.SoftwareBuildTime)
|
||||
result = strings.ReplaceAll(result, "{{ softwareDeveloper }}", params.SoftwareDeveloper)
|
||||
result = strings.ReplaceAll(result, "{{ softwareDescription }}", params.SoftwareDescription)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user