Skip to content

Commit

Permalink
refactor: degeneralize discord alert function
Browse files Browse the repository at this point in the history
  • Loading branch information
steveiliop56 committed Dec 4, 2024
1 parent 3ea6e68 commit 16ae149
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
10 changes: 1 addition & 9 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,7 @@ var serverCmd = &cobra.Command{
log.Logger.Info().Str("appId", appWithUpdate.Id).Str("tipiVersion", strconv.Itoa(appWithUpdate.Version)).Str("dockerVersion", appWithUpdate.DockerVersion).Msg("App has an update")

// Send alert
alertErr := alerts.SendAppUpdateAlert(&types.AppUpdateAlert{
Id: appWithUpdate.Id,
Name: appWithUpdate.Name,
Version: appWithUpdate.Version,
DockerVersion: appWithUpdate.DockerVersion,
ServerUrl: config.RuntipiUrl,
DiscordUrl: config.DiscordUrl,
AppStore: config.Appstore,
})
alertErr := alerts.SendDiscord(&appWithUpdate, config.DiscordUrl, config.RuntipiUrl, config.Appstore)

// Handle error
utils.HandleErrorLoggerNoExit(alertErr, "Failed to send app update alert")
Expand Down
12 changes: 6 additions & 6 deletions internal/alerts/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import (
"github.com/google/go-querystring/query"
)

func SendAppUpdateAlert(info *types.AppUpdateAlert) (error) {
func SendDiscord(app *types.SimpleApp, discordUrl string, runtipiUrl string, appstore string) (error) {
// Vars
appUrl := fmt.Sprintf("%s/apps/%s", info.ServerUrl, info.Id)
description := fmt.Sprintf("Your app %s has an available update!\nUpdate to version `%s` (%d)", info.Name, info.DockerVersion, info.Version)
appUrl := fmt.Sprintf("%s/apps/%s", runtipiUrl, app.Id)
description := fmt.Sprintf("Your app %s has an available update!\nUpdate to version `%s` (%d)", app.Name, app.DockerVersion, app.Version)
currentTime := time.Now().Format(time.RFC3339)

// Message
var message types.Message
message.Embeds = []types.Embed{
{
Title: info.Name,
Title: app.Name,
Description: description,
Url: appUrl,
Color: "3126084",
Expand All @@ -31,7 +31,7 @@ func SendAppUpdateAlert(info *types.AppUpdateAlert) (error) {
},
TimeStamp: currentTime,
Thumbnail: types.EmbedThumbnail{
Url: utils.GetAppImageUrl(info.Id, info.AppStore),
Url: utils.GetAppImageUrl(app.Name, appstore),
},
},
}
Expand All @@ -48,7 +48,7 @@ func SendAppUpdateAlert(info *types.AppUpdateAlert) (error) {
}

// Final url
url := fmt.Sprintf("%s?%s", info.DiscordUrl, queries.Encode())
url := fmt.Sprintf("%s?%s", discordUrl, queries.Encode())

// Marshal message
messageJson, marshalErr := json.Marshal(message)
Expand Down

0 comments on commit 16ae149

Please sign in to comment.