summaryrefslogtreecommitdiff
path: root/utilities.lisp
blob: 5644f2e375e8eb98ebf90118dcd3eaa75c626b72 (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
;;;; utilities -- nuff said

(in-package :dnd)


(let ((host (uiop:hostname))
      (count 0))
  (defun nuid ()
    "Generates a Nearly Universal ID"
    (format nil "~36r"
            (sxhash
             (list
              (incf count)
              host
              (get-universal-time))))))

(defun hash-string (plaintext salt)
  "Hash plaintext using SALT"
  (flexi-streams:octets-to-string 
   (ironclad:digest-sequence
    :sha3
    (flexi-streams:string-to-octets (concatenate 'string salt plaintext)
                                    :external-format :utf-8))
   :external-format :latin1))

(defparameter +user-nick-chars+ "0123456789abcdefghijklmnopqrstuvwxyz-._")

(defun/t valid-nick-p (nick)
  :tests
  (eql ("??????") nil)
  (eql ("⚔") nil)
  (eql ("cool_beans") t)
  (eql ("COOOL_BEANS") t)
  (eql ("COOL beans") nil)
  :end 
  (unless (zerop (length nick))
    (every (lambda (char) (find char +user-nick-chars+)) (string-downcase nick))))