~williewillus/public-inbox

First-order admin check fix (TODO: update roles on role mod) v1 SUPERSEDED

: 1
 First-order admin check fix (TODO: update roles on role mod)

 1 files changed, 22 insertions(+), 6 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/31222/mbox | git am -3
Learn more about email & git

[PATCH] First-order admin check fix (TODO: update roles on role mod) Export this patch

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

---
 frontends/discord.rkt | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/frontends/discord.rkt b/frontends/discord.rkt
index fb2fefe..75f59a7 100644
--- a/frontends/discord.rkt
+++ b/frontends/discord.rkt
@@ -1,6 +1,7 @@
#lang racket/base

(require
  json
 (only-in net/url get-pure-port string->url)
 racket/async-channel
 racket/class
@@ -134,18 +135,32 @@
    (define/public (response? v)
      (http:attachment? v))

    (define known-roles (make-hash))
    (define known-default-roles (make-hash))

    (define (setup-role guild-id role)
      (define perms (string->number (hash-ref role 'permissions)))
      (if (string=? (hash-ref role 'name) "@everyone")
        (hash-set! known-default-roles guild-id perms)
        (hash-set! known-roles (hash-ref role 'id) perms)))

    (define (message-perms message guild-id)
      (and~>> message
              (hash-ref _ 'member)
              (hash-ref _ 'roles)
              (map (lambda (r) (hash-ref known-roles r 0)))
              (foldl bitwise-ior (or (hash-ref known-default-roles guild-id #f) 0))))

    (define/public (can-modify? trick-obj)
      (define author-id (message-author-id (current-message)))
      (define guild-id (hash-ref (current-message) 'guild_id))
      (define perms (bitwise-ior rc:permission-administrator
                                 rc:permission-manage-guild))
      (or
       (equal? (trick-author trick-obj) author-id)
       (and~> (current-message)
              (hash-ref _ 'member)
              (hash-ref _ 'permissions)
              string->number
              (bitwise-and perms)
              ((negate zero?)))))
       (~> (message-perms (current-message) guild-id)
         (bitwise-and perms)
         zero? not)))

    ;; context/guild id -> (emote name -> emote id)
    (define emote-name-lookup (make-hash))
@@ -304,6 +319,7 @@
      (hash-set! emote-name-lookup
                 (hash-ref guild 'id)
                 (extract-emojis guild))
      (for-each (curry setup-role (hash-ref guild 'id)) (hash-ref guild 'roles))
      (recompute-known-emotes))

    (define (guild-delete _ws-client _client guild)
-- 
2.25.1