[project @ 2002-07-12 03:27:05 by unknown_lamer]
[clinton/bobotpp.git] / scripts / bobot-utils.scm
CommitLineData
cb21075d 1;;; this is a library of stuff that bobot++ scripts would probably
ad529fde 2;;; want to use. This file is autoloaded by bobot++
cb21075d 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
439869bf 11;;; Bot load (loads a file from %bot:loadpath)
ad529fde 12
439869bf 13(define %bot:loadpath (list
ad529fde 14 (string-append (getenv "HOME")
439869bf 15 "/.bobotpp/scripts/")
16 bot:sys-scripts-dir))
ad529fde 17
439869bf 18(define (bot:load file)
19 (let loop ((load-path %bot:loadpath))
ad529fde 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)))
439869bf 30 (begin (bot:log "ERROR: File " file " Not Found!\n") #f))))
ad529fde 31
cb21075d 32;;; REGEX UTILS
33
34;;; match-not-channel adds a prefix regex to your regex so it doesn't
35;;; match the sender or channel in a PUBLIC message
36(define (match-not-channel regex)
439869bf 37 (string-append "^[[:graph:]]* [&#+!][^ ,\a]+ [[:graph:][:space:]]*" regex))
cb21075d 38
39;;; match-to-me matches text that was addressed to the bot with a
40;;; ':',',', or nothing after the bot name
41(define (match-to-me regex)
439869bf 42 (string-append (match-not-channel (bot:getnickname))
cb21075d 43 "[:,]*[[:space:][:graph:]]*" regex))
44
45
46;;;; string-utils
47(define str-app string-append) ; shorter
48
49
50;;;; Misc UTILS
51
52;;; bot-log: Write as many messages as you want to the log. If the
ad529fde 53;;; arg is a thunk it will be executed and it's output will be
cb21075d 54;;; written to the log
439869bf 55(define (bot:log . messages)
cb21075d 56 (map
57 (lambda (x)
ad529fde 58 (if (thunk? x)
cb21075d 59 (display (x) (bot-logport))
60 (display x (bot-logport))))
61 messages )
439869bf 62 (bot:flushport))
63
64;;; DEPRECATED FUNCTION NAMED
65;;; These are provided for backwards compatibility
66;;; and will be removed in the 2.3 dev tree
67
68(define bot-load bot:load)
69(define bot-action bot:action)
70(define bot-adduser bot:adduser)
71(define bot-addserver bot:addserver)
72(define bot-addshit bot:addshit)
73(define bot-ban bot:ban)
74(define bot-cycle bot:cycle)
75(define bot-deban bot:deban)
76(define bot-delserver bot:delserver)
77(define bot-deluser bot:deluser)
78(define bot-delshit bot:delshit)
79(define bot-deop bot:deop)
80(define bot-die bot:die)
81(define bot-do bot:do)
82(define bot-invite bot:invite)
83(define bot-join bot:join)
84(define bot-keep bot:keep)
85(define bot-kick bot:kick)
86(define bot-kickban bot:kickban)
87(define bot-lock bot:lock)
88(define bot-logport bot:logport)
89(define bot-mode bot:mode)
90(define bot-msg bot:msg)
91(define bot-nextserver bot:nextserver)
92(define bot-nick bot:nick)
93(define bot-op bot:op)
94(define bot-part bot:part)
95(define bot-reconnect bot:reconnect)
96(define bot-say bot:say)
97(define bot-server bot:server)
98(define bot-setversion bot:setversion)
99(define bot-tban bot:tban)
100(define bot-tkban bot:tkban)
101(define bot-topic bot:topic)
102(define bot-unlock bot:unlock)
103(define bot-getnickname bot:getnickname)
104(define bot-getserver bot:getserver)
105(define bot-getserverlist bot:getserverlist)
106(define bot-flush bot:flush)
107(define bot-flushport bot:flushport)
108(define bot-random bot:random)
109(define bot-addcommand bot:addcommand)
110(define bot-delcommand bot:delcommand)
111(define bot-addhook bot:addhook)
112(define bot-addtimer bot:addtimer)
113(define bot-deltimer bot:deltimer)