;;; 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