~alanbell/mootbot/moin

1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
1
#########
2
#
3
# MootBot - Core Module
4
# Copyright 2006,2007 Christopher Oattes, Andrew Williams
5
#
6
#########
7
#
8
#########
9
#
10
#    This program is free software; you can redistribute it and/or modify
11
#    it under the terms of the GNU Lesser General Public License as published by
12
#    the Free Software Foundation; either version 2.1 of the License, or
13
#    (at your option) any later version.
14
#
15
#    This program is distributed in the hope that it will be useful,
16
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
#    GNU Lesser General Public License for more details.
19
#
20
#    You should have received a copy of the GNU Lesser General Public License
21
#    along with this program; if not, write to the Free Software
22
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23
#
24
#########
25
26
################################################################################
27
# DO NOT EDIT DO NOT EDIT DO NOT EDIT  DO NOT EDIT DO NOT EDIT DO NOT EDIT     #
28
#                         EDIT MOOTBOT_CONFIG.TCL			       #
29
################################################################################
30
31
# Load the config file
32
source scripts/mootbot_config.tcl
33
34
# Load required files
35
source scripts/mootbot_template.tcl
36
source scripts/mootbot_chan.tcl
37
source scripts/mootbot_vote.tcl
38
39
# Version Information
40
set mootbot_core_version 16
41
42
# Meeting Details
43
array set aInProgress {}
44
array set aChair {}
4 by andrewwilliams
Added a "topic" command for privmsg, telling the user the current topic. Also changed #endvote to
45
array set aChanTopic {}
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
46
47
# Files & Logging Info
48
array set aMinutesFile {}
49
array set aChanLog {}
9 by Alan Bell
added moin syntax log output
50
array set aMoinLog {}
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
51
array set aChanLogName {}
52
array set aAnchorCount {}
53
array set aPresent {}
9 by Alan Bell
added moin syntax log output
54
array set aActions {}
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
55
4 by andrewwilliams
Added a "topic" command for privmsg, telling the user the current topic. Also changed #endvote to
56
# Public Channel Command Bindings
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
57
bind pub - "#startmeeting"  pub:startmeeting
58
bind pub - "#endmeeting"  pub:endmeeting
59
bind pubm - "% \[IDEA\]*" pubm:idea
60
bind pubm - "% \[ACTION\]*" pubm:action
61
bind pubm - "% \[TOPIC\]*" pubm:topic
9 by Alan Bell
added moin syntax log output
62
bind pubm - "% \[PROGRESS REPORT\]*" pubm:progress
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
63
bind pubm - "% \[AGREED\]*" pubm:agreed
64
bind pubm - "% \[LINK\]*" pubm:link
65
bind pubm - * pubm:log
66
bind ctcp - "ACTION" ctcp:log
67
4 by andrewwilliams
Added a "topic" command for privmsg, telling the user the current topic. Also changed #endvote to
68
# Privmsg Command Bindings
69
bind msg - "help" msg:help
70
bind msg - "topic" msg:topic
71
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
72
# Add nick onto the present list
73
proc addPresent {chan nick} {
74
	global aPresent
75
76
	foreach person $aPresent($chan) {
77
		if { [string equal $nick $person] } {
78
			return
79
		}
80
	} 
81
		
82
	# Not in the present list, add them in
83
	lappend aPresent($chan) $nick
84
}
85
9 by Alan Bell
added moin syntax log output
86
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
87
#Checks if a meting is in progress. If it is, return true, else return false.
88
proc meetingInProgress {chan} {
89
	global aInProgress
90
91
	if {[info exists aInProgress($chan)]} { 
92
           return $aInProgress($chan)
93
        } else {
94
           return false
95
        }
96
}
97
98
# Outputs the IDEA, AGREED and ACTION tags
99
#   - Type, Originating Nick, Channel, Text to output, Text to display
100
proc outputTag {type nick chan text display} {
101
	global aChair aChanLogName aAnchorCount VerboseCommands AddToBotLog
102
103
	#Output to channel and PM
104
        if {$VerboseCommands} {
105
		putquick "PRIVMSG $chan :$type received: $display "
106
		putquick "PRIVMSG $aChair($chan) :$type received: $display"
107
	}
108
109
	if {$AddToBotLog} {
110
		putlog "$chan issued $type command"
111
	}
112
113
	#Output to summary
114
	logWrite 2 $chan "<tr>\n\t"
115
	logWrite 2 $chan "<td><a href='$aChanLogName($chan)#$aAnchorCount($chan)'>[clock format [clock seconds] -format %H:%M:%S]</a></td>"
116
	logWrite 2 $chan "<td>$type</td>\n<td>$nick</td>\n<td>$text</td>\n</tr>"
117
9 by Alan Bell
added moin syntax log output
118
	logWrite 3 $chan "||<#FF5555>''$display''||\n"
119
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
120
	#Output anchor link to text log.
121
	logWrite 1 $chan "<a name='$aAnchorCount($chan)'></a>"
122
	set aAnchorCount($chan) [expr $aAnchorCount($chan) + 1]
123
}
124
4 by andrewwilliams
Added a "topic" command for privmsg, telling the user the current topic. Also changed #endvote to
125
######### Public Message Functions
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
126
127
#Function to log /me actions
128
proc ctcp:log {nick host hand dest keyword text} {
129
	#First, ensure message was sent to channel, not the bot
130
	if {[string index $dest 0] != "#"} {
131
		return 0
132
	}
133
	global aChanLog
134
	#Only if a meeting is progress
135
	if {[meetingInProgress $dest]} {
3 by andrewwilliams
Fixed logging of actions, refered to a non existant variable
136
		logWrite 1 $dest "\[[clock format [clock seconds] -format %H:%M:%S]\] * $nick $text<br />"
11 by Alan Bell
error handling when there are no actions raised in the meeting
137
        	logWrite 3 $dest " * '''<<Verbatim($nick)>>''' $text\n"
9 by Alan Bell
added moin syntax log output
138
3 by andrewwilliams
Fixed logging of actions, refered to a non existant variable
139
		addPresent $dest $nick
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
140
	}
141
}
142
	
