From dc70752cfe39095327540aa1c4b7ea0b7ef17db4 Mon Sep 17 00:00:00 2001 From: Kichiyaki Date: Sat, 6 Feb 2021 10:36:13 +0100 Subject: [PATCH] make score in Session.handleTribeCommand more readable (add commas) --- discord/helpers.go | 2 +- discord/observations.go | 5 ++--- discord/public_commands.go | 5 +++-- go.mod | 1 + go.sum | 2 ++ message/translations/active.en.json | 2 +- message/translations/active.nl.json | 2 +- message/translations/active.pl.json | 2 +- 8 files changed, 12 insertions(+), 9 deletions(-) diff --git a/discord/helpers.go b/discord/helpers.go index 00a9644..e040a40 100644 --- a/discord/helpers.go +++ b/discord/helpers.go @@ -37,5 +37,5 @@ func BuildLink(text string, url string) string { if url == "" { return text } - return fmt.Sprintf("[``%s``](%s)", text, url) + return fmt.Sprintf("[`%s`](%s)", text, url) } diff --git a/discord/observations.go b/discord/observations.go index ad46c80..42a383f 100644 --- a/discord/observations.go +++ b/discord/observations.go @@ -745,10 +745,9 @@ func (s *Session) handleObservationsCommand(ctx *commandCtx, m *discordgo.Messag if version != nil { tribeURL = tw.BuildTribeURL(observation.Server, version.Host, observation.TribeID) } - msg.Append(fmt.Sprintf("**%d** | %d - %s - [``%s``](%s)\n", i+1, observation.ID, + msg.Append(fmt.Sprintf("**%d** | %d - %s - %s\n", i+1, observation.ID, observation.Server, - tag, - tribeURL)) + BuildLink(tag, tribeURL))) } } s.SendEmbed(m.ChannelID, NewEmbed(). diff --git a/discord/public_commands.go b/discord/public_commands.go index 7a98226..822cd05 100644 --- a/discord/public_commands.go +++ b/discord/public_commands.go @@ -13,6 +13,7 @@ import ( "github.com/tribalwarshelp/shared/tw" "github.com/bwmarrin/discordgo" + "github.com/dustin/go-humanize" "github.com/tribalwarshelp/golang-sdk/sdk" ) @@ -463,7 +464,7 @@ func (s *Session) handleTribeCommand(ctx *commandCtx, m *discordgo.MessageCreate msg.Append(ctx.localizer.MustLocalize(&i18n.LocalizeConfig{ MessageID: message.TribeMessageLine, DefaultMessage: message.FallbackMsg(message.TribeMessageLine, - "**{{.Index}}**. [``{{.PlayerName}}``]({{.PlayerURL}}) (Tribe: [``{{.TribeTag}}``]({{.TribeURL}}) | Rank: **{{.Rank}}** | Score: **{{.Score}}**)\n"), + "**{{.Index}}**. [`{{.PlayerName}}`]({{.PlayerURL}}) (Tribe: [`{{.TribeTag}}`]({{.TribeURL}}) | Rank: **{{.Rank}}** | Score: **{{.Score}}**)\n"), TemplateData: map[string]interface{}{ "Index": offset + i + 1, "PlayerName": player.Name, @@ -471,7 +472,7 @@ func (s *Session) handleTribeCommand(ctx *commandCtx, m *discordgo.MessageCreate "TribeTag": tribeTag, "TribeURL": tribeURL, "Rank": rank, - "Score": score, + "Score": humanize.Comma(int64(score)), }, })) } diff --git a/go.mod b/go.mod index 6494242..1a23e64 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.15 require ( github.com/bwmarrin/discordgo v0.22.0 + github.com/dustin/go-humanize v1.0.0 github.com/go-pg/pg/extra/pgdebug v0.2.0 github.com/go-pg/pg/v10 v10.7.3 github.com/joho/godotenv v1.3.0 diff --git a/go.sum b/go.sum index b731276..b1a2d2a 100644 --- a/go.sum +++ b/go.sum @@ -12,6 +12,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= diff --git a/message/translations/active.en.json b/message/translations/active.en.json index 3fb9ea2..1700518 100644 --- a/message/translations/active.en.json +++ b/message/translations/active.en.json @@ -35,7 +35,7 @@ "tribe.title.orderedByPoints": "Ordered by points", "tribe.tribesNotFound": "{{.Mention}} Tribes not found.", "tribe.exceededMaximumNumberOfPages": "{{.Mention}} You have exceeded the maximum number of pages ({{.Page}}/{{.MaxPage}}).", - "tribe.messageLine": "**{{.Index}}**. [``{{.PlayerName}}``]({{.PlayerURL}}) (Tribe: [``{{.TribeTag}}``]({{.TribeURL}}) | Rank: **{{.Rank}}** | Score: **{{.Score}}**)\n", + "tribe.messageLine": "**{{.Index}}**. [`{{.PlayerName}}`]({{.PlayerURL}}) (Tribe: [`{{.TribeTag}}`]({{.TribeURL}}) | Rank: **{{.Rank}}** | Score: **{{.Score}}**)\n", "addGroup.groupLimitHasBeenReached": "{{.Mention}} The group limit has been reached ({{.Total}}/{{.Limit}}).", "addGroup.success": "{{.Mention}} A new group has been created (ID: {{.ID}}).", diff --git a/message/translations/active.nl.json b/message/translations/active.nl.json index ca33e9e..ba1dc29 100644 --- a/message/translations/active.nl.json +++ b/message/translations/active.nl.json @@ -35,7 +35,7 @@ "tribe.title.orderedByPoints": "geranschikt op points", "tribe.tribesNotFound": "{{.Mention}} Stammen niet gevonden.", "tribe.exceededMaximumNumberOfPages": "{{.Mention}} Je hebt de maximale aantal pagina's overschreden ({{.Page}}/{{.MaxPage}}).", - "tribe.messageLine": "**{{.Index}}**. [``{{.PlayerName}}``]({{.PlayerURL}}) (Stam: [``{{.TribeTag}}``]({{.TribeURL}}) | Rang: **{{.Rank}}** | Score: **{{.Score}}**)\n", + "tribe.messageLine": "**{{.Index}}**. [`{{.PlayerName}}`]({{.PlayerURL}}) (Stam: [`{{.TribeTag}}`]({{.TribeURL}}) | Rang: **{{.Rank}}** | Score: **{{.Score}}**)\n", "addGroup.groupLimitHasBeenReached": "{{.Mention}} De groeplimiet is bereikt ({{.Total}}/{{.Limit}}).", "addGroup.success": "{{.Mention}} Een nieuwe groep is gemaakt (ID: {{.ID}}).", diff --git a/message/translations/active.pl.json b/message/translations/active.pl.json index c51ee29..6619829 100644 --- a/message/translations/active.pl.json +++ b/message/translations/active.pl.json @@ -35,7 +35,7 @@ "tribe.title.orderedByPoints": "Gracze posortowani według punktów", "tribe.tribesNotFound": "{{.Mention}} Plemię nie zostało znalezione.", "tribe.exceededMaximumNumberOfPages": "{{.Mention}} Przekroczyłeś limit stron ({{.Page}}/{{.MaxPage}}).", - "tribe.messageLine": "**{{.Index}}**. [``{{.PlayerName}}``]({{.PlayerURL}}) (Plemię: [``{{.TribeTag}}``]({{.TribeURL}}) | Ranking: **{{.Rank}}** | Wynik: **{{.Score}}**)\n", + "tribe.messageLine": "**{{.Index}}**. [`{{.PlayerName}}`]({{.PlayerURL}}) (Plemię: [`{{.TribeTag}}`]({{.TribeURL}}) | Ranking: **{{.Rank}}** | Wynik: **{{.Score}}**)\n", "addGroup.groupLimitHasBeenReached": "{{.Mention}} Osiągnięto limit grup ({{.Total}}/{{.Limit}}).", "addGroup.success": "{{.Mention}} Nowa grupa została utworzona (ID: {{.ID}}).",