summaryrefslogtreecommitdiff
path: root/src/main.lisp
blob: ee37ddc2a97ce17696364dc34ae6136906e73020 (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
(defpackage nullbot
  (:use #:cl
        #:cl-hash-util)
  (:local-nicknames
   (:jzon :com.inuoe.jzon)
   (:mapi :nullbot/matrix-api)
   (:sseq :split-sequence))
  (:export
   #:start))
(in-package #:nullbot)

(defclass nullbot (mapi:matrix-bot) ())
(defparameter *bot* (make-instance 'nullbot
                                   :token (uiop:getenv "NULLBOT_TOKEN")
                                   :homeserver "matrix.nullring.xyz"))

(defun process-roommsg
    (content room-id sender
     &aux
       (msgtype (gethash "msgtype" content))
       (body (gethash "body" content))
       (split-body (sseq:split-sequence #\Space body))
       (command (car split-body)))
  (format t "processing msg~%")
  (when (and (> (length body) 0) (equal (aref (car split-body) 0) #\$))
    (cond
      ((string= command "$help")
       (mapi:sendmsg *bot* room-id "Unlike some other bots, I'm nice :3")))))

(defmethod mapi:on-event
    ((obj nullbot) event room-id
     &aux
       (msgtype (gethash "type" event))
       (sender (gethash "sender" event)))
  (cond
    ((string= msgtype "m.room.message")
     (process-roommsg (gethash "content" event) room-id sender))))