vyvanse: fix top10 command, known unicode issue
This commit is contained in:
parent
b98574f0be
commit
adcc28d417
|
@ -132,8 +132,13 @@ func main() {
|
||||||
cs.AddCmd("printerfact", "facts about printers", bot.NoPermissions, printerFact)
|
cs.AddCmd("printerfact", "facts about printers", bot.NoPermissions, printerFact)
|
||||||
cs.AddCmd("dice", "roll the dice", bot.NoPermissions, roll)
|
cs.AddCmd("dice", "roll the dice", bot.NoPermissions, roll)
|
||||||
cs.AddCmd("splattus", "splatoon 2 map rotation status", bot.NoPermissions, spla2nMaps)
|
cs.AddCmd("splattus", "splatoon 2 map rotation status", bot.NoPermissions, spla2nMaps)
|
||||||
|
cs.AddCmd("top10", "shows the top 10 chatters on this server", bot.NoPermissions, top10(us))
|
||||||
|
|
||||||
dg.AddHandler(func(s *discordgo.Session, m *discordgo.MessageCreate) {
|
dg.AddHandler(func(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
|
if m.Author.ID == s.State.User.ID {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
sp, ctx := opentracing.StartSpanFromContext(context.Background(), "discordgo.message.create")
|
sp, ctx := opentracing.StartSpanFromContext(context.Background(), "discordgo.message.create")
|
||||||
defer sp.Finish()
|
defer sp.Finish()
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,12 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"git.xeserv.us/xena/vyvanse/internal/dao"
|
"git.xeserv.us/xena/vyvanse/internal/dao"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/olekukonko/tablewriter"
|
"github.com/olekukonko/tablewriter"
|
||||||
opentracing "github.com/opentracing/opentracing-go"
|
opentracing "github.com/opentracing/opentracing-go"
|
||||||
|
splog "github.com/opentracing/opentracing-go/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func top10(us *dao.Users) func(context.Context, *discordgo.Session, *discordgo.Message, []string) error {
|
func top10(us *dao.Users) func(context.Context, *discordgo.Session, *discordgo.Message, []string) error {
|
||||||
|
@ -25,23 +25,28 @@ func top10(us *dao.Users) func(context.Context, *discordgo.Session, *discordgo.M
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
|
|
||||||
table := tablewriter.NewWriter(buf)
|
table := tablewriter.NewWriter(buf)
|
||||||
table.SetHeader([]string{"Rank", "Nick", "Score"})
|
table.SetHeader([]string{"Nick", "Score"})
|
||||||
|
|
||||||
for i, u := range users {
|
for _, u := range users {
|
||||||
apd := []string{}
|
apd := []string{}
|
||||||
apd = append(apd, strconv.Itoa(i+1))
|
|
||||||
|
|
||||||
ch, err := s.Channel(m.ChannelID)
|
ch, err := s.Channel(m.ChannelID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
sp.LogFields(splog.Error(err))
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
mem, err := s.GuildMember(ch.GuildID, u.DiscordID)
|
mem, err := s.GuildMember(ch.GuildID, u.DiscordID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
sp.LogFields(splog.Error(err))
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
apd = append(apd, mem.Nick, strconv.Itoa(u.Score))
|
if mem.Nick == "" {
|
||||||
|
mem.Nick = mem.User.Username
|
||||||
|
}
|
||||||
|
|
||||||
|
apd = append(apd, mem.Nick, fmt.Sprint(u.Score))
|
||||||
|
|
||||||
table.Append(apd)
|
table.Append(apd)
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,16 +82,16 @@ func (u *Users) IncScore(ctx context.Context, discordID string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ID int `json:"id"`
|
ID int64 `json:"id"`
|
||||||
DiscordID string `json:"discord_id"`
|
DiscordID string `json:"discord_id"`
|
||||||
Score int `json:"score"`
|
Score int64 `json:"score"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *Users) Top10(ctx context.Context) ([]User, error) {
|
func (u *Users) Top10(ctx context.Context) ([]User, error) {
|
||||||
sp, ctx := opentracing.StartSpanFromContext(ctx, "users.top10")
|
sp, ctx := opentracing.StartSpanFromContext(ctx, "users.top10")
|
||||||
defer sp.Finish()
|
defer sp.Finish()
|
||||||
|
|
||||||
qr, err := u.conn.QueryOne("SELECT (id, discord_id, score) FROM users WHERE score > 0 ORDER BY score LIMIT 10")
|
qr, err := u.conn.QueryOne("SELECT id, discord_id, score FROM users WHERE score > 0 ORDER BY score DESC LIMIT 10")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sp.LogFields(splog.Error(err))
|
sp.LogFields(splog.Error(err))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue