summaryrefslogtreecommitdiff
path: root/src/wasp-user-badges.el
blob: d34a9fa6a669c3f7be25dd909297b4752e603228 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
;;; wsp-user-badges --- badges -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:

(require 'wasp-utils)
(require 'wasp-db)

(defvar w/badge-cache (ht-create))
(defun w/badge-populate-cache ()
  "Populate the `w/badge-cache' with all badges."
  (message "Populating badge cache...")
  (w/db-hgetall "badge:name"
    (lambda (bnames)
      (message "Retrieved names...")
      (w/db-hgetall "badge:desc"
        (lambda (bdescs)
          (message "Retrieved descriptions...")
          (w/db-hgetall "badge:mode"
            (lambda (bmodes)
              (message "Retrieved modes...")
              (w/db-hgetall "badge:text"
                (lambda (btexts)
                  (message "Retrieved text...")
                  (w/db-hgetall "badge:icon"
                    (lambda (bicons)
                      (message "Retrieved icons!")
                      (ht-clear! w/badge-cache)
                      (--each (ht-keys bnames)
                        (message "Processing badge: %s" it)
                        (ht-set! w/badge-cache it
                          (ht<-alist
                            `( (name . ,(ht-get bnames it))
                               (desc . ,(ht-get bdescs it))
                               (mode . ,(ht-get bmodes it))
                               (text . ,(ht-get btexts it))
                               (icon .
                                 ,(when-let* ((data (ht-get bicons it)))
                                    (create-image
                                      (encode-coding-string data 'no-conversion)
                                      nil t
                                      :height 20
                                      :ascent 'center))))))))))))))))))

(defun w/user-badge-text (uid k)
  "Pass a string of badges to attach to UID's messages to K."
  (w/db-smembers (s-concat "user:badges:" uid)
    (lambda (badges)
      (funcall k
        (s-join ""
          (--map
            (when-let* ((b (ht-get w/badge-cache it)))
              (cond
                ((s-equals? (ht-get b 'mode) "text")
                  (ht-get b 'text))
                ((s-equals? (ht-get b 'mode) "icon")
                  (propertize "Q" 'display (ht-get b 'icon)))))
            badges))))))

(defun w/badge-create-text (bid name desc text)
  "Create a new talent BID called NAME with DESC and TEXT."
  (w/db-hset "badge:name" bid name)
  (w/db-hset "badge:desc" bid desc)
  (w/db-hset "badge:mode" bid "text")
  (w/db-hset "badge:text" bid text))

(defun w/badge-create-icon (bid name desc iconpath)
  "Create a new talent BID called NAME with DESC and ICONPATH."
  (let ((icon (or (f-read-bytes iconpath) (error "Failed to open icon path: %s" iconpath))))
    (progn
      (w/db-hset "badge:name" bid name)
      (w/db-hset "badge:desc" bid desc)
      (w/db-hset "badge:mode" bid "icon")
      (w/db-hset "badge:icon" bid icon))))

(defun w/badge-grant (uid bid)
  "Give badge BID to user UID."
  (w/db-sadd (s-concat "user:badges:" uid) bid))

(defun w/badge-custom-equity-text (user text)
  "Give badge TEXT to USER."
  (let ((bid (w/uuid)))
    (w/badge-create-text bid "Equity Lord" "This user holds Equity Lordship status, entitling them to a vote at the shareholders' meeting." text)
    (w/user-id-from-name user
      (lambda (uid)
        (w/badge-grant uid bid)))))

(defun w/badge-custom-equity-icon (user icon)
  "Give badge ICON to USER."
  (let ((bid (w/uuid)))
    (w/badge-create-icon bid "Equity Lord" "This user holds Equity Lordship status, entitling them to a vote at the shareholders' meeting." icon)
    (w/user-id-from-name user
      (lambda (uid)
        (w/badge-grant uid bid)))))

(defun w/badge-default-equity (user)
  "Give USER the default equity badge."
  (w/user-id-from-name user
    (lambda (uid)
      (w/badge-grant uid "equitylord"))))

;; (w/badge-create-icon "equitylord" "Equity Lord" "This user holds Equity Lordship status, entitling them to a vote at the shareholders' meeting." (w/asset "badges/equitylord.png"))
;; (w/badge-create-text "themale" "MALE" "This user is known as \"The Male\" by some." "🧍‍♂ïļ")
;; (w/badge-create-icon "slime" "Slime" "This user is \"slime\"." (w/asset "badges/slime.png"))
;; (w/user-id-from-name "LCOLONQ"
;;   (lambda (uid)
;;     (w/badge-grant uid "equitylord")
;;     (w/badge-grant uid "themale")
;;     ))
;; (w/user-id-from-name "acher0_" (lambda (uid) (w/badge-grant uid "slime")))
;; (w/badge-custom-equity-text "bezelea" "â™ŋ")
;; (w/badge-custom-equity-text "bezelea" "🔔")
;; (w/badge-custom-equity-text "altovt" "📈")
;; (w/badge-custom-equity-text "prodzpod" "🌠")
;; (w/badge-custom-equity-text "prodzpod" "🌌")
;; (w/badge-custom-equity-text "prodzpod" "🎑")
;; (w/badge-custom-equity-text "faeliore" "ðŸ˜đ")
;; (w/badge-custom-equity-text "vasher_1025" "ðŸ•ī")
;; (w/badge-custom-equity-text "leadengin" "💈")
;; (w/badge-default-equity "kettlestew")
;; (w/badge-custom-equity-text "blazynights" "🀄")
;; (w/badge-default-equity "must_broke_")
;; (w/badge-custom-equity-text "bvnanana" "🧉")
;; (w/badge-custom-equity-text "venorrak" "📚")
;; (w/badge-custom-equity-text "venorrak" "📜")
;; (w/badge-default-equity "tf_tokyo")
;; (w/badge-custom-equity-text "devts_de" "∃")
;; (w/badge-custom-equity-icon "trap_exit" (w/twitch-emote-path "emotesv2_dfc4c36ccd3b4994b8ca4f082230f053"))
;; (w/badge-custom-equity-text "trap_exit" "☠")
;; (w/badge-custom-equity-text "trap_exit" "💀")
;; (w/badge-custom-equity-text "essento" "ðŸĨš")
;; (w/badge-custom-equity-text "tyumici" "ðŸĪŒ")
;; (w/badge-default-equity "liquidcake1")
;; (w/badge-default-equity "loufbread")
;; (w/badge-custom-equity-text "yellowberryhn" "ðŸŠī")
;; (w/badge-default-equity "maradyne_")
;; (w/badge-default-equity "sampie159")
;; (w/badge-custom-equity-text "zamielpayne" "ðŸĶ‰")
;; (w/badge-custom-equity-text "xorxavier" "ðŸŒļ")
;; (w/badge-custom-equity-text "6horntaurus" "⚰")
;; (w/badge-custom-equity-icon "bytomancer" (w/twitch-emote-path "emotesv2_beb191005b81486c8b1c823931c88387"))
;; (w/badge-default-equity "henriqmarq")
;; (w/badge-default-equity "wyndupboy")
;; (w/badge-custom-equity-text "steeledshield" "â›Ļ")
;; (w/badge-custom-equity-icon "asrael_io" (w/twitch-emote-path "emotesv2_a9dc5935824a4d6792f4b48f91031fcf"))
;; (w/badge-custom-equity-text "nichepenguin" "💚")
;; (w/badge-default-equity "h_ingles")
;; (w/badge-default-equity "compilingjay")
;; (w/badge-default-equity "watchmakering")
;; (w/badge-custom-equity-text "the0x539" "ïļ˜")
;; (w/badge-custom-equity-text "colinahscopy_" "⚜")
;; (w/badge-default-equity "eighteyedsixwingedseraph")
;; (w/badge-default-equity "a_tension_span")
;; (w/badge-default-equity "tomaterr")
;; (w/badge-custom-equity-icon "realnaesten" (w/twitch-emote-path "emotesv2_4d2812c659c14c64a9a4044c3eff6d30"))
;; (w/badge-default-equity "fmega")
;; (w/badge-default-equity "cr4zyk1tty")
;; (w/badge-default-equity "physbuzz")
;; (w/badge-custom-equity-text "sundemoniac" "🌞")
;; (w/badge-custom-equity-text "pralkewe67" "🌞")
;; (w/badge-custom-equity-text "nichePenguin" "🍋‍ðŸŸĐ")
;; (w/badge-custom-equity-icon "ellg" (w/twitch-emote-path "emotesv2_27a7f5d066144fb59490efae6c91820a"))

(provide 'wasp-user-badges)
;;; wasp-user-badges.el ends here