Top users
This commit is contained in:
parent
45049a0c84
commit
95e0b1952f
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -87,3 +88,24 @@ func handleKarma(u *nechotron.Update) error {
|
||||||
fmt.Sprintf("*%s \\(%d\\)* только что %s карму *%s \\(%d\\)*", mentionFrom, totalFromKarma, changeText, mentionTo, totalToKarma))
|
fmt.Sprintf("*%s \\(%d\\)* только что %s карму *%s \\(%d\\)*", mentionFrom, totalFromKarma, changeText, mentionTo, totalToKarma))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var topText = `
|
||||||
|
*Наш ТОП\-10 пользователей:*
|
||||||
|
|
||||||
|
%s
|
||||||
|
`
|
||||||
|
|
||||||
|
func handleTop(u *nechotron.Update, _ string) error {
|
||||||
|
store := tongo.NewStore[RatedUser](db)
|
||||||
|
users, err := store.GetMany(u.Ctx)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Join(errors.New("can't get top10 users"), err)
|
||||||
|
}
|
||||||
|
text := ""
|
||||||
|
for n, u := range users {
|
||||||
|
text += fmt.Sprintf("%d \\- %s \\(%d\\)\n", n, nechotron.EscapeMd2(u.Name), u.TotalKarma)
|
||||||
|
}
|
||||||
|
text = fmt.Sprintf(topText, text)
|
||||||
|
u.AnswerMarkdown(text)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -17,7 +17,8 @@ var MainState = neco.State{
|
||||||
|
|
||||||
mainCommands := neco.NewDispatcher().
|
mainCommands := neco.NewDispatcher().
|
||||||
HandleCommand(commandMe, handleMe).
|
HandleCommand(commandMe, handleMe).
|
||||||
HandleCommand(commandHelp, handleHelp)
|
HandleCommand(commandHelp, handleHelp).
|
||||||
|
HandleCommand(commandTop, handleTop)
|
||||||
|
|
||||||
replyDispatcher := neco.NewDispatcher().
|
replyDispatcher := neco.NewDispatcher().
|
||||||
HandleFilter(karmaTriggers, handleKarma)
|
HandleFilter(karmaTriggers, handleKarma)
|
||||||
|
|
9
types.go
9
types.go
|
@ -52,6 +52,15 @@ var userIndex = mongo.IndexModel{
|
||||||
|
|
||||||
func (User) Coll() string { return "users" }
|
func (User) Coll() string { return "users" }
|
||||||
|
|
||||||
|
type RatedUser struct {
|
||||||
|
tongo.Item `bson:",inline"`
|
||||||
|
Name string
|
||||||
|
ID int64
|
||||||
|
TotalKarma int64 `bson:"totalKarma"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (RatedUser) Coll() string { return "top10" }
|
||||||
|
|
||||||
type Chat struct {
|
type Chat struct {
|
||||||
tongo.Item `bson:",inline"`
|
tongo.Item `bson:",inline"`
|
||||||
ID int64
|
ID int64
|
||||||
|
|
Loading…
Reference in New Issue