summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGrant Shangreaux <shshoshin@protonmail.com>2019-10-04 13:16:33 -0500
committerGrant Shangreaux <shshoshin@protonmail.com>2019-10-04 13:16:33 -0500
commit58f698906747f5285ce6f6344eea96e05a6931a6 (patch)
tree8dc4ca0b56266672cc2e826a3c218c2911849e2e /examples
parentb98b2f23185980df0592ada3631886d6e31834ce (diff)
Clean: *room-id* special var refactoring handle-event generic
This addresses the conversation in issue #1. I went ahead and created the readme file to document the `*room-id*` variable. Also this commit removes the hardcoded value for the roshamo example bot, and provides a function to create and login your roshambot instead.
Diffstat (limited to 'examples')
-rw-r--r--examples/roshambot.lisp35
1 files changed, 12 insertions, 23 deletions
diff --git a/examples/roshambot.lisp b/examples/roshambot.lisp
index 1062302..48ed49d 100644
--- a/examples/roshambot.lisp
+++ b/examples/roshambot.lisp
@@ -4,12 +4,6 @@
(defpackage #:roshambot
(:use :cl :granolin))
- ;; (:import-from :granolin
- ;; :handle-event
- ;; :find-contact
- ;; :text-message-event
- ;; :send-text-message
- ;; :let-cond))
(in-package :roshambot)
@@ -58,14 +52,14 @@
(defun roshambo-move!? (str)
(nth-value 0 (ppcre:scan-to-strings +roshambo-move-regex+ str)))
-(defmethod handle-event :after ((bot roshambot) (event text-message-event) &optional room-id)
+(defmethod handle-event :after ((bot roshambot) (event text-message-event))
(let ((text (granolin:msg-body event)))
(let-cond
(challenged (you-wanna-piece-of-this!? text)
- (handle-new-challenge bot room-id (granolin:sender event) challenged))
- (roshambo-match (challenger-made-move!? bot room-id (granolin::sender event) text)
+ (handle-new-challenge bot *room-id* (granolin:sender event) challenged))
+ (roshambo-match (challenger-made-move!? bot *room-id* (granolin::sender event) text)
(handle-match-state-change bot roshambo-match))
- (roshambo-match (challenged-made-move!? bot room-id (granolin::sender event) text)
+ (roshambo-match (challenged-made-move!? bot *room-id* (granolin::sender event) text)
(handle-match-state-change bot roshambo-match)))))
(defun challenger-made-move!? (bot room-id sender text)
@@ -207,19 +201,14 @@
(defclass roshambo-bot (granolin:client granolin:server-directory roshambot auto-joiner) ())
-;; (defmethod handle-event :after ((bot roshambot-bot) (ev timeline-event) &optional room-id)
-;; (format t "~a - ~a:~% ~a~%" room-id (granolin::sender ev) (granolin:msg-body ev)))
+(defmethod handle-event :after ((bot roshambo-bot) (ev text-message-event))
+ (format t "~a - ~a:~% ~a~%" *room-id* (granolin::sender ev) (granolin:msg-body ev)))
-(defmethod handle-event :after ((bot roshambo-bot) (ev text-message-event) &optional room-id)
- (format t "~a - ~a:~% ~a~%" room-id (granolin::sender ev) (granolin:msg-body ev)))
-
-(defmethod handle-event :after ((bot roshambo-bot)
- (ev granolin::account-data-event)
- &optional room-id)
+(defmethod handle-event :after ((bot roshambo-bot) (ev granolin::account-data-event))
(format t "~a ~a" (event-type ev) (event-content ev)))
-
-(defvar *roshambot* (make-instance 'roshambo-bot
- :homeserver "https://matrix.hrlo.world"))
-
-
+;; creates and authenticates the bot, returns the bot instance
+(defun roshambot (homeserver user password)
+ (let ((bot (make-instance 'roshambo-bot :homeserver homeserver)))
+ (login bot user password)
+ bot))