summaryrefslogtreecommitdiff
path: root/src/wasp-user-stats.el
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2026-04-26 23:47:18 -0400
committerLLLL Colonq <llll@colonq>2026-04-26 23:47:18 -0400
commit75e005e81b73d8471f16dc5fad7bbdc312bdbfe7 (patch)
tree1ad7d61b04c44fc52b453aef44868a42012f3551 /src/wasp-user-stats.el
parentcf266a56f30daae8b9af7c9bc3267c61b1973192 (diff)
Diffstat (limited to 'src/wasp-user-stats.el')
-rw-r--r--src/wasp-user-stats.el109
1 files changed, 67 insertions, 42 deletions
diff --git a/src/wasp-user-stats.el b/src/wasp-user-stats.el
index 74c320aa..6fd52f81 100644
--- a/src/wasp-user-stats.el
+++ b/src/wasp-user-stats.el
@@ -7,24 +7,26 @@
(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)))
+ (let* ((factions '("nate" "lever" "tony")))
(nth (random (length factions)) factions))))
-(defun w/user-ensure-faction ()
- "Ensure that the current user has a faction assigned."
- (let ((cur (alist-get :faction w/user-current)))
- (unless cur
- (setf (alist-get :faction w/user-current)
- (w/user-initial-faction w/user-current-name)))))
+(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")
@@ -36,44 +38,67 @@
"Determine the initial faction for USER."
(let* ((factions w/user-elements))
(car (nth (random (length factions)) factions))))
-(defun w/user-ensure-element ()
- "Ensure that the current user has a faction assigned."
- (let ((cur (alist-get :element w/user-current)))
- (unless cur
- (setf (alist-get :element w/user-current)
- (w/user-initial-element)))))
+(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-faction-total (faction)
- "Compute the boost totals for FACTION."
- (-sum
- (-non-nil
- (--map
- (alist-get :boost it)
- (--filter
- (and (listp it) (eq faction (alist-get :faction it)))
- (ht-values w/user-cache))))))
-(defun w/user-faction-totals ()
- "Compute the boost totals for each FACTION."
- (list
- (w/user-faction-total 'nate)
- (w/user-faction-total 'tony)
- (w/user-faction-total 'lever)))
+(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-name ()
- "Ensure that the current user has a name assigned."
- (let ((cur (alist-get :name w/user-current)))
- (unless cur
- (setf (alist-get :name w/user-current) w/user-current-name))))
+(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 ()
- "Ensure that the current user has all stats."
- (w/user-ensure-name)
- (w/user-ensure-faction)
- (w/user-ensure-element))
+(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-stats-update-color (color)
- "Ensure that COLOR is set for the current user."
- (setf (alist-get :color w/user-current) color))
+(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