Skip to content

Commit

Permalink
it works now 🙂
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaprit committed Apr 23, 2022
1 parent 4cf23f1 commit 8795d3a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
.idea/
build/
12 changes: 7 additions & 5 deletions config/Config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import (
"fmt"
"github.com/BurntSushi/toml"
"github.com/patrickmn/go-cache"
"log"
"os"

_ "embed"
)

// go:embed default.toml
var defaultConfig string
var DefaultConfig string

var GlobalCache *cache.Cache

Expand Down Expand Up @@ -54,14 +52,18 @@ func ReadConfig() Config {
fmt.Println("Error creating config file: config.toml")
panic(er2)
}
_, er3 := file.WriteString(defaultConfig)
_, er3 := file.WriteString(DefaultConfig)
if er3 != nil {
panic(er3.Error())
}
file.Sync()
er4 := file.Close()
if er4 != nil {
panic(er4.Error())
}
log.Println("Created config file: config.toml, please fill in your token and other values")
log.Println(DefaultConfig)
os.Exit(0)
}
_, er2 := toml.DecodeFile("config.toml", &conf)
if er2 != nil {
Expand Down
2 changes: 1 addition & 1 deletion config/PrettyGameNames.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var PrettyGameNames = make(map[string]string)
// GetGameNames fetches the game display names from the gamedig GitHub repo
func GetGameNames() {
cacheItem, exists := GlobalCache.Get("PrettyGameNames")
if !exists {
if exists {
PrettyGameNames = cacheItem.(map[string]string)
return
}
Expand Down
2 changes: 1 addition & 1 deletion config/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
hostname = "127.0.0.1"
game = "tf2"
port = 27015
colour = "#CF7336"
colour = 0xCF7336
country = "???"
public_hostname = "tf2.example.com"
public_port = 27015
Expand Down
2 changes: 1 addition & 1 deletion discord/ServerStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func RefreshServerStatus(s *discordgo.Session) {
isOnline = true
}
c, er2 := s.ChannelMessages(server.ChannelID, 20, "", "", "")
if er2 == nil {
if er2 != nil {
log.Println("Failed to get messages: ", er2)
}
for _, i2 := range c {
Expand Down
9 changes: 9 additions & 0 deletions gogsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ import (
"os/signal"
"syscall"
"time"

_ "embed"
)

//go:embed config/default.toml
var defaultConfig string

func main() {

config.DefaultConfig = defaultConfig

config.GlobalCache = cache.New(5*time.Minute, 10*time.Minute)

conf := config.ReadConfig()
Expand All @@ -38,6 +45,8 @@ func main() {
}
}()

discord.RefreshServerStatus(s)

// Clean exit on ctrl+c
fmt.Println("Bot is now running. Press CTRL-C to exit.")
sc := make(chan os.Signal, 1)
Expand Down

0 comments on commit 8795d3a

Please sign in to comment.