1 ;;; This file is automatically loaded by Bobot++. This is required for
2 ;;; the bot to function.
4 ;;; This file is covered by the GPL version 2 or (at your option) any
7 ;;; the-bot-module must be available to guile-user so that scripts
8 ;;; loaded with Interp::Load have access to the bot: procedures
9 (module-use! (resolve-module '(guile-user) #f)
12 (use-modules (srfi srfi-1)
15 (define-public %bot:loadpath (list
16 (string-append (getenv "HOME")
20 (define-public %bot:load-extensions %load-extensions)
22 ;;; bot:log: Write as many messages as you want to the log. If the
23 ;;; arg is a thunk it will be executed and it's output will be
24 ;;; written to the log
25 (define-public (bot:log . messages)
29 (display (x) (bot:logport))
30 (display x (bot:logport))))
34 (define-public (bot:load file)
35 (let path-loop ((load-path %bot:loadpath))
36 (cond ((not (null? load-path))
38 (let ext-loop ((extensions %bot:load-extensions))
39 (cond ((not (null? extensions))
40 (if (catch 'system-error
43 (string-append (car load-path)
50 (ext-loop (cdr extensions))))
52 (path-loop (cdr load-path))))
54 (begin (bot:log "ERROR: File " file " Not Found!\n") #f)))))
56 (define-public (bot:load-module module-spec)
64 (map (lambda (str) (string-append "/" str)) rest))))
65 (map symbol->string module))))
68 (old-module (current-module)))
69 (module-use! new-module the-bot-module)
70 (set-current-module new-module)
71 (bot:load (module->string module-spec))
72 (set-current-module old-module)
75 (define-public (bot:use-module module-spec)
76 (module-use! (current-module)
77 (bot:load-module module-spec)))
82 ;;; match-not-channel adds a prefix regex to your regex so it doesn't
83 ;;; match the sender or channel in a PUBLIC message
84 (define-public (bot:match-not-channel regex)
85 (string-append "^[[:graph:]]*[&#+!][^ ,\a]+ [[:graph:][:space:]]*"
88 ;;; match-to-me matches text that was addressed to the bot with a
89 ;;; ':',',', or nothing after the bot name
91 ;(define-public (bot:match-to-me r) r)
92 (define-public (bot:match-to-me regex)
93 (string-append (bot:match-not-channel (bot:getnickname))
94 "[[:space:][:graph:]]*" regex))
96 (define-public (bot:sent-to-me? message)
97 (let ((to-me (make-regexp (bot:match-to-me ""))))
98 (if (regexp-exec to-me message) #t #f)))
101 (define-public str-app string-append) ; shorter
103 ;;; Message sending utils
105 ;;; Returns the CTCP quoted message
106 ;;; Input _MUST NOT_ contain the trailing \r\n
107 ;;; (it is added by the message sending code)
108 (define-public (bot:ctcp-quote message)
109 ;; TODO: Not very efficient, it may be worth reimplementing
110 (let ((ls (string->list message)))
112 (map (lambda (chr) ; CTCP level quoting
113 (case (char->integer chr)
114 ((#o134) (string (integer->char #o134) (integer->char
116 ((#o01) (string (integer->char #o134) #\a)) ; X-DELIM
117 (else (string chr))))
120 (map (lambda (chr) ; Low-level
121 (let ((m-quote (integer->char #o20)))
123 ((m-quote) (string m-quote m-quote))
124 ((#\nul) (string m-quote #\0))
125 ((#\nl) (string m-quote #\n))
126 ((#\cr) (string m-quote #\r))
127 (else (string chr)))))
130 ;;; bot:channel-users user object accessors
131 (define-public (bot:channel-user-nick cu)
134 (define-public (bot:channel-user-user/host cu)
137 (define-public (bot:channel-user-mode cu)
140 (define-public (bot:channel-user-has-modes? cu . modes)
141 (let ((mode (apply logior modes)))
142 (= (logand (bot:channel-user-mode cu)) mode mode)))
144 (define-public (bot:channel-user-op? cu)
145 (bot:channel-user-has-modes? cu bot:mode/op))
147 (define-public (bot:channel-user-voice? cu)
148 (bot:channel-user-has-modes? cu bot:mode/voice))
150 (define-public (bot:channel-user-away? cu)
151 (bot:channel-user-has-modes? cu bot:mode/away))
153 (define-public (bot:channel-user-ircop? cu)
154 (bot:channel-user-has-modes? cu bot:mode/op))
156 ;;; DEPRECATED FUNCTION NAMES
157 ;;; These are provided for backwards compatibility
158 ;;; and will be removed in the 3.0 release
161 (define-macro (_deprecated-fun old-name new-name)
162 `(define-public ,old-name
165 (set-current-error-port (bot:logport))))
166 (issue-deprecation-warning
168 (symbol->string ',old-name)
169 " is a deprecated function. Please use "
170 (symbol->string ',new-name) " instead."))
172 (set-current-error-port old-error))
173 (apply ,new-name args))))
175 (_deprecated-fun bot-load bot:load)
176 (_deprecated-fun bot-action bot:action)
177 (_deprecated-fun bot-adduser bot:adduser)
178 (_deprecated-fun bot-addserver bot:addserver)
179 (_deprecated-fun bot-addshit bot:addshit)
180 (_deprecated-fun bot-ban bot:ban)
181 (_deprecated-fun bot-cycle bot:cycle)
182 (_deprecated-fun bot-deban bot:deban)
183 (_deprecated-fun bot-delserver bot:delserver)
184 (_deprecated-fun bot-deluser bot:deluser)
185 (_deprecated-fun bot-delshit bot:delshit)
186 (_deprecated-fun bot-deop bot:deop)
187 (_deprecated-fun bot-die bot:die)
188 (_deprecated-fun bot-do bot:do)
189 (_deprecated-fun bot-invite bot:invite)
190 (_deprecated-fun bot-join bot:join)
191 (_deprecated-fun bot-keep bot:keep)
192 (_deprecated-fun bot-kick bot:kick)
193 (_deprecated-fun bot-kickban bot:kickban)
194 (_deprecated-fun bot-lock bot:lock)
195 (_deprecated-fun bot-logport bot:logport)
196 (_deprecated-fun bot-mode bot:mode)
197 (_deprecated-fun bot-msg bot:msg)
198 (_deprecated-fun bot-nextserver bot:nextserver)
199 (_deprecated-fun bot-nick bot:nick)
200 (_deprecated-fun bot-op bot:op)
201 (_deprecated-fun bot-part bot:part)
202 (_deprecated-fun bot-reconnect bot:reconnect)
203 (_deprecated-fun bot-say bot:say)
204 (_deprecated-fun bot-server bot:server)
205 (_deprecated-fun bot-setversion bot:setversion)
206 (_deprecated-fun bot-tban bot:tban)
207 (_deprecated-fun bot-tkban bot:tkban)
208 (_deprecated-fun bot-topic bot:topic)
209 (_deprecated-fun bot-unlock bot:unlock)
210 (_deprecated-fun bot-getnickname bot:getnickname)
211 (_deprecated-fun bot-getserver bot:getserver)
212 (_deprecated-fun bot-getserverlist bot:getserverlist)
213 (_deprecated-fun bot-flush bot:flush)
214 (_deprecated-fun bot-flushport bot:flushport)
215 (_deprecated-fun bot-random bot:random)
216 (_deprecated-fun bot-addcommand bot:addcommand)
217 (_deprecated-fun bot-delcommand bot:delcommand)
218 (_deprecated-fun bot-addhook bot:addhook)
219 (_deprecated-fun bot-addtimer bot:addtimer)
220 (_deprecated-fun bot-deltimer bot:deltimer)
222 (define-public hooks/leave hooks/part))