Ignore:
Timestamp:
01/24/12 21:16:27 (4 months ago)
Author:
GeorgeClark
Message:

Item9551: Some cleanup

And start to convert the twitter and irc code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ImmediateNotifyPlugin/lib/Foswiki/Plugins/ImmediateNotifyPlugin/IRC.pm

    r13777 r13817  
    1 # Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/ 
    2 # 
    3 # Copyright (C) 2005 TWiki Contributors. All Rights Reserved. 
    4 # TWiki Contributors are listed in the AUTHORS file in the root 
    5 # of this distribution. 
    6 # NOTE: Please extend that file, not this notice. 
    7 # 
    8 # Additional copyrights apply to some or all of the code in this 
    9 # file as follows: 
    10 # Copyright (C) 2000-2003 Andrea Sterbini, a.sterbini@flashnet.it 
    11 # Copyright (C) 2001-2004 Peter Thoeny, peter@thoeny.com 
    12 # 
    13 # This program is free software; you can redistribute it and/or 
    14 # modify it under the terms of the GNU General Public License 
    15 # as published by the Free Software Foundation; either version 2 
    16 # of the License, or (at your option) any later version. For 
    17 # more details read LICENSE in the root of this distribution. 
    18 # 
    19 # This program is distributed in the hope that it will be useful, 
    20 # but WITHOUT ANY WARRANTY; without even the implied warranty of 
    21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
     1# See bottom of file for default license and copyright information 
    222 
    23 =pod 
     3=begin TML 
    244 
    25 ---+ package IrcPlugin 
     5---+ package Foswiki::Plugins::ImmediateNotifyPlugin::IRC 
    266 
     7This plugin module supports immediate notification of topic saves using the IRC (Jabber) protocol. 
     8. 
    279=cut 
    2810 
    29 package TWiki::Plugins::IrcPlugin; 
     11package Foswiki::Plugins::ImmediateNotifyPlugin::IRC; 
     12 
    3013use strict; 
     14use warnings; 
    3115 
    32 use Net::IRC; 
     16#use Net::IRC;  DEPRECATED  
     17 
     18use Bot::BasicBot; 
    3319use Data::Dumper; 
    3420 
    35 use vars qw( $VERSION $RELEASE $debug $pluginName ); 
    36 $VERSION = '$Rev$'; 
    37 $RELEASE = 'Dakar'; 
     21my $debug; 
     22my $warning; 
    3823 
    39 # Name of this Plugin, only used in this module 
    40 $pluginName = 'IrcPlugin'; 
     24sub new { 
     25    my ($class) = @_; 
    4126 
    42 ################################################################################ 
     27    my $this = bless( {}, $class ); 
    4328 
    44 sub initPlugin { 
    45     my( $topic, $web, $user, $installWeb ) = @_; 
     29    $this->{ircUser} = 
     30      $Foswiki::cfg{Plugins}{ImmediateNotifyPlugin}{IRC}{Username}; 
     31    $this->{ircPass} = 
     32      $Foswiki::cfg{Plugins}{ImmediateNotifyPlugin}{IRC}{Password}; 
     33    $this->{ircServer} = 
     34      $Foswiki::cfg{Plugins}{ImmediateNotifyPlugin}{IRC}{Server}; 
    4635 
    47     # check for Plugins.pm versions 
    48     if( $TWiki::Plugins::VERSION < 1.026 ) { 
    49         TWiki::Func::writeWarning( "Version mismatch between $pluginName and Plugins.pm" ); 
    50         return 0; 
    51     } 
     36    # SMELL: Resource allows multiple concurrent logins - consider including 
     37    # the pid or some other identifier so multiple fastcgi handlers could 
     38    # maintain concurrent connections. 
     39    $this->{ircResource} = 
     40      'Foswiki';    #Foswiki::Func::getPreferencesValue( 'WIKITOOLNAME' ); 
     41    $this->{con} = ''; 
    5242 
    53     # Plugin correctly initialized 
    54     return 1; 
     43    $debug   = \&Foswiki::Plugins::ImmediateNotifyPlugin::debug; 
     44    $warning = \&Foswiki::Plugins::ImmediateNotifyPlugin::warning; 
     45 
     46    &$debug( 
     47"- IRC init with $this->{ircUser},  $this->{ircPass}, $this->{ircServer}" 
     48    ); 
     49 
     50    return $this; 
    5551} 
     52 
     53 
    5654 
    5755sub afterSaveHandler { 
     
    5957    my ( $topic, $web, $error, $meta ) = @_[1..4]; 
    6058 
    61     TWiki::Func::writeDebug( "- ${pluginName}::afterSaveHandler( ${web}.${topic} )" ) if $debug; 
     59    Foswiki::Func::writeDebug( "- ${pluginName}::afterSaveHandler( ${web}.${topic} )" ) if $debug; 
    6260 
    6361    my $topicInfo = $meta->get( 'TOPICINFO' ); 
     
    6664 
    6765    _writeIrc({ newconn => { 
    68         Server => TWiki::Func::getPluginPreferencesValue( 'SERVER' ) || 'localhost', 
    69         Port => TWiki::Func::getPluginPreferencesValue( 'PORT' ) || '6667', 
    70         Nick => 'TWikiIrcPlugin' || TWiki::Func::getPluginPreferencesValue( 'NICK' ) || 'TWikiIrcPlugin', 
     66        Server => Foswiki::Func::getPluginPreferencesValue( 'SERVER' ) || 'localhost', 
     67        Port => Foswiki::Func::getPluginPreferencesValue( 'PORT' ) || '6667', 
     68        Nick => 'FoswikiIrcPlugin' || Foswiki::Func::getPluginPreferencesValue( 'NICK' ) || 'FoswikiIrcPlugin', 
    7169#       Ircname  => 'This bot brought to you by Net::IRC.', 
    72 #       Username => 'TWikiIrcPlugin', 
     70#       Username => 'FoswikiIrcPlugin', 
    7371    }, 
    74                 msg => TWiki::Func::getScriptUrl( $web, $topic, 'view' ) . ' ' 
     72                msg => Foswiki::Func::getScriptUrl( $web, $topic, 'view' ) . ' ' 
    7573                    . ( $version == 1 ? 'created' : "updated to r$version" ) 
    7674                    . " by $topicInfo->{author}", 
     
    115113    my $self = shift; 
    116114 
    117     my $CHANNEL = TWiki::Func::getPluginPreferencesValue( 'CHANNEL' ) || 'test'; 
     115    my $CHANNEL = Foswiki::Func::getPluginPreferencesValue( 'CHANNEL' ) || 'test'; 
    118116    $self->join( $CHANNEL ); 
    119117#    print STDERR "nick=[" . $self->nick . "]\n"; 
     
    153151 
    1541521; 
     153 
     154__END__ 
     155Foswiki - The Free and Open Source Wiki, http://foswiki.org/ 
     156 
     157Copyright (C) 2012 Foswiki Contributors. Foswiki Contributors 
     158are listed in the AUTHORS file in the root of this distribution. 
     159 
     160Additional copyrights apply to some or all of the code in this 
     161file as follows: 
     162Copyright (C) 2005 TWiki Contributors. All Rights Reserved. 
     163   TWiki Contributors are listed in the AUTHORS file in the root 
     164   of the TWiki distribution. 
     165Copyright (C) 2000-2003 Andrea Sterbini, a.sterbini@flashnet.it 
     166Copyright (C) 2001-2004 Peter Thoeny, peter@thoeny.com 
     167 
     168This program is free software; you can redistribute it and/or 
     169modify it under the terms of the GNU General Public License 
     170as published by the Free Software Foundation; either version 2 
     171of the License, or (at your option) any later version. For 
     172more details read LICENSE in the root of this distribution. 
     173 
     174This program is distributed in the hope that it will be useful, 
     175but WITHOUT ANY WARRANTY; without even the implied warranty of 
     176MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
     177 
     178As per the GPL, removal of this notice is prohibited. 
     179 
Note: See TracChangeset for help on using the changeset viewer.