Moved botinfo to State::IRC.
This commit is contained in:
1 parent
c999bd1372
commit
703f2c2ec8
6 files changed
+31
-30
No files matched your search
@@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log
|
|||||||
|
|
||||||
3.0 Indev
|
3.0 Indev
|
||||||
===============================================================================
|
===============================================================================
|
||||||
|
* Moved botinfo to State::IRC.
|
||||||
* Added hook on_selfkick for when we are kicked from a channel.
|
* Added hook on_selfkick for when we are kicked from a channel.
|
||||||
* Moved chanusers to State::IRC.
|
* Moved chanusers to State::IRC.
|
||||||
* Created State::IRC.
|
* Created State::IRC.
|
||||||
|
|||||||
+4
-4
@@ -82,7 +82,7 @@ sub cmode {
|
|||||||
sub umode {
|
sub umode {
|
||||||
my ($svr, $modes) = @_;
|
my ($svr, $modes) = @_;
|
||||||
|
|
||||||
Auto::socksnd($svr, 'MODE '.$Proto::IRC::botinfo{$svr}{nick}." $modes");
|
Auto::socksnd($svr, 'MODE '.$State::IRC::botinfo{$svr}{nick}." $modes");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,7 @@ sub privmsg {
|
|||||||
my ($svr, $target, $message) = @_;
|
my ($svr, $target, $message) = @_;
|
||||||
|
|
||||||
# Get maximum length.
|
# Get maximum length.
|
||||||
my $maxlen = 510 - length q{:}.$Proto::IRC::botinfo{$svr}{nick}.q{!}.$Proto::IRC::botinfo{$svr}{user}.q{@}.$Proto::IRC::botinfo{$svr}{mask}." PRIVMSG $target :";
|
my $maxlen = 510 - length q{:}.$State::IRC::botinfo{$svr}{nick}.q{!}.$State::IRC::botinfo{$svr}{user}.q{@}.$State::IRC::botinfo{$svr}{mask}." PRIVMSG $target :";
|
||||||
|
|
||||||
# Divide message if it surpasses the maximum length.
|
# Divide message if it surpasses the maximum length.
|
||||||
while (length $message >= $maxlen) {
|
while (length $message >= $maxlen) {
|
||||||
@@ -109,7 +109,7 @@ sub notice {
|
|||||||
my ($svr, $target, $message) = @_;
|
my ($svr, $target, $message) = @_;
|
||||||
|
|
||||||
# Get maximum length.
|
# Get maximum length.
|
||||||
my $maxlen = 510 - length q{:}.$Proto::IRC::botinfo{$svr}{nick}.q{!}.$Proto::IRC::botinfo{$svr}{user}.q{@}.$Proto::IRC::botinfo{$svr}{mask}." NOTICE $target :";
|
my $maxlen = 510 - length q{:}.$State::IRC::botinfo{$svr}{nick}.q{!}.$State::IRC::botinfo{$svr}{user}.q{@}.$State::IRC::botinfo{$svr}{mask}." NOTICE $target :";
|
||||||
|
|
||||||
# Divide message if it surpasses the maximum length.
|
# Divide message if it surpasses the maximum length.
|
||||||
while (length $message >= $maxlen) {
|
while (length $message >= $maxlen) {
|
||||||
@@ -136,7 +136,7 @@ sub nick {
|
|||||||
|
|
||||||
Auto::socksnd($svr, "NICK $newnick");
|
Auto::socksnd($svr, "NICK $newnick");
|
||||||
|
|
||||||
$Proto::IRC::botinfo{$svr}{newnick} = $newnick;
|
$State::IRC::botinfo{$svr}{newnick} = $newnick;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ hook_add('on_whoreply', 'ircusers.who', sub {
|
|||||||
my ($svr, $nick, undef) = @_;
|
my ($svr, $nick, undef) = @_;
|
||||||
|
|
||||||
# Ensure it is not us.
|
# Ensure it is not us.
|
||||||
if (lc $nick ne lc $Proto::IRC::botinfo{$svr}{nick}) {
|
if (lc $nick ne lc $State::IRC::botinfo{$svr}{nick}) {
|
||||||
# It is not. Check if they're already in the users hash.
|
# It is not. Check if they're already in the users hash.
|
||||||
if (!$users{$svr}{lc $nick}) {
|
if (!$users{$svr}{lc $nick}) {
|
||||||
# They are not; add them.
|
# They are not; add them.
|
||||||
|
|||||||
+22
-22
@@ -38,7 +38,7 @@ our %RAWC = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
# Variables for various functions.
|
# Variables for various functions.
|
||||||
our (%got_001, %botinfo, %botchans, %csprefix, %chanmodes, %cap);
|
our (%got_001, %botchans, %csprefix, %chanmodes, %cap);
|
||||||
|
|
||||||
# Events.
|
# Events.
|
||||||
API::Std::event_add('on_capack');
|
API::Std::event_add('on_capack');
|
||||||
@@ -112,14 +112,14 @@ sub num001 {
|
|||||||
$got_001{$svr} = 1;
|
$got_001{$svr} = 1;
|
||||||
|
|
||||||
# In case we don't get NICK from the server.
|
# In case we don't get NICK from the server.
|
||||||
if (!defined $botinfo{$svr}{nick}) {
|
if (!defined $State::IRC::botinfo{$svr}{nick}) {
|
||||||
$botinfo{$svr}{nick} = $botinfo{$svr}{newnick};
|
$State::IRC::botinfo{$svr}{nick} = $State::IRC::botinfo{$svr}{newnick};
|
||||||
delete $botinfo{$svr}{newnick};
|
delete $State::IRC::botinfo{$svr}{newnick};
|
||||||
}
|
}
|
||||||
|
|
||||||
# Log.
|
# Log.
|
||||||
API::Log::alog "! Successfully connected to $svr as $botinfo{$svr}{nick}";
|
API::Log::alog "! Successfully connected to $svr as $State::IRC::botinfo{$svr}{nick}";
|
||||||
API::Log::dbug "! Successfully connected to $svr as $botinfo{$svr}{nick}";
|
API::Log::dbug "! Successfully connected to $svr as $State::IRC::botinfo{$svr}{nick}";
|
||||||
|
|
||||||
# Trigger on_connect.
|
# Trigger on_connect.
|
||||||
API::Std::event_run('on_connect', $svr);
|
API::Std::event_run('on_connect', $svr);
|
||||||
@@ -184,7 +184,7 @@ sub num396 {
|
|||||||
my ($svr, @ex) = @_;
|
my ($svr, @ex) = @_;
|
||||||
|
|
||||||
# Update our mask.
|
# Update our mask.
|
||||||
$botinfo{$svr}{mask} = $ex[3];
|
$State::IRC::botinfo{$svr}{mask} = $ex[3];
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -202,7 +202,7 @@ sub num432 {
|
|||||||
API::IRC::quit($svr, 'An error occurred.');
|
API::IRC::quit($svr, 'An error occurred.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined $botinfo{$svr}{newnick}) { delete $botinfo{$svr}{newnick} }
|
if (defined $State::IRC::botinfo{$svr}{newnick}) { delete $State::IRC::botinfo{$svr}{newnick} }
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -212,8 +212,8 @@ sub num432 {
|
|||||||
sub num433 {
|
sub num433 {
|
||||||
my ($svr, undef) = @_;
|
my ($svr, undef) = @_;
|
||||||
|
|
||||||
if (defined $botinfo{$svr}{newnick}) {
|
if (defined $State::IRC::botinfo{$svr}{newnick}) {
|
||||||
API::IRC::nick($svr, $botinfo{$svr}{newnick}.'_');
|
API::IRC::nick($svr, $State::IRC::botinfo{$svr}{newnick}.'_');
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@@ -224,10 +224,10 @@ sub num433 {
|
|||||||
sub num438 {
|
sub num438 {
|
||||||
my ($svr, @ex) = @_;
|
my ($svr, @ex) = @_;
|
||||||
|
|
||||||
if (defined $botinfo{$svr}{newnick}) {
|
if (defined $State::IRC::botinfo{$svr}{newnick}) {
|
||||||
API::Std::timer_add('num438_'.$botinfo{$svr}{newnick}, 1, $ex[11], sub {
|
API::Std::timer_add('num438_'.$State::IRC::botinfo{$svr}{newnick}, 1, $ex[11], sub {
|
||||||
API::IRC::nick($Proto::IRC::botinfo{$svr}{newnick});
|
API::IRC::nick($State::IRC::botinfo{$svr}{newnick});
|
||||||
if (defined $botinfo{$svr}{newnick}) { delete $botinfo{$svr}{newnick} }
|
if (defined $State::IRC::botinfo{$svr}{newnick}) { delete $State::IRC::botinfo{$svr}{newnick} }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,7 +353,7 @@ sub cjoin {
|
|||||||
$chan =~ s/^://gxsm;
|
$chan =~ s/^://gxsm;
|
||||||
|
|
||||||
# Check if this is coming from ourselves.
|
# Check if this is coming from ourselves.
|
||||||
if ($src{nick} eq $botinfo{$svr}{nick}) {
|
if ($src{nick} eq $State::IRC::botinfo{$svr}{nick}) {
|
||||||
$botchans{$svr}{lc $chan} = 1;
|
$botchans{$svr}{lc $chan} = 1;
|
||||||
API::Std::event_run("on_ucjoin", ($svr, $chan));
|
API::Std::event_run("on_ucjoin", ($svr, $chan));
|
||||||
}
|
}
|
||||||
@@ -389,7 +389,7 @@ sub kick {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Check if we were the ones kicked.
|
# Check if we were the ones kicked.
|
||||||
if (lc($ex[3]) eq lc($botinfo{$svr}{nick})) {
|
if (lc($ex[3]) eq lc($State::IRC::botinfo{$svr}{nick})) {
|
||||||
# We were kicked!
|
# We were kicked!
|
||||||
|
|
||||||
# Delete channel from botchans.
|
# Delete channel from botchans.
|
||||||
@@ -421,7 +421,7 @@ sub kick {
|
|||||||
sub mode {
|
sub mode {
|
||||||
my ($svr, @ex) = @_;
|
my ($svr, @ex) = @_;
|
||||||
|
|
||||||
if ($ex[2] ne $botinfo{$svr}{nick}) {
|
if ($ex[2] ne $State::IRC::botinfo{$svr}{nick}) {
|
||||||
# Set data we'll need later.
|
# Set data we'll need later.
|
||||||
my $chan = $ex[2];
|
my $chan = $ex[2];
|
||||||
$ex[3] =~ s/^://xsm;
|
$ex[3] =~ s/^://xsm;
|
||||||
@@ -523,10 +523,10 @@ sub nick {
|
|||||||
$src{svr} = $svr;
|
$src{svr} = $svr;
|
||||||
|
|
||||||
# Check if this is coming from ourselves.
|
# Check if this is coming from ourselves.
|
||||||
if ($src{nick} eq $botinfo{$svr}{nick}) {
|
if ($src{nick} eq $State::IRC::botinfo{$svr}{nick}) {
|
||||||
# It is. Update bot nick hash.
|
# It is. Update bot nick hash.
|
||||||
$botinfo{$svr}{nick} = $nex;
|
$State::IRC::botinfo{$svr}{nick} = $nex;
|
||||||
delete $botinfo{$svr}{newnick} if (defined $botinfo{$svr}{newnick});
|
delete $State::IRC::botinfo{$svr}{newnick} if (defined $State::IRC::botinfo{$svr}{newnick});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# It isn't. Update chanusers and trigger on_nick.
|
# It isn't. Update chanusers and trigger on_nick.
|
||||||
@@ -570,7 +570,7 @@ sub part {
|
|||||||
$src{svr} = $svr;
|
$src{svr} = $svr;
|
||||||
|
|
||||||
# Check if it's from us or someone else.
|
# Check if it's from us or someone else.
|
||||||
if ($src{nick} eq $botinfo{$svr}{nick}) {
|
if ($src{nick} eq $State::IRC::botinfo{$svr}{nick}) {
|
||||||
# Delete this channel from botchans.
|
# Delete this channel from botchans.
|
||||||
if ($botchans{$svr}{$ex[2]}) { delete $botchans{$svr}{$ex[2]} }
|
if ($botchans{$svr}{$ex[2]}) { delete $botchans{$svr}{$ex[2]} }
|
||||||
# Trigger on_upart.
|
# Trigger on_upart.
|
||||||
@@ -621,7 +621,7 @@ sub privmsg {
|
|||||||
|
|
||||||
my ($cmd, $cprefix, $rprefix);
|
my ($cmd, $cprefix, $rprefix);
|
||||||
# Check if it's to a channel or to us.
|
# Check if it's to a channel or to us.
|
||||||
if (lc($ex[2]) eq lc($botinfo{$svr}{nick})) {
|
if (lc($ex[2]) eq lc($State::IRC::botinfo{$svr}{nick})) {
|
||||||
# It is coming to us in a private message.
|
# It is coming to us in a private message.
|
||||||
|
|
||||||
# Ensure it's a valid length.
|
# Ensure it's a valid length.
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ package State::IRC;
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use API::Std qw(hook_add);
|
use API::Std qw(hook_add);
|
||||||
our (%chanusers);
|
our (%chanusers, %botinfo);
|
||||||
|
|
||||||
# Create on_namesreply hook.
|
# Create on_namesreply hook.
|
||||||
hook_add('on_namesreply', 'state.irc.names', sub {
|
hook_add('on_namesreply', 'state.irc.names', sub {
|
||||||
|
|||||||
+2
-2
@@ -55,9 +55,9 @@ sub on_num491 {
|
|||||||
sub is_opered {
|
sub is_opered {
|
||||||
my ($svr) = @_;
|
my ($svr) = @_;
|
||||||
# Auto is not opered.
|
# Auto is not opered.
|
||||||
return if $Proto::IRC::botinfo{$svr}{modes} !~ m/o/xsm;
|
return if $State::IRC::botinfo{$svr}{modes} !~ m/o/xsm;
|
||||||
# Auto is opered.
|
# Auto is opered.
|
||||||
return 1 if $Proto::IRC::botinfo{$svr}{modes} =~ m/o/xsm;
|
return 1 if $State::IRC::botinfo{$svr}{modes} =~ m/o/xsm;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user