Changeset 263

Show
Ignore:
Timestamp:
05/20/06 12:11:06 (3 years ago)
Author:
stillflame
Message:

- moved plugin require to the initialize
- added comments, reformatted

Location:
trunk/tools/irc
Files:
2 modified

Legend:

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

    r255 r263  
    3838    # Which server/s to connect to 
    3939    Servers = { 
    40         'irc.freenode.net'  => ['#faeriemud'], 
     40        'irc.freenode.net'  => ['#faeriemud', '#flood'], 
    4141    } 
    4242 
     43 
     44    ### Load in our custom plugin 
     45    def initialize( *args ) 
     46        super 
     47        require File.join( File.dirname(__FILE__), 'trac' ) 
     48    end 
    4349 
    4450 
    4551    ### Log to the database instead of a file 
    4652    def log( message, where="server" ) 
    47         # :TODO: Log to the database, creating a table for the 'where' if it 
     53        # :TODO: Log to the database, creating a table for the 'where' if it 
    4854        # doesn't exist already. Or maybe only for public messages? 
    4955    end 
     
    5864 
    5965end # class bogswiddle 
    60  
  • trunk/tools/irc/trac.rb

    r262 r263  
    11#!/usr/bin/ruby 
     2# 
     3# TracPlugin - An rbot plugin for tracking Trac. 
     4# 
     5# == Synopsis 
     6#  
     7#    
     8#  
     9# == Authors 
     10#  
     11# * Martin Chase <stillflame@FaerieMUD.org> 
     12#  
     13# == Copyright 
     14# 
     15# Copyright (c) 2006 The FaerieMUD Consortium. All rights reserved. 
     16#  
     17# This module is free software. You may use, modify, and/or redistribute this 
     18# software under the terms of the Perl Artistic License. (See 
     19# http://language.perl.com/misc/Artistic.html) 
     20#  
     21# == Subversion Id 
     22# 
     23#  $Id$ 
     24#  
    225 
    3  
     26require 'rbot/plugins' 
    427require 'rss/1.0' 
    528require 'rss/2.0' 
     
    1033 
    1134    def help( plugin, topic="" ) 
    12         "trac plugin: periodicly notifies channels of Trac activity.  " + 
    13         "'trac <url>': reports on a Trac" 
     35        "trac plugin: periodicly notifies channel of Trac activity.  " + 
     36            "'trac <url>': reports on a Trac" 
    1437    end 
    1538 
    1639    def initialize 
    17       super 
    18       @feeds = {} 
    19       @period = 60 
    20       @bot.timer.add( @period, self ) { |tracer| 
    21         tracer.feed 
    22       } 
     40        super 
     41        @feeds = {} 
     42        @period = 60 
     43        @bot.timer.add( @period, self ) { |tracer| 
     44            tracer.feed 
     45        } 
    2346    end 
    2447 
    2548    def feed 
    26       puts @feeds.to_yaml 
    27       @feeds.each {|url,params| 
    28         begin 
    29           open( url ) {|page| 
    30             data = page.read 
    31             @bot.say params[:where], parse( data, params ) 
    32           } 
    33         rescue OpenURI::HTTPError, EOFError 
    34           retry         #:MC: is this going to be very bad? 
    35         end 
    36       } 
     49        puts @feeds.to_yaml 
     50        @feeds.each {|url,params| 
     51            begin 
     52                open( url ) {|page| 
     53                    data = page.read 
     54                    @bot.say params[:where], parse( data, params ) 
     55                } 
     56            rescue OpenURI::HTTPError, EOFError 
     57                retry         #:MC: is this going to be really bad, like, if the connection goes down? 
     58            end 
     59        } 
    3760    end 
    3861 
     
    4164 
    4265    def parse( data, params ) 
    43       begin 
    44         rss = RSS::Parser.parse( data ) 
    45       rescue RSS::InvalidRSSError 
    46         rss = RSS::Parser.parse( data, false ) 
    47       end 
    48       message = '' 
    49       newest = params[:last_change] 
    50       rss.channel.items.find_all {|item| 
    51         params[:last_change] < item.pubDate 
    52       }.sort_by {|item| item.pubDate}.each {|item| 
    53         newest = item.pubDate 
    54         message += DisplayString % Elements.map {|element| 
    55           value = item.send( element ) || '' 
    56           value = "???" if value.kind_of?(String) and value.empty? 
    57           value 
    58         } + "\n" 
    59       } 
    60       params[:last_change] = newest 
    61       return message 
     66        begin 
     67            rss = RSS::Parser.parse( data ) 
     68        rescue RSS::InvalidRSSError 
     69            rss = RSS::Parser.parse( data, false ) 
     70        end 
     71        message = '' 
     72        newest = params[:last_change] 
     73        rss.channel.items.find_all {|item| 
     74            params[:last_change] < item.pubDate 
     75        }.sort_by {|item| 
     76            item.pubDate 
     77        }.each {|item| 
     78            newest = item.pubDate 
     79            message += DisplayString % Elements.map {|element| 
     80                value = item.send( element ) || '' 
     81                value = "???" if value.kind_of?(String) and value.empty? 
     82                value 
     83            } + "\n" 
     84        } 
     85        params[:last_change] = newest 
     86        return message 
    6287    end 
    6388 
    6489    def feed_on( m, params ) 
    65       puts "m is '#{m.to_yaml}'" 
    66       puts "params is '#{params.to_yaml}'" 
    67       url = params[:what] 
    68       @feeds[url] = { 
    69         :last_change => Time.at(0), 
    70         :where => m.channel 
    71       } 
     90        @feeds[params[:what]] = { 
     91            :last_change => Time.at(0), 
     92            :where => m.channel 
     93        } #:TODO: these may want to be persistant 
    7294    end 
    7395