96 lines
3.1 KiB
Common Lisp
96 lines
3.1 KiB
Common Lisp
;; Copyright (C) 2013 Tom Willemsen <tom at ryuslash dot org>
|
|
|
|
;; This file is part of Sil
|
|
|
|
;; Sil is free software: you can redistribute it and/or modify it
|
|
;; under the terms of the GNU General Public License as published by
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
;; (at your option) any later version.
|
|
|
|
;; Sil is distributed in the hope that it will be useful, but WITHOUT
|
|
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
;; License for more details.
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with Sil. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
;;; Code:
|
|
|
|
(in-package :org.ryuslash.sil)
|
|
|
|
(require 'cl-xmpp-tls)
|
|
|
|
(export '(sil))
|
|
|
|
(defvar *connection* nil
|
|
"The connection to the jabber server.")
|
|
|
|
(defvar *host* "ryuslash.org"
|
|
"The host to log-in on.")
|
|
|
|
(defvar *username* "sil"
|
|
"The username to log-in with, should not contain the jabber host.")
|
|
|
|
(defvar *password* "tomtom"
|
|
"The password to log-in with.")
|
|
|
|
(defvar *resource* "test"
|
|
"The resource to use when logging in.")
|
|
|
|
(defvar *muc-rooms-alist* '("aethon@muc.ryuslash.org/sil")
|
|
"Any MUCs to join.")
|
|
|
|
(defvar *jid* "sil@ryuslash.org/test"
|
|
"The JID used.")
|
|
|
|
(defun get-rc-location ()
|
|
"Get the location of the RC file."
|
|
(let ((xdg (sb-ext:posix-getenv "XDG_DATA_HOME"))
|
|
(home (sb-ext:posix-getenv "HOME")))
|
|
(pathname
|
|
(apply 'concatenate 'string
|
|
(or xdg home)
|
|
(unless xdg "/.config")
|
|
'("/sil/rc.lisp")))))
|
|
|
|
(defun get-response (message)
|
|
(cond
|
|
((string-equal (body message) "date")
|
|
(multiple-value-bind (second minute hour date month year day
|
|
daylight-p zone) (get-decoded-time)
|
|
(declare (ignore day daylight-p zone))
|
|
(format nil "Date: ~D-~D-~D ~D:~D:~D" date month year hour
|
|
minute second)))
|
|
(t (format nil "auto-reply to: ~A" (from message)))))
|
|
|
|
(defmethod handle ((connection connection) (message message))
|
|
(if (string-equal (type- message) "groupchat")
|
|
(when (string-equal (body message) "," :end1 1)
|
|
(setf (body message) (subseq (body message) 1))
|
|
(xmpp:message connection "aethon@muc.ryuslash.org"
|
|
(get-response message) :type :groupchat))
|
|
(xmpp:message connection (from message) (get-response message))))
|
|
|
|
(defun load-rc ()
|
|
"Load the RC file."
|
|
(let ((*package* (in-package :org.ryuslash.sil)))
|
|
(load (get-rc-location) :if-does-not-exist nil)))
|
|
|
|
(defun receive ()
|
|
(format t "Recieving~%")
|
|
(handler-case (receive-stanza-loop *connection*)
|
|
(simple-error () (receive))))
|
|
|
|
(defun sil (args)
|
|
(handler-case
|
|
(progn
|
|
(load-rc)
|
|
(setf *connection* (connect-tls :hostname *host*))
|
|
(auth *connection* "sil" "tomtom" "test")
|
|
(map nil (lambda (ms)
|
|
(join-chatroom *connection* :room ms :from *jid*))
|
|
*muc-rooms-alist*)
|
|
(receive))
|
|
(sb-sys:interactive-interrupt () (format t "No! Don't leave me. *sob*~%")))
|
|
(disconnect *connection*))
|