~williewillus/public-inbox

Fallback to update behavior if registering an extant trick v1 APPLIED

: 2
 Fallback to update behavior if registering an extant trick
 Paginate popular cmd, now we can see everything in a guild

 2 files changed, 12 insertions(+), 9 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~williewillus/public-inbox/patches/23961/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH 1/2] Fallback to update behavior if registering an extant trick Export this patch

From: Alwinfy <20421383+Alwinfy@users.noreply.github.com>

---
 main.rkt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/main.rkt b/main.rkt
index ca7aadd..5ba5db4 100755
--- a/main.rkt
+++ b/main.rkt
@@ -133,7 +133,7 @@
     [(not body) (~a "Trick " name " needs a body!")]
     [(db:add-trick! db context-id name (thunk (make-trick body message #f)))
      (~a "Successfully registered trick " name "!")]
     [else (~a "Trick " name " already exists!")])))
     [else (update-trick client db message text)])))

(define (call-trick client db message text)
  (check-trick-prereqs
-- 
2.25.1

[PATCH 2/2] Paginate popular cmd, now we can see everything in a guild Export this patch

From: Alwinfy <20421383+Alwinfy@users.noreply.github.com>

---
 main.rkt | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/main.rkt b/main.rkt
index 5ba5db4..cec8a66 100755
--- a/main.rkt
+++ b/main.rkt
@@ -203,17 +203,20 @@
        (> (trick-invocations l) (trick-invocations r)))))

(define (popular-tricks client db message text)
  (let ([tricks (sort (db:all-tricks db (context-id message)) cmp-tricks)])
  (let* ([tricks (sort (db:all-tricks db (context-id message)) cmp-tricks)]
         [pages  (exact-ceiling (/ (length tricks) leaderboard-size))]
         [pageno (~> text (string->number 10 'number-or-false) (or 1) inexact->exact (max 1) (min pages) sub1)]
         [page   (drop tricks (* leaderboard-size pageno))])
    (if (empty? tricks)
        (~a "There aren't any tricks registered in your guild! Use `" prefix "register` to create one.")
        (apply ~a "**Most popular tricks in your guild:**"
               (for/list ([(trick i)
                           (in-indexed
                            (if (> (length tricks) leaderboard-size)
                                (take tricks leaderboard-size)
                                tricks))])
        (apply ~a "**Most popular tricks in your guild (page " (add1 pageno) " of " pages "):**"
               (for/list ([i (in-naturals (add1 (* leaderboard-size pageno)))]
                          [trick
                            (if (> (length page) leaderboard-size)
                                (take page leaderboard-size)
                                page)])
                 (~a
                  "\n" (add1 i) ". **" (car trick) "**, by <@" (trick-author (cdr trick))
                  "\n" i ". **" (car trick) "**, by <@" (trick-author (cdr trick))
                  ">, invoked **" (trick-invocations (cdr trick)) "**x"))))))

(define (show-trick client db message text)
-- 
2.25.1