(module-use! (resolve-module '(guile-user) #f)
the-bot-module)
-(use-modules (srfi srfi-13))
+(use-modules (srfi srfi-1)
+ (srfi srfi-13))
-(define-public %bot:loadpath (list
- (string-append (getenv "HOME")
- "/.bobotpp/scripts/")
- bot:sys-scripts-dir))
-
-(define-public %bot:load-extensions %load-extensions)
+(eval-when (compile load eval)
+ (set! %load-path (cons* (string-append (getenv "HOME") "/.bobotpp/scripts/")
+ bot:sys-scripts-dir
+ %load-path)))
;;; bot:log: Write as many messages as you want to the log. If the
;;; arg is a thunk it will be executed and it's output will be
messages)
(bot:flushport))
-(define-public (bot:load file)
- (let path-loop ((load-path %bot:loadpath))
- (cond ((not (null? load-path))
- (if (not
- (let ext-loop ((extensions %bot:load-extensions))
- (if (not (null? extensions))
- (if (catch 'system-error
- (lambda ()
- (load
- (string-append (car load-path)
- file
- (car extensions))))
- (lambda args
- #f ))
- #t
- (ext-loop (cdr extensions))))))
- (path-loop (cdr load-path))))
- (else
- (begin (bot:log "ERROR: File " file " Not Found!\n") #f)))))
+(define-public bot:load load-from-path)
+
+(define (module->string module)
+ (apply (lambda (s . rest)
+ (string-append
+ s
+ (apply string-append
+ (map (lambda (str) (string-append "/" str)) rest))))
+ (map symbol->string module)))
(define-public (bot:load-module module-spec)
- (let ((module->string
- (lambda (module)
- (apply
- (lambda (s . rest)
- (string-append
- s
- (apply string-append
- (map (lambda (str) (string-append "/" str)) rest))))
- (map symbol->string module))))
- (new-module
- (make-module))
+ (let ((new-module (make-module 31 (list the-bot-module)))
(old-module (current-module)))
(module-use! new-module the-bot-module)
(set-current-module new-module)
(module-use! (current-module)
(bot:load-module module-spec)))
-
;;; REGEX UTILS
;;; match-not-channel adds a prefix regex to your regex so it doesn't
;;; match the sender or channel in a PUBLIC message
(define-public (bot:match-not-channel regex)
- (string-append "^[[:graph:]]* [&#+!][^ ,\a]+ [[:graph:][:space:]]*"
+ (string-append "^[[:graph:]]*[&#+!][^ ,\a]+ [[:graph:][:space:]]*"
regex))
;;; match-to-me matches text that was addressed to the bot with a
;;; ':',',', or nothing after the bot name
+
(define-public (bot:match-to-me regex)
(string-append (bot:match-not-channel (bot:getnickname))
"[[:space:][:graph:]]*" regex))
-(define-public bot:sent-to-me?
+(define-public (bot:sent-to-me? message)
(let ((to-me (make-regexp (bot:match-to-me ""))))
- (lambda (message)
- (if (regexp-exec to-me message) #t #f))))
+ (if (regexp-exec to-me message) #t #f)))
;;;; string-utils
(define-public str-app string-append) ; shorter
((#\cr) (string m-quote #\r))
(else (string chr)))))
ls)))))))
+
+;;; bot:channel-users user object accessors
+(define-public (bot:channel-user-nick cu)
+ (first cu))
+
+(define-public (bot:channel-user-user/host cu)
+ (second cu))
+
+(define-public (bot:channel-user-mode cu)
+ (third cu))
+
+(define-public (bot:channel-user-has-modes? cu . modes)
+ (let ((mode (apply logior modes)))
+ (= (logand (bot:channel-user-mode cu)) mode mode)))
+
+(define-public (bot:channel-user-op? cu)
+ (bot:channel-user-has-modes? cu bot:mode/op))
+
+(define-public (bot:channel-user-voice? cu)
+ (bot:channel-user-has-modes? cu bot:mode/voice))
+
+(define-public (bot:channel-user-away? cu)
+ (bot:channel-user-has-modes? cu bot:mode/away))
-
+(define-public (bot:channel-user-ircop? cu)
+ (bot:channel-user-has-modes? cu bot:mode/op))
;;; DEPRECATED FUNCTION NAMES
;;; These are provided for backwards compatibility