blob: 6fd52f81d88ecb063350c1e62db5714669547497 (
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
|
;;; wasp-user-stats --- User data: statistics -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(require 'dash)
(require 's)
(require 'ht)
(require 'wasp-user)
;;;; Factions
(defvar w/user-faction-exemptions
(list
"LCOLONQ"
"MODCLONK"
"fn_lumi"))
(defun w/user-initial-faction (user)
"Determine the initial faction for USER."
(unless (-contains? w/user-faction-exemptions user)
(let* ((factions '("nate" "lever" "tony")))
(nth (random (length factions)) factions))))
(defun w/user-ensure-faction (uid nm)
"Ensure that user UID named NM has a faction assigned."
(w/user-get-property uid "faction"
(lambda (cur)
(unless cur
(when-let* ((new (w/user-initial-faction nm)))
(w/user-set-property uid "faction" new))))))
;;;; Elements
(defconst w/user-elements
'(("fire" "🔥" "red")
("water" "🌊" "blue")
("wind" "🍃️" "green")
("earth" "🪨" "brown")
("lightning" "⚡" "yellow")
("heart" "🩷" "pink")))
(defun w/user-initial-element ()
"Determine the initial faction for USER."
(let* ((factions w/user-elements))
(car (nth (random (length factions)) factions))))
(defun w/user-ensure-element (uid nm)
"Ensure that the user UID named NM has a faction assigned."
(ignore nm)
(w/user-get-property uid "element"
(lambda (cur)
(unless cur
(w/user-set-property uid "element" (w/user-initial-element))))))
(defun w/user-ensure-name (uid nm)
"Ensure that the user UID named NM has a name assigned."
(w/user-get-property uid "name"
(lambda (cur)
(unless (and cur (s-equals? (s-downcase cur) (s-downcase nm)))
(w/user-set-property uid "name"
(s-downcase nm))))))
(defun w/user-ensure-attribute (uid nm attr init)
"Ensure that the user UID named NM has attribute ATTR assigned.
INIT is the initial value."
(ignore nm)
(w/user-get-stat uid attr
(lambda (cur)
(unless (integerp cur)
(w/user-set-stat uid attr init)))))
(defun w/user-ensure-attribute-nonzero (uid nm attr init)
"Ensure that the user UID named NM has attribute ATTR assigned.
INIT is the initial value."
(ignore nm)
(w/user-get-stat uid attr
(lambda (cur)
(unless (and (integerp cur) (> cur 0))
(w/user-set-stat uid attr init)))))
(defun w/user-ensure-icon (uid nm)
"Ensure that the user UID named NM has an icon uploaded."
(let ((key (format "user:avatar:%s" uid)))
(w/db-exists key
(lambda (exists)
(unless exists
(w/twitch-get-user-avatar nm
(lambda ()
(when-let* ((avatar (w/user-avatar nm)))
(w/db-set key avatar)))))))))
(defun w/user-stats-update (uid nm)
"Ensure that the user UID named NM has all stats."
(w/user-ensure-faction uid nm)
(w/user-ensure-element uid nm)
(w/user-ensure-name uid nm)
(w/user-ensure-icon uid nm)
(w/user-ensure-attribute uid nm "power" (+ 9 (random 3)))
(w/user-ensure-attribute uid nm "speed" (+ 9 (random 3)))
(w/user-ensure-attribute uid nm "majjyka" (+ 9 (random 3)))
(w/user-ensure-attribute uid nm "wisdom" (+ 9 (random 3)))
(w/user-ensure-attribute-nonzero uid nm "talentpoints" 5))
(defun w/user-color-update (uid nm color)
"Ensure that COLOR is set for the user UID named NM."
(ignore nm)
(w/user-set-property uid "color" color))
(provide 'wasp-user-stats)
;;; wasp-user-stats.el ends here
|