Skip to content

Commit 470164e

Browse files
committed
Adds Commit to stats
1 parent 5a0047d commit 470164e

File tree

7 files changed

+33
-8
lines changed

7 files changed

+33
-8
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ WORKDIR /app
3939
COPY --from=builder /app /app
4040
COPY ./locales/ /app/locales
4141

42-
# Port used for
42+
# Port used for health/liveliness checks
4343
EXPOSE 8080
4444
# Port used for application command and control
4545
EXPOSE 5000

discord/bot.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func MakeAndStartBot(version, commit, token, token2, url, emojiGuildID string, n
119119

120120
dg.UpdateStatusComplex(*status)
121121

122-
bot.RedisInterface.SetVersion(Version)
122+
bot.RedisInterface.SetVersionAndCommit(Version, Commit)
123123

124124
go StartHealthCheckServer("8080")
125125

discord/redis.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ func versionKey() string {
3939
return "automuteus:version"
4040
}
4141

42+
func commitKey() string {
43+
return "automuteus:commit"
44+
}
45+
4246
func totalGuildsKey(version string) string {
4347
return "automuteus:count:guilds:version-" + version
4448
}
@@ -79,19 +83,29 @@ func (redisInterface *RedisInterface) GetAndIncrementMatchID() int64 {
7983
return num
8084
}
8185

82-
func (redisInterface *RedisInterface) SetVersion(version string) {
86+
func (redisInterface *RedisInterface) SetVersionAndCommit(version, commit string) {
8387
err := redisInterface.client.Set(ctx, versionKey(), version, 0).Err()
8488
if err != nil {
8589
log.Println(err)
8690
}
91+
92+
err = redisInterface.client.Set(ctx, commitKey(), commit, 0).Err()
93+
if err != nil {
94+
log.Println(err)
95+
}
8796
}
8897

89-
func (redisInterface *RedisInterface) GetVersion() string {
98+
func (redisInterface *RedisInterface) GetVersionAndCommit() (string, string) {
9099
v, err := redisInterface.client.Get(ctx, versionKey()).Result()
91100
if err != nil {
92101
log.Println(err)
93102
}
94-
return v
103+
104+
c, err := redisInterface.client.Get(ctx, commitKey()).Result()
105+
if err != nil {
106+
log.Println(err)
107+
}
108+
return v, c
95109
}
96110

97111
func (redisInterface *RedisInterface) AddUniqueGuildCounter(guildID, version string) {

discord/responses.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ func (bot *Bot) statsResponse(sett *storage.GuildSettings) *discordgo.MessageEmb
116116
Author: nil,
117117
}
118118

119-
version := broker.GetVersion(bot.RedisInterface.client)
119+
version, commit := broker.GetVersionAndCommit(bot.RedisInterface.client)
120120
totalGuilds := broker.GetGuildCounter(bot.RedisInterface.client, version)
121121
totalGames := broker.GetActiveGames(bot.RedisInterface.client)
122122

123-
fields := make([]*discordgo.MessageEmbedField, 3)
123+
fields := make([]*discordgo.MessageEmbedField, 4)
124124
fields[0] = &discordgo.MessageEmbedField{
125125
Name: sett.LocalizeMessage(&i18n.Message{
126126
ID: "responses.statsResponse.Guilds",
@@ -145,6 +145,14 @@ func (bot *Bot) statsResponse(sett *storage.GuildSettings) *discordgo.MessageEmb
145145
Value: version,
146146
Inline: true,
147147
}
148+
fields[3] = &discordgo.MessageEmbedField{
149+
Name: sett.LocalizeMessage(&i18n.Message{
150+
ID: "responses.statsResponse.Commit",
151+
Other: "Commit",
152+
}),
153+
Value: commit,
154+
Inline: true,
155+
}
148156

149157
embed.Fields = fields
150158
return &embed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ go 1.15
66

77
require (
88
github.com/BurntSushi/toml v0.3.1
9-
github.com/automuteus/galactus v0.0.1
9+
github.com/automuteus/galactus v0.0.3
1010
github.com/bsm/redislock v0.7.0
1111
github.com/bwmarrin/discordgo v0.22.0
1212
github.com/go-redis/redis/v8 v8.3.3

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
55
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
66
github.com/automuteus/galactus v0.0.1 h1:kdMfWIYBdJMZpo7D/BQbU6TzMSPKMngaDMLIS9bJMeU=
77
github.com/automuteus/galactus v0.0.1/go.mod h1:fWFnpCRyOs9wSVHvksupPlMPiAEO6CGhbI+uPtrmJcs=
8+
github.com/automuteus/galactus v0.0.3 h1:9L8GoWhA0xwPjUI2EQh6Vk6a0BZ9XakVMpJ2i/ZbwXk=
9+
github.com/automuteus/galactus v0.0.3/go.mod h1:fWFnpCRyOs9wSVHvksupPlMPiAEO6CGhbI+uPtrmJcs=
810
github.com/bsm/redislock v0.7.0 h1:RL7aZJhCKkuBjQbnSTKCeedTRifBWxd/ffP+GZ599Mo=
911
github.com/bsm/redislock v0.7.0/go.mod h1:3Kgu+cXw0JrkZ5pmY/JbcFpixGZ5M9v9G2PGWYqku+k=
1012
github.com/bwmarrin/discordgo v0.22.0 h1:uBxY1HmlVCsW1IuaPjpCGT6A2DBwRn0nvOguQIxDdFM=

locales/active.en.toml

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
"responses.statsResponse.Guilds" = "Total Guilds"
102102
"responses.statsResponse.Games" = "Active Games"
103103
"responses.statsResponse.Version" = "Version"
104+
"responses.statsResponse.Commit" = "Commit"
104105
"settings.AllSettings.AdminUserIDs.args" = "<User @ mentions>..."
105106
"settings.AllSettings.AdminUserIDs.desc" = "Specify which individual users have admin bot permissions"
106107
"settings.AllSettings.AdminUserIDs.shortDesc" = "Bot Admins"

0 commit comments

Comments
 (0)