@@ -10,6 +10,7 @@ import (
1010 "slices"
1111 "strconv"
1212 "strings"
13+ "time"
1314
1415 "github.com/moolite/bot/internal/db"
1516 "github.com/moolite/bot/internal/dicer"
@@ -35,7 +36,9 @@ func registerCommands(ctx context.Context, b *tg.Bot) error {
3536 // Search
3637 {Command : "search" , Description : "Search media files" },
3738 // Top
38- {Command : "top" , Description : "Top 10 media files" },
39+ {Command : "top10" , Description : "Top 10 media files" },
40+ // Top20
41+ {Command : "top20" , Description : "Top 20 media files" },
3942 // grumpyness
4043 {Command : "grumpyness" , Description : "Grumpyness measuring instrument" },
4144 },
@@ -59,9 +62,15 @@ func registerBotHandlers(_ context.Context, b *tg.Bot) {
5962 & tg.UpdateHandler {
6063 Type : tg .UPD_STARTSWITH ,
6164 Param : "/top" ,
62- Aliases : []string {"/t" },
65+ Aliases : []string {"/t" , "/top10" },
6366 Fn : MediaToptenCommand ,
6467 },
68+ & tg.UpdateHandler {
69+ Type : tg .UPD_STARTSWITH ,
70+ Param : "/tte" ,
71+ Aliases : []string {"/t2" , "/top20" },
72+ Fn : MediaToptwentyCommand ,
73+ },
6574 & tg.UpdateHandler {
6675 Type : tg .UPD_STARTSWITH ,
6776 Param : "/pot" ,
@@ -560,6 +569,25 @@ func MediaBottomtenCommand(ctx context.Context, b *tg.Bot, update *tg.Update) (*
560569 return snd , nil
561570}
562571
572+ func MediaToptwentyCommand (ctx context.Context , b * tg.Bot , update * tg.Update ) (* tg.Sendable , error ) {
573+ media , err := db .SelectMediaTop (ctx , update .Message .Chat .ID , 20 )
574+ if err != nil {
575+ return nil , err
576+ }
577+
578+ go func () {
579+ time .Sleep (time .Millisecond * 200 ) // wait a reasonable 1/5 of a second
580+ snd := mediaCollection (update .Message .Chat .ID , media [10 ].Description , media [10 :])
581+
582+ if _ , err := b .Send (context .Background (), snd ); err != nil {
583+ slog .Error ("error in bot.Send" , "err" , err )
584+ }
585+ }()
586+
587+ snd := mediaCollection (update .Message .Chat .ID , media [0 ].Description , media [:10 ])
588+ return snd , nil
589+ }
590+
563591func MediaRememberCommand (ctx context.Context , b * tg.Bot , update * tg.Update ) (* tg.Sendable , error ) {
564592 kind := ""
565593 data := ""
0 commit comments