From be87455504a9db1278357e7525a3a4147e19be37 Mon Sep 17 00:00:00 2001 From: Kazuo Koga Date: Sun, 31 Jul 2016 22:53:23 +0900 Subject: [PATCH] add run client script --- client.ros | 39 +++++++++++++++++++++++++++++++++++++++ src/slack-client.lisp | 5 +---- t/slack-client.lisp | 20 -------------------- 3 files changed, 40 insertions(+), 24 deletions(-) create mode 100755 client.ros diff --git a/client.ros b/client.ros new file mode 100755 index 0000000..d761166 --- /dev/null +++ b/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: diff --git a/src/slack-client.lisp b/src/slack-client.lisp index aeb7dde..a0cc891 100644 --- a/src/slack-client.lisp +++ b/src/slack-client.lisp @@ -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) diff --git a/t/slack-client.lisp b/t/slack-client.lisp index 2257cbf..fa1b661 100644 --- a/t/slack-client.lisp +++ b/t/slack-client.lisp @@ -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)