Skip to content

Commit fef5ff8

Browse files
committed
Better update messages
1 parent 3fa6192 commit fef5ff8

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

factUpdater/fullPackage.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"ChatWire/cwlog"
66
"ChatWire/disc"
77
"ChatWire/fact"
8+
"ChatWire/glob"
89
"fmt"
910
"os"
1011
"strings"
@@ -29,6 +30,7 @@ func fullPackage(info *InfoData) error {
2930
url := fmt.Sprintf("%v%v/%v/%v", baseDownloadURL, branch, info.Build, info.Distro)
3031
var data []byte
3132

33+
glob.UpdateMessage = disc.SmartEditDiscordEmbed(cfg.Local.Channel.ChatChannel, glob.UpdateMessage, "Updating Factorio", "Downloading...", 0x0099ff)
3234
cwlog.DoLogCW("Downloading: %v", url)
3335

3436
data, filename, err = httpGet(url)
@@ -39,6 +41,7 @@ func fullPackage(info *InfoData) error {
3941
}
4042

4143
cwlog.DoLogCW("Download of %v complete, verifying...", filename)
44+
glob.UpdateMessage = disc.SmartEditDiscordEmbed(cfg.Local.Channel.ChatChannel, glob.UpdateMessage, "Updating Factorio", "Verifying update.", 0x0099ff)
4245

4346
archive, err := checkFullPackage(data)
4447
if err != nil {

factUpdater/latest.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ package factUpdater
22

33
import (
44
"ChatWire/cfg"
5+
"ChatWire/disc"
56
"ChatWire/fact"
7+
"ChatWire/glob"
68
"encoding/json"
79
"fmt"
10+
11+
"github.com/bwmarrin/discordgo"
812
)
913

1014
func DoQuickLatest(force bool) (*InfoData, string, bool, bool) {
15+
glob.UpdateMessage = nil
16+
1117
info := &InfoData{Xreleases: cfg.Local.Options.ExpUpdates, Build: "headless", Distro: "linux64"}
1218

1319
if force {
@@ -36,11 +42,14 @@ func DoQuickLatest(force bool) (*InfoData, string, bool, bool) {
3642
fact.NewVersion = newVersion.IntToString()
3743

3844
if isVersionNewerThan(*newVersion, oldVersion) || force {
45+
glob.UpdateMessage = disc.SmartWriteDiscordEmbed(cfg.Local.Channel.ChatChannel, &discordgo.MessageEmbed{Title: "Updating Factorio", Description: "Found Factorio update: " + newVersion.IntToString(), Color: 0x0099ff})
46+
3947
info.VersInt = *newVersion
4048
err := fullPackage(info)
4149
if err != nil {
4250
return info, fmt.Sprintf("DoQuickLatest: fullPackage: %v", err.Error()), true, false
4351
}
52+
4453
return info, fmt.Sprintf("Factorio upgraded from %v to %v.", oldVersion.IntToString(), newVersion.IntToString()), false, false
4554
} else if isVersionEqual(*newVersion, info.VersInt) {
4655
return info, "Factorio is up-to-date.", false, true

glob/glob.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ type ChoiceData struct {
127127
}
128128

129129
var (
130-
BootMessage *discordgo.Message
131-
QuitMessage *discordgo.Message
130+
BootMessage *discordgo.Message
131+
QuitMessage *discordgo.Message
132+
UpdateMessage *discordgo.Message
132133

133134
FactorioContext context.Context
134135
FactorioCancel context.CancelFunc

support/factLauncher.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func GetSaveGame(doInject bool) (foundGood bool, fileName string, fileDir string
115115

116116
/* We can't read saves dir */
117117
if err != nil {
118-
fact.LogCMS(cfg.Local.Channel.ChatChannel, "Unable to read saves folder, stopping.")
118+
cwlog.DoLogCW("Unable to read saves folder, stopping.")
119119
return false, "", ""
120120
}
121121

@@ -369,7 +369,6 @@ func launchFactorio() {
369369
found, fileName, folderName := GetSaveGame(true)
370370
if !found {
371371
disc.SmartEditDiscordEmbed(cfg.Local.Channel.ChatChannel, msg, "ERROR", "Unable to access save-games.", 0xff0000)
372-
373372
fact.FactAutoStart = false
374373
return
375374
}

support/mainLoops.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"syscall"
1010
"time"
1111

12-
embed "github.com/Clinet/discordgo-embed"
1312
"github.com/bwmarrin/discordgo"
1413

1514
"ChatWire/banlist"
@@ -478,10 +477,10 @@ func MainLoops() {
478477
/* Reboot anyway */
479478
if glob.UpdateWarnCounter > glob.UpdateGraceMinutes {
480479
msg := "(SYSTEM) Rebooting for Factorio update!"
481-
fact.LogGameCMS(true, cfg.Local.Channel.ChatChannel, msg)
480+
fact.FactChat(msg)
482481
glob.UpdateWarnCounter = 0
483482
fact.QuitFactorio("Rebooting for Factorio update: " + fact.NewVersion)
484-
time.Sleep(time.Minute * 10)
483+
time.Sleep(time.Minute * 15)
485484
}
486485
glob.UpdateWarnCounter = (glob.UpdateWarnCounter + 1)
487486

@@ -593,20 +592,18 @@ func MainLoops() {
593592
time.Sleep(time.Second * 15)
594593
for glob.ServerRunning {
595594
if cfg.Local.Options.AutoUpdate {
595+
glob.UpdateMessage = nil
596596
_, msg, err, upToDate := factUpdater.DoQuickLatest(false)
597597
if msg != "" {
598598
if !err && !upToDate {
599+
glob.UpdateMessage = disc.SmartEditDiscordEmbed(cfg.Local.Channel.ChatChannel, glob.UpdateMessage, "Updated", msg, 0x0099ff)
599600
cwlog.DoLogCW(msg)
600-
601-
myembed := embed.NewEmbed().
602-
SetTitle("Factorio Updated").
603-
SetDescription(msg).
604-
SetColor(0x00ffff).MessageEmbed
605-
disc.SmartWriteDiscordEmbed(cfg.Local.Channel.ChatChannel, myembed)
606601
} else if err && !upToDate {
602+
glob.UpdateMessage = disc.SmartEditDiscordEmbed(cfg.Local.Channel.ChatChannel, glob.UpdateMessage, "ERROR", msg, 0xFF0000)
607603
cwlog.DoLogCW(msg)
608604
}
609605
}
606+
glob.UpdateMessage = nil
610607
time.Sleep(time.Minute * 10)
611608
time.Sleep(time.Second * time.Duration(rand.Intn(300))) //Add 5 minutes of randomness
612609
} else {

0 commit comments

Comments
 (0)