143
144
#Function to log all channel text
145
proc pubm:log {nick host hand chan text} {
146
	global aChanLog aPresent ScrapeURLs
147
	if {[meetingInProgress $chan]} {
148
149
		if {$ScrapeURLs && ![string compare [string range $text 0 [expr [string first ":" $text] - 1]] "http"]} {
150
			pubm:link $nick $host $hand $chan "\[LINK\] $text"
151
		}	
152
153
		logWrite 1 $chan "\[[clock format [clock seconds] -format %H:%M:%S]\] &lt;$nick\&gt; $text<br />"
11 by Alan Bell
error handling when there are no actions raised in the meeting
154
		logWrite 3 $chan " <'''<<Verbatim($nick)>>'''> $text\n"
10 by Alan Bell
added formatted vote functionality
155
                #the verbatim macro is to avoid link overload on CamelCase nicks
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
156
		addPresent $chan $nick
157
	}
158
}
159
160
#Starts a meeting. Assigns person that issued the command as chair.
161
proc pub:startmeeting {nick host hand chan text} {
9 by Alan Bell
added moin syntax log output
162
	global aInProgress aChair aMinutesFile aChanLog aPresent aMoinLog
4 by andrewwilliams
Added a "topic" command for privmsg, telling the user the current topic. Also changed #endvote to
163
        global aChanLogName aAnchorCount outputPath aChanTopic
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
164
165
	if {![meetingInProgress $chan]} {
166
		set datetimeprefix [clock format [clock seconds] -format %Y%m%d_%H%M]
2 by andrewwilliams
Fixed issue with channel name being outputted as raw (e.g. #mootbot), this stopped the anchors in
167
		set channame  [string range $chan 1 end]
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
168
2 by andrewwilliams
Fixed issue with channel name being outputted as raw (e.g. #mootbot), this stopped the anchors in
169
		set aMinutesFile($chan) [open [file join $outputPath $channame.$datetimeprefix.html] "w"]
9 by Alan Bell
added moin syntax log output
170
		set aMoinLog($chan) [open [file join $outputPath $channame.moin.$datetimeprefix.txt] "w"]
2 by andrewwilliams
Fixed issue with channel name being outputted as raw (e.g. #mootbot), this stopped the anchors in
171
		set aChanLog($chan) [open [file join $outputPath $channame.log.$datetimeprefix.html]  "w"]
172
		set aChanLogName($chan) $channame.log.$datetimeprefix.html		
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
173
174
		logWrite 1 $chan "Started logging meeting in $chan<br />"
175
		#Initialise variables for that channel
176
		set aInProgress($chan) true
177
		set aChair($chan) $nick
178
		set aAnchorCount($chan) 0
179
		set aPresent($chan) {}
4 by andrewwilliams
Added a "topic" command for privmsg, telling the user the current topic. Also changed #endvote to
180
                set aChanTopic($chan) ""
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
181
182
		cleanVoting $chan
183
184
		set start_time [clock format [clock seconds] -format %H:%M]
185
186
		#Output to channel and PM chair
187
		putquick "PRIVMSG $chan :Meeting started at $start_time. The chair is $aChair($chan)."
9 by Alan Bell
added moin syntax log output
188
		putquick "PRIVMSG $chan :Commands Available: \[TOPIC\], \[PROGRESS REPORT\], \[IDEA\], \[ACTION\], \[AGREED\], \[LINK\], \[VOTE\]"
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
189
		putquick "PRIVMSG $aChair($chan) :Meeting started at $start_time. The chair is $aChair($chan)." 
190
191
		#Write to log file
192
		logWrite 2 $chan "<html>\n<body>\nMeeting started by $aChair($chan) at $start_time\n<table border=1>"
9 by Alan Bell
added moin syntax log output
193
                logWrite 3 $chan "||<tablestyle=\"float:right; font-size: 0.9em; width:40%; background:#F1F1ED; margin: 0 0 1em 1em;\" style=\"padding:0.5em;\"><<TableOfContents>>||"
194
		logWrite 3 $chan "= Meeting opened by $aChair($chan) at $start_time ="
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
195
	} else {
9 by Alan Bell
added moin syntax log output
196
		putquick "PRIVMSG $chan :$nick, There is already a meeting in progress - chair is $aChair($chan)."
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
197
	}
198
}
199
200
#Ends the meeting. Can only be used by chair.
201
proc pub:endmeeting {nick host hand chan text} {
9 by Alan Bell
added moin syntax log output
202
	global aInProgress aChair aMinutesFile aChanLog aChanLogName aMoinLog
203
        global aAnchorCount aPresent LeaveChannelAfter aChanTopic aActions
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
204
205
	#Check meeting is currently in progress, and that user is chair.
206
	if {[meetingInProgress $chan] && [string equal $nick $aChair($chan)]} {
207
		if {[isVoting $chan]} {
208
			putquick "PRIVMSG $chan :Vote is in progress. Finishing now."
209
			pub:endvote $nick $host $hand $chan $text
210
		}
211
212
		set chair "None"
213
214
		putquick "PRIVMSG $chan :Meeting finished at [clock format [clock seconds] -format %H:%M]." 
215
		putquick "PRIVMSG $aChair($chan) :Meeting finished at [clock format [clock seconds] -format %H:%M]." 
13 by Alan Bell
log location updated
216
		putquick "PRIVMSG $aChair($chan) :Logs available at http://mootbot.ubuntu-uk.org/"
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
217
		
218
		if {$LeaveChannelAfter} {
219
			killChannel $chan
220
		}
221
	
222
		logWrite 2 $chan "</table>\nMeeting ended at [clock format [clock seconds] -format %H:%M].\n"
223
		logWrite 2 $chan "<br/>\n<br/>\nPeople Present:<br/>\n<ol>"
224
9 by Alan Bell
added moin syntax log output
225
                logWrite 3 $chan "----"
226
		logWrite 3 $chan "= Meeting closed at [clock format [clock seconds] -format %H:%M] ="
227
		logWrite 3 $chan "== People Present =="
228
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
229
		foreach person $aPresent($chan) {
230
			logWrite 2 $chan "<li>$person</li>\n"
9 by Alan Bell
added moin syntax log output
231
			logWrite 3 $chan " * $person\n"
232
		} 
233
		logWrite 3 $chan "== Actions Recorded =="
11 by Alan Bell
error handling when there are no actions raised in the meeting
234
                #note the lack of a $ on the aActions in the exists syntax
235
                if {[info exists aActions($chan)]} {
236
	                foreach action $aActions($chan) {
237
		                logWrite 3 $chan " * $action\n"
238
	                } 
239
                } else {
240
                        logWrite 3 $chan " None\n"
241
                }
9 by Alan Bell
added moin syntax log output
242
11 by Alan Bell
error handling when there are no actions raised in the meeting
243
                #clear up ready for the next meeting
244
                set aActions($chan) {}
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
245
		set aPresent($chan) {}
246
247
		logWrite 2 $chan "</body></html>"
248
		close $aMinutesFile($chan)
249
250
		logWrite 1 $chan "Meeting ended.<br />"
251
		close $aChanLog($chan)
252
9 by Alan Bell
added moin syntax log output
253
                close $aMoinLog($chan)
254
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
255
		#Write changes to variables
256
		set aInProgress($chan) false
257
		set aChair($chan) ""
258
		set aChanLog($chan) {}
259
		set aChanLogName($chan) {}
4 by andrewwilliams
Added a "topic" command for privmsg, telling the user the current topic. Also changed #endvote to
260
                set aChanTopic($chan) ""
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
261
	}
262
263
}
264
265
#Records IDEA tag
266
proc pubm:idea {nick host hand chan text} {
267
	if {[meetingInProgress $chan]} {
268
		set message_text [string range $text [expr [string first "]" $text] + 1] end]
269
		outputTag "IDEA" $nick $chan $message_text $message_text
270
	}
271
272
}
273
274
#Record ACTION tag. Can only be used by chair.
275
proc pubm:action {nick host hand chan text} {
9 by Alan Bell
added moin syntax log output
276
	global aChair aActions
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
277
	if {[meetingInProgress $chan] && [string equal $nick $aChair($chan)]} {
278
		set message_text [string range $text [expr [string first "]" $text] + 1] end]
279
		outputTag "ACTION" $nick $chan $message_text $message_text
9 by Alan Bell
added moin syntax log output
280
        	lappend aActions($chan) $message_text
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
281
	}
282
}
283
284
#Recrods AGREED tag. Can only be used by chair.
285
proc pubm:agreed {nick host hand chan text} {
286
	global aChair
287
	if {[meetingInProgress $chan] && [string equal $nick $aChair($chan)]} {
288
		set message_text [string range $text [expr [string first "]" $text] + 1] end]
289
		outputTag "AGREED" $nick $chan $message_text $message_text
290
	}
291
}
292
293
# Records LINK tag
294
proc pubm:link {nick host hand chan text} {
295
        if {[meetingInProgress $chan]} {
296
                set message_text [string range $text [expr [string first "]" $text] + 1] end]
297
		
298
		if {![string compare [string range $message_text 1 [expr [string first ":" $message_text] - 1]] "wiki"]} {
299
		    set rurl "http://wiki.ubuntu.com/[string range $message_text [expr [string first ":" $message_text] + 1] end]"
300
                } else {
301
		    set rurl $message_text
302
                }
303
304
		set url "<a href=\"$rurl\">$message_text</a>" 
305
                outputTag "LINK" $nick $chan $url $message_text
306
        }
307
308
}
309
310
#Records TOPIC tag. Can only be used by chair.
311
proc pubm:topic {nick host hand chan text} {
4 by andrewwilliams
Added a "topic" command for privmsg, telling the user the current topic. Also changed #endvote to
312
	global aChair aChanLogName aAnchorCount VerboseCommands AddToBotLog aChanTopic
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
313
    
314
  	if {[meetingInProgress $chan] && [string equal $nick $aChair($chan)]} {
315
		set message_text [string range $text [expr [string first "]" $text] + 1] end]
316
317
		if {[isVoting $chan]} {
318
                        putquick "PRIVMSG $chan :Vote is in progress. Finishing now."
319
                        pub:endvote $nick $host $hand $chan $text
320
		}
321
322
                if {$VerboseCommands} {
323
			putquick "PRIVMSG $chan :New Topic: $message_text "
324
			putquick "PRIVMSG $aChair($chan) :New Topic: $message_text"
325
		}
326
327
		if {$AddToBotLog} {
328
			putlog "$chan issued TOPIC command"
329
		}
330
4 by andrewwilliams
Added a "topic" command for privmsg, telling the user the current topic. Also changed #endvote to
331
		set aChanTopic($chan) $message_text
332
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
333
		logWrite 2 $chan "<tr>\n\t"
334
		logWrite 2 $chan "<td><a href='$aChanLogName($chan)#$aAnchorCount($chan)'>[clock format [clock seconds] -format %H:%M:%S]</a></td>"
335
		logWrite 2 $chan "<th colspan=3>Topic: $message_text</th>\n</tr>"
9 by Alan Bell
added moin syntax log output
336
		logWrite 3 $chan "== $message_text =="
337
		logWrite 1 $chan "<a name='$aAnchorCount($chan)'></a>"
338
		set aAnchorCount($chan) [expr $aAnchorCount($chan) + 1]
339
	}
340
}
341
342
#Records PROGRESS REPORT tag. Can only be used by chair.
343
proc pubm:progress {nick host hand chan text} {
344
	global aChair aChanLogName aAnchorCount VerboseCommands AddToBotLog aChanTopic
345
    
346
  	if {[meetingInProgress $chan] && [string equal $nick $aChair($chan)]} {
347
		set message_text [string range $text [expr [string first "]" $text] + 1] end]
348
349
		if {[isVoting $chan]} {
350
                        putquick "PRIVMSG $chan :Vote is in progress. Finishing now."
351
                        pub:endvote $nick $host $hand $chan $text
352
		}
353
354
                if {$VerboseCommands} {
355
			putquick "PRIVMSG $chan :Progress Report: $message_text "
356
			putquick "PRIVMSG $aChair($chan) :Progress Report: $message_text"
357
		}
358
359
		if {$AddToBotLog} {
360
			putlog "$chan issued Progress command"
361
		}
362
363
		set aChanTopic($chan) $message_text
364
365
		logWrite 2 $chan "<tr>\n\t"
366
		logWrite 2 $chan "<td><a href='$aChanLogName($chan)#$aAnchorCount($chan)'>[clock format [clock seconds] -format %H:%M:%S]</a></td>"
367
		logWrite 2 $chan "<th colspan=3>Progress: $message_text</th>\n</tr>"
368
		logWrite 3 $chan "=== $message_text ==="
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
369
		logWrite 1 $chan "<a name='$aAnchorCount($chan)'></a>"
370
		set aAnchorCount($chan) [expr $aAnchorCount($chan) + 1]
371
	}
372
}
373
4 by andrewwilliams
Added a "topic" command for privmsg, telling the user the current topic. Also changed #endvote to
374
375
######### Privmsg Commands
376
377
#Privmsgs the user some basic help
378
proc msg:help {nick host hand text} {
9 by Alan Bell
added moin syntax log output
379
	puthelp "PRIVMSG $nick :Commands Available: \[TOPIC\], \[PROGRESS REPORT\], \[IDEA\], \[ACTION\], \[AGREED\], \[LINK\], \[VOTE\]"
4 by andrewwilliams
Added a "topic" command for privmsg, telling the user the current topic. Also changed #endvote to
380
}
381
382
proc msg:topic {nick host hand text} {
383
   global aChanTopic
384
   set chan [lindex [split $text] 0]
385
386
   if {[string index $chan 0] == "#"} {
387
        if {[meetingInProgress $chan]} {
388
            putquick "PRIVMSG $nick :Current Topic for $chan: $aChanTopic($chan)"
389
        } else {
390
	    putquick "PRIVMSG $nick :Theres no current meeting in $chan"
391
        }
392
   } else {
393
 	putquick "PRIVMSG $nick :Please specify a valid channel"
394
   }
395
}
396
1 by andrewwilliams
Inital import from nikdoof-devel Bazaar branch
397
putlog "MootBot - r$mootbot_core_version - Loaded"