Changeset 265

Show
Ignore:
Timestamp:
05/20/06 18:42:53 (3 years ago)
Author:
stillflame
Message:

- started plugging BogswiddleBot? up to the database
- initial schema and configuration file to use postgres and ActiveRecord?
- an attempt at getting logging to the database working

Location:
trunk/tools/irc
Files:
8 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/tools/irc/bogswiddle.rb

    r263 r265  
    2424#  
    2525 
     26$:.unshift File.dirname(__FILE__) 
     27require 'bogsdb' 
    2628require 'rbot/ircbot' 
    2729 
     
    4143    } 
    4244 
     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 
    4356 
    4457    ### Load in our custom plugin 
    4558    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 
    4865    end 
    4966 
    5067 
    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 
    55102    end 
    56103 
  • trunk/tools/irc/trac.rb

    r264 r265  
    9999            :last_change => Time.at(0), 
    100100            :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        } 
    102108    end 
    103109 
     
    106112plugin = TracPlugin.new 
    107113plugin.map 'trac :what', :action => 'feed_on' 
     114plugin.map 'stop tracing :which', :action => 'do_not_feed'