~williewillus/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

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

Details
Message ID
<20210723214208.173212-1-wenming.yi@gmail.com>
DKIM signature
pass
Download raw message
Patch: +1 -1
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

Details
Message ID
<20210723214208.173212-2-wenming.yi@gmail.com>
In-Reply-To
<20210723214208.173212-1-wenming.yi@gmail.com> (view parent)
DKIM signature
pass
Download raw message
Patch: +11 -8
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
Reply to thread Export thread (mbox)