Code: Select all
#!/usr/bin/perl
#IRCb plugin file
# This is an example plugin file
# ATTENTION: Pluins have to be copied into the plugins directory AND have to
# be added to the plugin.dat file in order to be loaded by IRCbot !!!
##INIT
use strict;
&ircb_plugin::register_plugin("example","EXP","Example plugin","0.03","13.02.2002");
#(pluginname,author,description,versionnumber,versiondate)
&ircb_plugin::register_onconnect("example_connect_handle_1",\&handle_connect,3);
#(identifier,handlerfunction,mode)
# mode: 1=on socket connect, 2=before motd, 3=after motd, 4=after chanjoin
#NOTE: There can be only one registered handler per identifier string.
&ircb_plugin::register_ondisconnect("example_disconnect_handle_1",\&handle_disconnect);
#(identifier,handlerfunction)
#NOTE: There can be only one registered handler per identifier string.
&ircb_plugin::register_onjoin("example_onjoin_handle_1",\&handle_onjoin);
#(identifier,handlerfunction)
#Called for every user who joins one of our channels
&ircb_plugin::register_onpart("example_onpart_handle_1",\&handle_onpart);
#(identifier,handlerfunction)
#Called for every user who partss one of our channels
&ircb_plugin::register_raw("example_raw_handle_1",\&handle_raw);
#(identifier,handlerfunction)
#EVERY line the bot recieves from the server will first be passed
#to this handler before ANY other action is taken with it.
#WARNING: You can do EVERYTHING with this handler, BUT REMEMBER
# if you return 0 the current line WILL BE DROPPED and
# won't reach any other plugins or commands
&ircb_plugin::register_command("examplecmd",\&handle_examplecmd,3,3,"examplecmd","some example cmd");
#(cmdname,handlerfunction,mode,requireduserlevel,syntax help, help)
# mode: 1=query only, 2=chan only, 3=both
#NOT YET IMPLEMENTED - You could "emulate" them via register_raw
#&ircb_plugin::register_onquit();
#&ircb_plugin::register_onpart();
#&ircb_plugin::register_onkick();
#&ircb_plugin::register_onop();
#&ircb_plugin::register_ondeop();
#&ircb_plugin::register_timer(timername,utime,handler);
##
#SUBs
sub handle_connect #()
{
my $owner = "somenick";
&ircb_plugin::notice($owner,"I AM BACK!");
return 0;
#we return 0 here because we want other onconnect plugins to be
#executed
#
#return 1 on success (HANDLED), 0 on error (CONTINUE)
#1 will not run any further plugins for that action, 0 will continue
#until all are processed or a func returns 1
}
sub handle_disconnect #()
{
#Don't know what to do here. IMPORTANT: we might have NO IRC CONNECTION
#at this point if we where disconnected due to an irc error. We can only
#send output if the disconnect was caused by a quitbot command.
#check if irc connection still valid
if ($main::socket)
{
#this is only executed if we are still connected
my $owner = "somenick";
&ircb_plugin::notice($owner,"I'LL COME BACK TO FINISH THIS!");
}
return 0;
#return 1 on success (HANDLED), 0 on error (CONTINUE)
#1 will not run any further plugins for that action, 0 will continue
#until all are processed or a func returns 1
}
sub handle_onjoin #(user,ipstr,chan)
{
my $u = $_[0];
my $ipstr = $_[1];
my $c = $_[2];
&ircb_plugin::notice($u,"Welcome in $c, have phun!");
return 0;
#return 1 on success (HANDLED), 0 on error (CONTINUE)
#1 will not run any further plugins for that action, 0 will continue
#until all are processed or a func returns 1
}
sub handle_onpart #(user,ipstr,chan)
{
my $u = $_[0];
my $ipstr = $_[1];
my $c = $_[2];
&ircb_plugin::notice($u,"Hope to see you again in $c");
return 0;
#return 1 on success (HANDLED), 0 on error (CONTINUE)
#1 will not run any further plugins for that action, 0 will continue
#until all are processed or a func returns 1
}
sub handle_raw #(line)
{
my $line = $_[0];
#WARNING: You can do EVERYTHING with this handler, BUT REMEMBER
# if you return 1 the current line WILL BE DROPPED and
# won't reach any other plugins or commands
#Something you want to do but have no ircb handler for? Here you
#can really do everything!
#Delete all lines with the word "fuck" in it before they are
#processed in any way (don't know why you would want to do this,
#but, hey, you never know ;)
# if ($line =~ /fuck/)
# {
# return 1;
# }
return 0;
#YOU DONT WANT TO RETURN 1 HERE UNLESS YOU ARE ABSOLUTLY SURE THAT
#YOU KNOW WHAT YOU ARE DOING!
#
#!!! return 1 will drop the current line !!!
#
#return 1 on success (HANDLED), 0 on error (CONTINUE)
#1 will not run any further plugins for that action, 0 will continue
#until all are processed or a func returns 1
}
sub handle_examplecmd #(user,ipstr,chan,\@parameters)
{
my $u = $_[0];
my $ipstr = $_[1];
my $c = $_[2];
my $p = $_[3];
my @p = @{$p};
&ircb_plugin::send($u,"This is the examplecmd. Got: ".@{$p}." parameters (@p).");
#(user/chan,msg)
&ircb_plugin::notice($u,"I RULE!");
#(user,msg)
&ircb_plugin::sendraw("NOTICE $u :I RULE the 2nd!");
#(anyirccommandstring)
my $ip = &ircb_plugin::getip($ipstr);
#get ip from ipstr: Bone!~EXP@unreal.berlinweb.de => unreal.berlinweb.de
#my $lev = &ircb_plugin::getlev($u); (NOT YET IMPLEMENTED)
my $uname = $main::d->{'user'}->{$ipstr};
my $lev = $main::d->{'mode'}->{$uname};
#get userlevel for user
&ircb_plugin::notice($u,"ip: $ip, lev: $lev");
return 1;
#return 1 on success (HANDLED), 0 on error (CONTINUE)
#1 will not run any further plugins for that action, 0 will continue
#until all are processed or a func returns 1
}
1;
#don't remove this