-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands-keyword.lisp
41 lines (32 loc) · 1.37 KB
/
commands-keyword.lisp
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
38
;;Commands keyword definitions
(in-package :lotzo)
;;command prefix string
(defvar *command-prefix-character* "!")
;command keyword
;;all commands starts with "!"
(defkeyword
((if (> (length (car sentence)) 0)
(equal (char (car sentence) 0) #\!)))
((setf (car sentence) (string-left-trim *command-prefix-character*
(car sentence)))
(when (gethash (car sentence) *commands*)
(funcall (gethash (car sentence) *commands*) from where (cdr sentence)))))
;;bot commands
(defparameter *commands* (make-hash-table :test 'equal))
(defun register-command (command action)
(setf (gethash command *commands*) action))
(defmacro defcommand (command-name (&key (min-level 0)
(help-msg 'nil))
&body action)
`(progn ,(when (not (null help-msg))
`(defhelpmsg ,command-name
(say where ,help-msg)))
(register-command
,command-name
(lambda (from where command-args)
(if (allowed-user from ,min-level)
(progn (format t "Running action ~A for user ~A~%"
,command-name from)
(format t "Command arguments: ~A~%" command-args)
,@action)
(say from "You're not allowed to do this !!!"))))))