89cd34b12a2759ca1af566ce40d7fbc6569d4505
[clinton/bobotpp.git] / scripts / bobot-utils.scm
1 ;;; this is a library of stuff that bobot++ scripts would probably
2 ;;; want to use. This file is autoloaded by bobot++
3
4 ;;; This file is covered by the GPL version 2 or (at your option) any
5 ;;; later version
6
7 ;;; Why the GPL? Technically anything that uses Bobot++'s functions
8 ;;; must be GPLed, so all of your scripts have to be GPLed anyway
9 ;;; because you are really linking with Bobot++, a GPLed program!
10
11 ;;; Bot load (loads a file from %bot-loadpath)
12
13 (define %bot-loadpath (list
14 (string-append (getenv "HOME")
15 "/.bobotpp/scripts")
16 bot-sys-scripts-dir))
17
18 (define (bot-load file)
19 (let loop ((load-path %bot-loadpath))
20 (if (not (null? load-path))
21 (if (catch 'system-error
22 (lambda ()
23 (load
24 (string-append (car load-path)
25 file)))
26 (lambda args
27 #f ))
28 #t
29 (loop (cdr load-path)))
30 #f )))
31
32
33 ;;; REGEX UTILS
34
35 ;;; match-not-channel adds a prefix regex to your regex so it doesn't
36 ;;; match the sender or channel in a PUBLIC message
37 (define (match-not-channel regex)
38 (string-append "[[:graph:]]* [&#+!][^ ,\a]+ [[:graph:][:space:]]*" regex))
39
40 ;;; match-to-me matches text that was addressed to the bot with a
41 ;;; ':',',', or nothing after the bot name
42 (define (match-to-me regex)
43 (string-append (match-not-channel (bot-getnickname))
44 "[:,]*[[:space:][:graph:]]*" regex))
45
46
47 ;;;; string-utils
48 (define str-app string-append) ; shorter
49
50
51 ;;;; Misc UTILS
52
53 ;;; bot-log: Write as many messages as you want to the log. If the
54 ;;; arg is a thunk it will be executed and it's output will be
55 ;;; written to the log
56 (define (bot-log . messages)
57 (map
58 (lambda (x)
59 (if (thunk? x)
60 (display (x) (bot-logport))
61 (display x (bot-logport))))
62 messages )
63 (bot-flushport))