[project @ 2002-07-09 14:28:08 by unknown_lamer]
[clinton/bobotpp.git] / scripts / stupid_stuff / stupid_stuff
1 ;;; -*- guile-scheme -*-
2 ;;; this shows off some interesting things...(based on boulet)
3 ;;; This is unknown_lamer's bot DumbBot
4
5 ;;; To use this run:
6 ;;; sh sayings.sh
7 ;;; cat sayings | guile -s insert_saying.scm
8 ;;; Then load this file.
9 ;;; To add a new saying to the bot db just run insert_saying.scm
10
11 ;;; yes, this uses a sql db!
12 (use-modules (database simplesql)
13 (ice-9 debug))
14 (load "../bobot-utils.scm")
15
16 ;;; Activate or desactivate the bot
17 (define talk 1)
18
19 (define (shutup)
20 (set! talk 0))
21 (bot-addcommand "shutup" shutup #f 0 2)
22
23 (define (dotalk)
24 (set! talk 1))
25 (bot-addcommand "talk" dotalk #f 0 2)
26
27
28 ;;; Miscellaneous list functions
29 (define (removeChannel c l)
30 (if (null? l)
31 (list)
32 (let ((deb (car l)))
33 (if (string-ci=? c (car deb))
34 (cdr l)
35 (append (list deb) (removeChannel c (cdr l)))))))
36
37 (define (changeChannel c n l)
38 (if (null? l)
39 (list)
40 (let ((deb (car l)))
41 (if (string-ci=? c (car deb))
42 (append (list (list c n)) (cdr l))
43 (append (list deb) (changeChannel c n (cdr l)))))))
44
45 (define (addChannel c n l)
46 (append l (list (list c n))))
47
48 ;;; When someone joins a channel
49 (define dumbTimer (list))
50 (define (joinLourd n c)
51 (if (string-ci=? n (bot-getnickname))
52 (begin
53 (if (= 1 talk) (bot-say c "I like limos"))
54 (set! dumbTimer
55 (addChannel c (bot-addtimer (+ 600 (bot-random 300))
56 (dumbLourd c)) dumbTimer)))
57 (if (= 1 talk) (bot-say c (string-append "Arf Moo Arf! " n
58 " I like pizza...")))))
59 (bot-addhook hooks/join ".*" joinLourd)
60
61 ;;; When someone leaves the channel
62 (define (partLourd n c)
63 (bot-flushport)
64 (if (not (string-ci=? n (bot-getnickname)))
65 (if (= 1 talk) (bot-msg n "I HATED YOU ANYWAY"))
66 (let* ((timer (assoc c dumbTimer)))
67 (bot-deltimer (cadr timer))
68 (set! dumbTimer (removeChannel c dumbTimer)))))
69 (bot-addhook hooks/part ".*" partLourd)
70
71 ;;; Random action to say something dumb
72 (define (dumbLourd c)
73 (lambda ()
74 (if (= 1 talk)
75 (bot-say
76 c
77 (vector-ref (list-ref dumbList (bot-random (length dumbList))) 0)))
78 (set! dumbTimer
79 (changeChannel
80 c
81 (bot-addtimer (+ 600 (bot-random 300)) (dumbLourd c)) dumbTimer))))
82
83
84 (define dumbDB (simplesql-open 'postgresql "bot_sayings"))
85 ;(define dumbList #f)
86 ; (define (reload-sayings)
87 ; (set! dumbList (cdr (simplesql-query dumbDB "SELECT saying FROM sayings")))
88 ; (display "Reloaded sayings from db\n" (bot-logport))
89 ; (bot-flushport))
90 ; (bot-addcommand "reloadsayings" reload-sayings #f 0 4)
91 ; (reload-sayings)
92
93 (define (_length db)
94 (let ((length (+ 1
95 (vector-ref
96 (list-ref (cdr
97 (simplesql-query
98 db
99 "SELECT count(saying) FROM sayings")) 0) 0))))
100 length ))
101
102 (define (_select db entry)
103 (list-ref
104 (cdr
105 (simplesql-query db
106 (str-app "SELECT saying FROM sayings "
107 "WHERE id = "
108 (number->string entry)))) 0))
109
110
111
112
113 (define (random-saying)
114 (vector-ref (_select dumbDB (bot-random (_length dumbDB))) 0))
115
116 ;;; Misc
117 ;;; note that public hooks match the channel name too!
118 ;;; match-not-channel prevents this
119
120 ;;; this should be the first so it doesn't clobber the other hooks
121 (bot-addhook
122 hooks/public (match-to-me "")
123 (lambda (f t p)
124 (if (= 1 talk)
125 (bot-say t
126 (string-append f ": " (random-saying))))) -50 #f)
127
128
129 (bot-addhook hooks/public (match-not-channel "oracle")
130 (lambda (f t p)
131 (if (= 1 talk)
132 (bot-say t "Oracle is evil! Use Postgres instead!"))))
133
134 (define (add-gnu word)
135 (bot-addhook hooks/public (match-not-channel word)
136 (lambda (f t p)
137 (if (= 1 talk)
138 (bot-say t
139 (string-append f ": I hope you meant GNU!"))))))
140 (map add-gnu '("[^/g]linux" "microsoft" "bsd"))
141
142 (bot-addhook hooks/public (match-not-channel "boulet")
143 (lambda (f t p)
144 (if (= 1 talk) (bot-say t "on parle de moi ?"))))
145
146 (bot-addhook hooks/public (match-not-channel "arf")
147 (lambda (f t p)
148 (if (= 1 talk)
149 (bot-say t (random-saying)))))
150
151 (bot-addhook hooks/public (match-not-channel "csn")
152 (lambda (f t p)
153 (if (= 1 talk) (bot-say t "???"))))
154
155 (bot-addhook hooks/public (match-not-channel "pizza|pasta|soda")
156 (lambda (f t p)
157 (if (= 1 talk)
158 (bot-say t (string-append f ": give me one too!")))))
159
160 (define (add-foul word)
161 (bot-addhook hooks/public (match-not-channel word)
162 (lambda (f t p)
163 (if (= 1 talk)
164 (bot-action
165 t (string-append "hits " f
166 " for having a potty mouth"))))))
167 (map add-foul '("bitch" "fuck" "whore" "cunt" "tit" "shit" "dick" "cock"))
168
169 (bot-addhook hooks/public (match-not-channel "anal sex")
170 (lambda (f t p)
171 (if (= 1 talk)
172 (if (not (string-match "unknown_lamer" f))
173 (bot-action
174 t (string-append "grabs " f
175 " and buggers " f " up the ass"))))))
176
177 (bot-addhook
178 hooks/public (match-not-channel "[[:space:]]*lame[[:space:]]+")
179 (lambda (f t p)
180 (if (= 1 talk)
181 (bot-say t
182 (string-append f ": NO NO YOU ARE THE LAMER")))))
183
184 (bot-addhook hooks/public (match-to-me "burn")
185 (lambda (f t p)
186 (if (= 1 talk)
187 (bot-say
188 t
189 (string-append "How about you burn " f "?")))))
190
191
192 ;;; 9h00, on arrive au boulot
193 ;(define (newDay l)
194 ; (if (not (null? l))
195 ; (begin
196 ; (bot-say (caar l) "What is up my homey g-d0g?")
197 ; (newDay (cdr l))
198 ; )
199 ; )
200 ;)
201
202 ;(bot-addhook hooks/timer "09:00" (lambda (h) (newDay dumbTimer) (talk)))
203
204 ;;; 18h00, il est temps de rentrer
205 ;(define (timeToGo l)
206 ; (if (not (null? l))
207 ; (begin
208 ; (bot-say (caar l) "Give me food")
209 ; (bot-action (caar l) "I'm bored")
210 ; (timeToGo (cdr l))
211 ; )
212 ; )
213 ;)
214 ;(bot-addhook hooks/timer "18:00" (lambda (h) (timeToGo dumbTimer) (shutup)))