include more bot data

This commit is contained in:
2022-12-31 18:27:04 -06:00
parent 71fd5f0d32
commit 8fe3de08e5
2 changed files with 43 additions and 6 deletions

View File

@@ -23,26 +23,42 @@ func BotExists(id string) bool {
return true
}
func GetBots() []discord.SimpleUser {
type BotData struct {
User discord.User `json:"user"`
TokenCount int `json:"token_count"`
}
type BotDataSimple struct {
User discord.SimpleUser `json:"user"`
TokenCount int `json:"token_count"`
}
func GetBots() []BotDataSimple {
botIDs, err := client.SMembers(ctx, "bots").Result()
if err != nil && err != redis.Nil {
panic(err)
}
bots := make([]discord.SimpleUser, 0)
bots := make([]BotDataSimple, 0)
for _, id := range botIDs {
bots = append(bots, GetBot(id).Simplify())
bots = append(bots, BotDataSimple{
User: GetBot(id).User.Simplify(),
TokenCount: len(TokensUnderBot(id)),
})
}
return bots
}
func GetBot(id string) discord.User {
func GetBot(id string) BotData {
var bot discord.User
key := fmt.Sprintf("bot:%s:data", id)
err := client.Get(ctx, key).Scan(&bot)
if err != nil && err != redis.Nil {
panic(err)
}
return bot
return BotData{
User: bot,
TokenCount: len(TokensUnderBot(id)),
}
}
func ExistsBot(id string) bool {