Changeset 265
- Timestamp:
- 05/20/06 18:42:53 (3 years ago)
- Location:
- trunk/tools/irc
- Files:
-
- 8 added
- 2 modified
-
.irbrc (added)
-
README (added)
-
bogsdb.rb (added)
-
bogswiddle.rb (modified) (2 diffs)
-
channel.rb (added)
-
database.yml-example (added)
-
message.rb (added)
-
nick.rb (added)
-
schema.pg.sql (added)
-
trac.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/irc/bogswiddle.rb
r263 r265 24 24 # 25 25 26 $:.unshift File.dirname(__FILE__) 27 require 'bogsdb' 26 28 require 'rbot/ircbot' 27 29 … … 41 43 } 42 44 45 # Where our database config file is 46 ConfigFilename = File.join( File.dirname(__FILE__), 'database.yml') 47 48 # Some default config settings for the database 49 DefaultDatabaseConfig = { 50 'hostname' => 'localhost', 51 } 52 53 # Keep track of whether the database is open 54 @@db = nil 55 43 56 44 57 ### Load in our custom plugin 45 58 def initialize( *args ) 46 super 47 require File.join( File.dirname(__FILE__), 'trac' ) 59 super 60 # :MC: can't load a plugin until the bot has been created 61 require 'trac' 62 63 BogswiddleBot.init_db 64 integrate_with_db 48 65 end 49 66 50 67 51 ### Log to the database instead of a file 52 def log( message, where="server" ) 53 # :TODO: Log to the database, creating a table for the 'where' if it 54 # doesn't exist already. Or maybe only for public messages? 68 ### Initialize the database 69 def BogswiddleBot.init_db 70 File.open( ConfigFilename ) {|cfg| 71 config = DefaultDatabaseConfig.merge( YAML.load( cfg.read ) ) 72 @@db = ActiveRecord::Base.establish_connection( config ) 73 } unless @@db 74 end 75 76 77 ### Load saved plugin data, make sure default records exist 78 def integrate_with_db 79 #:TODO: 80 end 81 82 83 ### Keep our log in the database instead of a file 84 def log( m, where="server" ) 85 message = Message.new 86 message.channel = Channel.find_or_create( "#{@nick}_log" ) 87 message.author = Nick.find_or_create( @nick ) 88 message.happened_at = Time.now 89 message.content = m 90 message.save 91 end 92 93 94 ### Log an actual message 95 def log_message( m ) 96 message = Message.new 97 message.channel = Channel.find_or_create( m.replyto ) # replyto will be either the channel or the sourcenick 98 message.author = Nick.find_or_create( m.sourcenick ) 99 message.content = m.message 100 message.happened_at = m.time 101 message.save 55 102 end 56 103 -
trunk/tools/irc/trac.rb
r264 r265 99 99 :last_change => Time.at(0), 100 100 :where => m.channel 101 } #:TODO: these may want to be persistant 101 } #:TODO: these want to be persistant 102 end 103 104 def do_not_feed( m, params ) 105 @feeds.delete_if {|url,args| 106 url.match( params[:which].strip ) 107 } 102 108 end 103 109 … … 106 112 plugin = TracPlugin.new 107 113 plugin.map 'trac :what', :action => 'feed_on' 114 plugin.map 'stop tracing :which', :action => 'do_not_feed'
