feat(stats): push guild count to bot status

This commit is contained in:
spiral 2022-12-06 10:45:38 +00:00
parent d1d0faaa7e
commit c547901e00
No known key found for this signature in database
GPG Key ID: 244A11E4B0BCF40E
4 changed files with 35 additions and 2 deletions

View File

@ -20,5 +20,5 @@ require (
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be // indirect
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/text v0.5.0 // indirect
)

View File

@ -164,6 +164,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=

View File

@ -11,7 +11,13 @@ import (
"github.com/getsentry/sentry-go"
)
var set_guild_count = false
func main() {
if _, ok := os.LookupEnv("SET_GUILD_COUNT"); ok {
set_guild_count = true
}
err := sentry.Init(sentry.ClientOptions{
Dsn: os.Getenv("SENTRY_DSN"),
})

View File

@ -4,6 +4,9 @@ import (
"context"
"fmt"
"log"
"golang.org/x/text/language"
"golang.org/x/text/message"
)
func task_main() {
@ -11,6 +14,7 @@ func task_main() {
update_db_meta()
update_stats()
update_bot_status()
}
var table_stat_keys = []string{"system", "member", "group", "switch", "message"}
@ -44,7 +48,7 @@ func update_db_message_meta() {
}
}
func update_stats() {
func get_discord_counts() (int, int) {
redisStats := run_redis_query()
guild_count := 0
@ -56,6 +60,12 @@ func update_stats() {
channel_count += v.ChannelCount
}
return guild_count, channel_count
}
func update_stats() {
guild_count, channel_count := get_discord_counts()
do_stats_insert("guilds", guild_count)
do_stats_insert("channels", channel_count)
@ -65,3 +75,18 @@ func update_stats() {
do_stats_insert(plural(key), int(val))
}
}
func update_bot_status() {
if !set_guild_count {
return
}
guild_count, _ := get_discord_counts()
p := message.NewPrinter(language.English)
s := p.Sprintf("%d\n", guild_count)
cmd := rdb.Set(context.Background(), "discord_botstatus", "in "+s+" servers", 0)
if err := cmd.Err(); err != nil {
panic(err)
}
}