diff options
| author | LLLL Colonq <llll@colonq> | 2024-09-13 13:52:38 -0400 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2024-09-13 13:52:38 -0400 |
| commit | d93ab7e848bf0f4bc1087504eecd7c959d19bf6c (patch) | |
| tree | f4f1806ceb56d2a68c9641313000f9a50fa77d78 /src/gizmo/wasp-hexamedia.el | |
| parent | cc3ccebbd3af825f5e4866532906f1a7a2756518 (diff) | |
Update :3
Diffstat (limited to 'src/gizmo/wasp-hexamedia.el')
| -rw-r--r-- | src/gizmo/wasp-hexamedia.el | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/gizmo/wasp-hexamedia.el b/src/gizmo/wasp-hexamedia.el new file mode 100644 index 00000000..58ea5ef7 --- /dev/null +++ b/src/gizmo/wasp-hexamedia.el @@ -0,0 +1,79 @@ +;;; wasp-hexamedia --- Hexamedia interface -*- lexical-binding: t; -*- +;;; Commentary: +;;; Code: + +(require 'dash) +(require 's) +(require 'f) +(require 'ht) +(require 'rx) +(require 'cl-lib) +(require 'request) +(require 'dom) +(require 'wasp-user) + +(defcustom w/hexamedia-server "https://hexa.media" + "Server URL for Hexamedia." + :type '(string) + :group 'wasp) + +(defvar w/hexamedia-last-response nil) + +(defun w/hexamedia-get (loc k) + "Get LOC from Hexamedia, passing the returned HTML to K." + (setf request-message-level -1) + (request + (s-concat w/hexamedia-server loc) + :type "GET" + :parser (lambda () (libxml-parse-html-region (point-min) (point-max))) + :success + (cl-function + (lambda (&key data &allow-other-keys) + (setq w/hexamedia-last-response data) + (funcall k data)))) + t) + +(defun w/hexamedia-parse-binder-string (bs) + "Given BS, return the number of obtained cards." + (let ((match + (s-match-strings-all + (rx + string-start + (group (zero-or-more (or alnum space))) + " Set (" + (group (one-or-more digit)) + ) + bs))) + (cons (cadar match) (string-to-number (caddar match))))) + +(defun w/hexamedia-get-card-totals (user k) + "Retrieve the Hexamedia binder for USER. +Pass the resulting card totals to K." + (w/hexamedia-get + (s-concat "/binder/" (s-downcase user)) + (lambda (p) + (funcall + k + (-map + #'w/hexamedia-parse-binder-string + (-filter + #'stringp + (--map + (caddr it) + (dom-by-tag p 'center)))))))) + +(defvar w/hexamedia-user-cache nil) +(defun w/hexamedia-update-user (user) + "Update USER data from Hexamedia." + (unless (-contains? w/hexamedia-user-cache user) + (add-to-list 'w/hexamedia-user-cache user) + (w/hexamedia-get-card-totals + user + (lambda (ct) + (w/user-bind + user + (lambda () + (setf (alist-get :hexamedia-cards w/user-current) ct))))))) + +(provide 'wasp-hexamedia) +;;; wasp-hexamedia.el ends here |
