be6f8571 |
(defmacro if-let* ((&rest bindings) &body (then-form &optional else-form))
"Like if-let, but sets bindings sequentially. Doesn't short-circuit."
`(let* ,bindings
(if (and ,@(mapcar #'car bindings))
,then-form
,else-form)))
;; Utility functions
(defun pick (keys h-t)
(mapcar (plambda:plambda (gethash :1 h-t))
keys))
(define-command "myip" (event-pump ts channel)
(in-wq (event-pump)
(blackbird:alet ((ip (carrier:request "http://api.ipify.org/" :return-body t)))
|
5ea361e0 |
(string-case for
("channel" channel)
(t (concat "don't know the id for " for)))))
(defmacro with ((var val) &body body)
`(let ((,var ,val))
,@body))
(ql:quickload '(:vecto :ironclad))
(defun hash-of-vector (vec)
(ironclad:byte-array-to-hex-string (ironclad:digest-sequence :sha256 vec)))
(defpackage #:vecto-example
(:use :cl :alexandria :serapeum :slacker :vecto)
(:shadowing-import-from :alexandria :rotate))
(in-package :vecto-example)
(defmacro with ((var val) &body body)
`(let ((,var ,val))
,@body))
(defun octets-to-36string (octets)
(string-join (map 'list (lambda (it)
(format nil "~2,1,0,'0@a"
(with (*print-base* 36)
(write-to-string it ))))
octets)))
(defmacro with-digested-output ((stream (data-sym digest-sym)) data-form &body body)
(with-gensyms (digest-stream data-stream)
`(let* ((,digest-stream (ironclad:make-digesting-stream :sha256))
(,data-stream (ironclad:make-octet-output-stream))
(,stream (make-broadcast-stream ,data-stream ,digest-stream)))
,data-form
(let ((,data-sym (ironclad:get-output-stream-octets ,data-stream))
(,digest-sym (ironclad:produce-digest ,digest-stream)))
,@body))))
(define-command "ring-word" (event-pump ts channel &optional (content #(#x3BB)))
(bt:make-thread
(lambda ()
(declare (optimize (debug 3)))
(let ((*default-pathname-defaults* "/home/edwlan/github_repos/hhgbot/"))
(with-canvas (:width 90 :height 90)
(let ((font (get-font "times.ttf"))
(step (/ pi 7)))
(set-font font 40)
(translate 45 45)
(format hhgbot-augmented-assistant::*zxcv* "~&content: ~s~%" content)
(draw-centered-string 0 -10 (map 'vector #'char-code content))
(set-rgb-stroke 1 0 0)
(centered-circle-path 0 0 35)
(stroke)
(set-rgba-stroke 0 0 1.0 0.5)
(set-line-width 4)
(dotimes (i 14)
(with-graphics-state
(vecto:rotate (* i step))
(move-to 30 0)
(line-to 40 0)
(stroke))))
(let* ((image-directory (ensure-directories-exist "/home/edwlan/public_html/slack_images/"))
(image-basename (concat channel "-" ts ".png"))
(image-filename (merge-pathnames image-basename image-directory))
(payload
(concat "token=" *api-token*
"&channel=" channel
"&text=..."
"&as_user=true"
"&attachments="
(quri:url-encode
(concat
"[{\"fallback\": \"foo\", \"ts\":" ts ",\"image_url\": \"https://srv2.elangley.org/~edwlan/slack_images/"
image-basename "\"}]")))))
(vecto:save-png image-filename)
(babel:octets-to-string
(drakma:http-request "https://slack.com/api/chat.postMessage"
:method :post
:content payload))))))
:name "Image Maker"))
|