Skip to content

Commit

Permalink
add run client script
Browse files Browse the repository at this point in the history
  • Loading branch information
kkazuo committed Jul 31, 2016
1 parent b1d020b commit be87455
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
39 changes: 39 additions & 0 deletions client.ros
@@ -0,0 +1,39 @@
#!/bin/sh
#|-*- mode:lisp -*-|#
#| Slack rtm client.
exec ros -Q -- $0 "$@"
|#
(progn ;;init forms
(push #p"./" asdf:*central-registry*)
(ql:quickload "slack-client" :silent t))

(defpackage :ros.script.client.3678960423
(:use :cl))
(in-package :ros.script.client.3678960423)

(defun example ()
(let ((client (make-instance 'sc:slack-client)))
(sc:bind "hello" client
(lambda (ev)
(declare (ignore ev))
(format t "connected.~%")))
(sc:bind "message" client
(lambda (ev)
(sc:with-data-let ev (channel user text)
(format t "~A:~A: ~A~%" channel user text)
(when (equal text "hello")
(sc:send-text client channel "world"))
(when (equal text "now")
(sc:send-text client channel (get-universal-time))))))

(as:with-event-loop ()
(as:signal-handler
as:+sigint+ (lambda (sig)
(declare (ignore sig))
(as:exit-event-loop)))
(sc:run-client client))))

(defun main (&rest argv)
(declare (ignorable argv))
(example))
;;; vim: set ft=lisp lisp:
5 changes: 1 addition & 4 deletions src/slack-client.lisp
Expand Up @@ -163,10 +163,7 @@
:close ws
(lambda (code reason)
(format t "Closed because '~A' (Code=~A)~%" reason code)))
(wsd:start-connection ws))
(format t "started.~%"))
(t
(format t "failed.~%"))))
(wsd:start-connection ws)))))

(defun run-client (client)
(bb:chain (slack-api-token)
Expand Down
20 changes: 0 additions & 20 deletions t/slack-client.lisp
Expand Up @@ -8,24 +8,4 @@

(plan nil)

(defparameter *c* (make-instance 'sc:slack-client))
(sc:bind :* *c*
(lambda (ev)
(format t "~A: ~A~%" (ev:ev ev) ev)))
(sc:bind "message" *c*
(lambda (ev)
(sc:with-data-let ev (channel user text)
(format t "~A:~A: ~A~%" channel user text)
(when (equal text "hello")
(sc:send-text *c* channel "world"))
(when (equal text "now")
(sc:send-text *c* channel (get-universal-time))))))

(as:with-event-loop ()
(as:signal-handler
as:+sigint+ (lambda (sig)
(declare (ignore sig))
(as:exit-event-loop)))
(sc:run-client *c*))

(finalize)

0 comments on commit be87455

Please sign in to comment.