]>
iEval git - poe-component-irc-plugin-infobot.git/blob - Infobot.pm
bd8d83d6009923cfdf8679bc5e239ebb2795aac1
1 package POE
:: Component
:: IRC
:: Plugin
:: Infobot
;
7 our $VERSION = '0.001002' ;
11 use IRC
:: Utils qw
/parse_user/ ;
12 use POE
:: Component
:: IRC
:: Plugin qw
/PCI_EAT_NONE/ ;
15 OK
=> [ 'sure, %s ' , 'ok, %s ' , 'gotcha, %s ' ],
16 A_IS_B
=> [ ' %s is %s ' , 'I think %s is %s ' , 'hmmm... %s is %s ' , 'it has been said that %s is %s ' , ' %s is probably %s ' , 'rumour has it %s is %s ' , 'i heard %s was %s ' , 'somebody said %s is %s ' , 'i guess %s is %s ' , 'well, %s is %s ' , ' %s is, like, %s ' , 'methinks %s is %s ' ],
17 I_DONT_KNOW
=> [ 'I don \' t know, %s ' , 'Dunno, %s ' , 'No idea, %s ' , ' %s : huh?' , 'nem tudom, %s ' , 'anlamıyorum, %s ' , 'bilmiyorum, %s ' , 'nu ştiu d \' astea, %s ' , 'Je ne sais pas, %s ' , 'Я не знаю, %s ' ],
23 filename
=> 'factoids.db' ,
28 $self ->{ dbobj
} = tie
%db , DB_File
=> $self ->{ filename
} if defined $self ->{ filename
};
35 my @strings = @
$rstrings ;
36 sprintf $strings [ int rand $#strings ], @_
40 my ( $self , $irc , $key , $value , $to , $nick ) = @_ ;
41 if ( exists $self ->{ db
}->{ $key }) {
42 $irc -> yield ( privmsg
=> $to => "I already had it that way, $nick " ) if $value eq $self ->{ db
}->{ $key };
43 $irc -> yield ( privmsg
=> $to => "... but $key is $self ->{db}->{ $key }!" ) unless $value eq $self ->{ db
}->{ $key };
45 $self ->{ db
}->{ $key } = $value ;
46 $self ->{ dbobj
}-> sync if exists $self ->{ dbobj
};
47 $irc -> yield ( privmsg
=> $to => getstr OK
, $nick );
52 my ( $self , $irc , $key , $to , $nick , $addressed ) = @_ ;
53 if ( exists $self ->{ db
}->{ $key }) {
54 my @answers = split /\s+\|\s+/ , $self ->{ db
}->{ $key };
55 local $_ = $answers [ int rand $#answers ];
57 if ( /^<action> (.+)$/i ) {
58 $irc -> yield ( ctcp
=> $to => "ACTION $1 " )
59 } elsif ( /^<reply> (.*)$/i ) {
60 $irc -> yield ( privmsg
=> $to => $1 )
62 $irc -> yield ( privmsg
=> $to => getstr A_IS_B
, $key , $_ )
64 } elsif ( $addressed ) {
65 $irc -> yield ( privmsg
=> $to => getstr I_DONT_KNOW
, $nick )
70 my ( $self , $irc , $key , $to , $nick ) = @_ ;
71 if ( exists $self ->{ db
}->{ $key }) {
72 delete $self ->{ db
}->{ $key };
73 $self ->{ dbobj
}-> sync if exists $self ->{ dbobj
};
74 $irc -> yield ( privmsg
=> $to => " $nick : I forgot $key " )
76 $irc -> yield ( privmsg
=> $to => "I didn't have anything matching $key , $nick " )
81 my ( $self , $irc , $to , $nick , $message , $addressed ) = @_ ;
85 if ( /^(.+)\s+is\s+(.*[^?])$/ ) {
86 infobot_add
$self , $irc , $1 , $2 , $to , $nick if $addressed
87 } elsif ( /^(.+)\?$/ ) {
88 infobot_query
$self , $irc , $1 , $to , $nick , $addressed
89 } elsif ( /^forget\s+(.*)$/ ) {
90 infobot_forget
$self , $irc , $1 , $to , $nick if $addressed
95 my ( $self , $irc ) = @_ ;
96 $irc -> plugin_register ( $self , SERVER
=> qw
/public msg/ );
100 sub PCI_unregister
{ 1 }
103 my ( $self , $irc , $rfullname , $rchannels , $rmessage ) = @_ ;
104 my $nick = parse_user
$ $rfullname ;
106 for my $channel ( @
$ $rchannels ) {
107 local $_ = $ $rmessage ;
110 my $mynick = $irc -> nick_name ;
111 if ( /^$mynick [,:]\s+/x ) {
113 s/^$mynick [,:]\s+//x ;
116 runcmd
$self , $irc , $channel , $nick , $_ , $addressed
123 my ( $self , $irc , $rfullname , $rtargets , $rmessage ) = @_ ;
124 my $nick = parse_user
$ $rfullname ;
126 runcmd
$self , $irc , $nick , $nick , $ $rmessage , 1 ;
138 POE::Component::IRC::Plugin::Infobot - Add infobot features to an PoCo-IRC
142 use POE::Component::IRC::Plugin::Infobot;
143 $irc->plugin_add(Infobot => POE::Component::Plugin::Infobot->new(filename => '/tmp/stuff.db'))
147 POE::Component::IRC::Plugin::Infobot is a PoCo-IRC plugin that makes a PoCo-IRC behave like a simple infobot.
149 It stores factoids in a DB_File database and lets IRC users add, remove and retreive factoids.
151 The constructor takes one optional argument, I<filename>, the path to the factoids database. It is 'factoids.db' by default.
159 Any message of the form "X is Y" which is addressed to the bot or sent in private is an add command. This will not overwrite a previous factoid with the same key.
163 < mgv> bot: IRC is Internet Relay Chat
165 < mgv> bot: IRC is Internet Relay Chat
166 <+bot> I already had it that way, mgv
167 < mgv> bot: IRC is Internally-Routed Communication
168 <+bot> ... but IRC is Internet Relay Chat!
169 < mgv> bot: x is <reply> y!
171 < mgv> bot: whistle is <action> whistles
176 Any message of the form "forget X" which is addressed to the bot or sent in private is a forget command. This command will erase any previous factoid with this key.
180 < mgv> bot: forget IRC
181 <+bot> mgv: I forgot IRC
182 < mgv> bot: forget IRC
183 <+bot> I didn't have anything matching IRC, mgv
187 Any message ending in a question mark is a query command. If a factoid with that key is found, the plugin will respond. If no such factoid is found AND the message is either addressed to the bot or sent in private, the bot will say that it doesn't know the answer to the question.
189 If the factoid starts with C<< <reply> >>, everything after the C<< <reply> >> is sent. If it starts with C<< <action> >>, it is sent as a CTCP ACTION. Otherwise, a message of the form C<factoid_key is factoid_value> is sent.
194 <+bot> methinks IRC is Internet Relay Chat
207 L<POE::Component::IRC::Plugin>, L<http://infobot.sourceforge.net/>
211 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
213 =head1 COPYRIGHT AND LICENSE
215 Copyright (C) 2013 by Marius Gavrilescu
217 This library is free software; you can redistribute it and/or modify
218 it under the same terms as Perl itself, either Perl version 5.14.2 or,
219 at your option, any later version of Perl 5 you may have available.
This page took 0.068892 seconds and 3 git commands to generate.