=begin
1. robust
a) ensure data on disk is always in a good state (atomic saving), ensure disk is relatively up to date with state
b) ensure bot gracefully reconnects if kicked etc.
2. async. session-based plug-ins
a) each time a plug-in is invoked, it is done so in a thread, and this plug-in can read() from the channel (whcih by default is filtered to the user initiating the command, but this filter could be changed by plug-in)
b) plug-in can have a main() or similar and should be allowed to post to the channel w/o being invoked (e.g. RSS feed)
3. data schema: bot should log all data in a nice relational database or similar and provide an API to query this (with JOINs and SELECTs)
=enddefmain
line = read_line_from_channel()if plugin = plugins.find {|p| p.can_handle? line }Thread.new{plugin.new(line, channel, db, io)}endendclassSeenPlugIndefinitialize(line, channel, db, io)
author =$1if line =~/\$seen (\w+)/if res = db.query("SELECT date FROM messages WHERE author = #{line.author.nick} ORDER BY date DESC LIMIT 1")
io <<"#{author} was last seen #{res['date']}"else
authors = db.query("SELECT nick FROM authors")
candidates = sort_by_edit_distance(author, authors)
candidates.each do |candidate|
io <<"did you mean #{candidate}?"if io.read =='yes'
…
breakendendendend
…
end