Started State::IRC, and moved chanusers to it.
This commit is contained in:
1 parent
ab2d404f20
commit
f2deae219d
6 files changed
+80
-63
No files matched your search
@@ -3,6 +3,8 @@ Auto IRC Bot 3.0: Change Log
|
|||||||
|
|
||||||
3.0 Indev
|
3.0 Indev
|
||||||
===============================================================================
|
===============================================================================
|
||||||
|
* Moved chanusers to State::IRC.
|
||||||
|
* Created State::IRC.
|
||||||
* UNO now keeps game duration and cards played count.
|
* UNO now keeps game duration and cards played count.
|
||||||
* Added a LOLCAT module for translating English to LOLCAT.
|
* Added a LOLCAT module for translating English to LOLCAT.
|
||||||
* EightBall module rewritten.
|
* EightBall module rewritten.
|
||||||
|
|||||||
+4
-4
@@ -375,15 +375,15 @@ sub match_user {
|
|||||||
my $svr = $ulhp{net}[0];
|
my $svr = $ulhp{net}[0];
|
||||||
if (defined $Auto::SOCKET{$svr}) {
|
if (defined $Auto::SOCKET{$svr}) {
|
||||||
if ($ccnm eq 'CURRENT' and defined $user{chan}) {
|
if ($ccnm eq 'CURRENT' and defined $user{chan}) {
|
||||||
if (defined $Proto::IRC::chanusers{$svr}{$user{chan}}{$user{nick}}) {
|
if (defined $State::IRC::chanusers{$svr}{$user{chan}}{$user{nick}}) {
|
||||||
if ($Proto::IRC::chanusers{$svr}{$user{chan}}{$user{nick}} =~ m/($ccst)/sm) { return $userkey; } ## no critic qw(RegularExpressions::RequireExtendedFormatting)
|
if ($State::IRC::chanusers{$svr}{$user{chan}}{$user{nick}} =~ m/($ccst)/sm) { return $userkey; } ## no critic qw(RegularExpressions::RequireExtendedFormatting)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
foreach my $bcj (keys %{ $Proto::IRC::botchans{$svr} }) {
|
foreach my $bcj (keys %{ $Proto::IRC::botchans{$svr} }) {
|
||||||
if (API::IRC::match_mask($bcj, $ccnm)) {
|
if (API::IRC::match_mask($bcj, $ccnm)) {
|
||||||
if (defined $Proto::IRC::chanusers{$svr}{$bcj}{$user{nick}}) {
|
if (defined $State::IRC::chanusers{$svr}{$bcj}{$user{nick}}) {
|
||||||
if ($Proto::IRC::chanusers{$svr}{$bcj}{$user{nick}} =~ m/($ccst)/sm) { return $userkey; } ## no critic qw(RegularExpressions::RequireExtendedFormatting)
|
if ($State::IRC::chanusers{$svr}{$bcj}{$user{nick}} =~ m/($ccst)/sm) { return $userkey; } ## no critic qw(RegularExpressions::RequireExtendedFormatting)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -32,8 +32,8 @@ hook_add("on_quit", "quit_update_chanusers", sub {
|
|||||||
my %src = %{ $src };
|
my %src = %{ $src };
|
||||||
|
|
||||||
# Delete the user from all channels.
|
# Delete the user from all channels.
|
||||||
foreach my $ccu (keys %{ $Proto::IRC::chanusers{$src{svr}}}) {
|
foreach my $ccu (keys %{ $State::IRC::chanusers{$src{svr}}}) {
|
||||||
if (defined $Proto::IRC::chanusers{$src{svr}}{$ccu}{$src{nick}}) { delete $Proto::IRC::chanusers{$src{svr}}{$ccu}{$src{nick}}; }
|
if (defined $State::IRC::chanusers{$src{svr}}{$ccu}{$src{nick}}) { delete $State::IRC::chanusers{$src{svr}}{$ccu}{$src{nick}}; }
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@@ -196,7 +196,7 @@ hook_add('on_disconnect', 'core.irc.deldata', sub {
|
|||||||
if (defined $Proto::IRC::got_001{$svr}) { delete $Proto::IRC::got_001{$svr} }
|
if (defined $Proto::IRC::got_001{$svr}) { delete $Proto::IRC::got_001{$svr} }
|
||||||
if (defined $Proto::IRC::botinfo{$svr}) { delete $Proto::IRC::botinfo{$svr} }
|
if (defined $Proto::IRC::botinfo{$svr}) { delete $Proto::IRC::botinfo{$svr} }
|
||||||
if (defined $Proto::IRC::botchans{$svr}) { delete $Proto::IRC::botchans{$svr} }
|
if (defined $Proto::IRC::botchans{$svr}) { delete $Proto::IRC::botchans{$svr} }
|
||||||
if (defined $Proto::IRC::chanusers{$svr}) { delete $Proto::IRC::chanusers{$svr} }
|
if (defined $State::IRC::chanusers{$svr}) { delete $State::IRC::chanusers{$svr} }
|
||||||
if (defined $Proto::IRC::csprefix{$svr}) { delete $Proto::IRC::csprefix{$svr} }
|
if (defined $Proto::IRC::csprefix{$svr}) { delete $Proto::IRC::csprefix{$svr} }
|
||||||
if (defined $Proto::IRC::chanmodes{$svr}) { delete $Proto::IRC::chanmodes{$svr} }
|
if (defined $Proto::IRC::chanmodes{$svr}) { delete $Proto::IRC::chanmodes{$svr} }
|
||||||
if (defined $Proto::IRC::cap{$svr}) { delete $Proto::IRC::cap{$svr} }
|
if (defined $Proto::IRC::cap{$svr}) { delete $Proto::IRC::cap{$svr} }
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ hook_add('on_namesreply', 'ircusers.names', sub {
|
|||||||
my ($svr, $chan, undef) = @_;
|
my ($svr, $chan, undef) = @_;
|
||||||
|
|
||||||
# Iterate through the users for this channel.
|
# Iterate through the users for this channel.
|
||||||
foreach (keys %{$Proto::IRC::chanusers{$svr}{$chan}}) {
|
foreach (keys %{$State::IRC::chanusers{$svr}{$chan}}) {
|
||||||
# Check if the user already exists.
|
# Check if the user already exists.
|
||||||
if (!$users{$svr}{$_}) {
|
if (!$users{$svr}{$_}) {
|
||||||
# They do not; WHO them.
|
# They do not; WHO them.
|
||||||
@@ -77,9 +77,9 @@ hook_add('on_kick', 'ircusers.onkick', sub {
|
|||||||
if ($users{$src->{svr}}{lc $user}) {
|
if ($users{$src->{svr}}{lc $user}) {
|
||||||
# Figure out if the user is in any other channel we're in.
|
# Figure out if the user is in any other channel we're in.
|
||||||
my $ri = 0;
|
my $ri = 0;
|
||||||
foreach my $chan (keys %{$Proto::IRC::chanusers{$src->{svr}}}) {
|
foreach my $chan (keys %{$State::IRC::chanusers{$src->{svr}}}) {
|
||||||
if ($chan ne $kchan) {
|
if ($chan ne $kchan) {
|
||||||
if (defined $Proto::IRC::chanusers{$src->{svr}}{$chan}{lc $user}) { $ri++; last; }
|
if (defined $State::IRC::chanusers{$src->{svr}}{$chan}{lc $user}) { $ri++; last; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$ri) {
|
if (!$ri) {
|
||||||
@@ -100,9 +100,9 @@ hook_add('on_part', 'ircusers.onpart', sub {
|
|||||||
if ($users{$src->{svr}}{lc $src->{nick}}) {
|
if ($users{$src->{svr}}{lc $src->{nick}}) {
|
||||||
# Figure out if the user is in any other channel we're in.
|
# Figure out if the user is in any other channel we're in.
|
||||||
my $ri = 0;
|
my $ri = 0;
|
||||||
foreach my $chan (keys %{$Proto::IRC::chanusers{$src->{svr}}}) {
|
foreach my $chan (keys %{$State::IRC::chanusers{$src->{svr}}}) {
|
||||||
if ($chan ne $pchan) {
|
if ($chan ne $pchan) {
|
||||||
if (defined $Proto::IRC::chanusers{$src->{svr}}{$chan}{lc $src->{nick}}) { $ri++; last; }
|
if (defined $State::IRC::chanusers{$src->{svr}}{$chan}{lc $src->{nick}}) { $ri++; last; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$ri) {
|
if (!$ri) {
|
||||||
|
|||||||
+17
-51
@@ -38,7 +38,7 @@ our %RAWC = (
|
|||||||
);
|
);
|
||||||
|
|
||||||
# Variables for various functions.
|
# Variables for various functions.
|
||||||
our (%got_001, %botinfo, %botchans, %csprefix, %chanusers, %chanmodes, %cap);
|
our (%got_001, %botinfo, %botchans, %csprefix, %chanmodes, %cap);
|
||||||
|
|
||||||
# Events.
|
# Events.
|
||||||
API::Std::event_add('on_capack');
|
API::Std::event_add('on_capack');
|
||||||
@@ -171,40 +171,6 @@ sub num353 {
|
|||||||
|
|
||||||
# Get rid of the colon.
|
# Get rid of the colon.
|
||||||
$ex[5] =~ s/^://xsm;
|
$ex[5] =~ s/^://xsm;
|
||||||
# Delete the old chanusers hash if it exists.
|
|
||||||
if (defined $chanusers{$svr}{$ex[4]}) { delete $chanusers{$svr}{$ex[4]} }
|
|
||||||
# Iterate through each user.
|
|
||||||
for (5..$#ex) {
|
|
||||||
my $fi = 0;
|
|
||||||
PFITER: foreach my $spfx (keys %{ $csprefix{$svr} }) {
|
|
||||||
# Check if the user has status in the channel.
|
|
||||||
if (substr($ex[$_], 0, 1) eq $csprefix{$svr}{$spfx}) {
|
|
||||||
# He/she does. Lets set that.
|
|
||||||
if (defined $chanusers{$svr}{$ex[4]}{lc $ex[$_]}) {
|
|
||||||
# If the user has multiple statuses.
|
|
||||||
$chanusers{$svr}{$ex[4]}{lc substr $ex[$_], 1} = $chanusers{$svr}{$ex[4]}{lc $ex[$_]}.$spfx;
|
|
||||||
delete $chanusers{$svr}{$ex[4]}{lc $ex[$_]};
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
# Or not.
|
|
||||||
$chanusers{$svr}{$ex[4]}{lc substr $ex[$_], 1} = $spfx;
|
|
||||||
}
|
|
||||||
$fi = 1;
|
|
||||||
$ex[$_] = substr $ex[$_], 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
# Check if there's still a prefix.
|
|
||||||
foreach my $spfx (keys %{$csprefix{$svr}}) {
|
|
||||||
if (substr($ex[$_], 0, 1) eq $csprefix{$svr}{$spfx}) { goto 'PFITER' }
|
|
||||||
}
|
|
||||||
# They had status, so go to the next user.
|
|
||||||
next if $fi;
|
|
||||||
# They didn't, set them as a normal user.
|
|
||||||
if (!defined $chanusers{$svr}{$ex[4]}{lc $ex[$_]}) {
|
|
||||||
$chanusers{$svr}{$ex[4]}{lc $ex[$_]} = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Trigger on_namesreply.
|
# Trigger on_namesreply.
|
||||||
API::Std::event_run('on_namesreply', ($svr, $ex[4], @ex[5..$#ex]));
|
API::Std::event_run('on_namesreply', ($svr, $ex[4], @ex[5..$#ex]));
|
||||||
|
|
||||||
@@ -392,7 +358,7 @@ sub cjoin {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# It isn't. Update chanusers and trigger on_rcjoin.
|
# It isn't. Update chanusers and trigger on_rcjoin.
|
||||||
$chanusers{$svr}{lc $chan}{$src{nick}} = 1;
|
$State::IRC::chanusers{$svr}{lc $chan}{$src{nick}} = 1;
|
||||||
$src{svr} = $svr;
|
$src{svr} = $svr;
|
||||||
API::Std::event_run("on_rcjoin", (\%src, $chan));
|
API::Std::event_run("on_rcjoin", (\%src, $chan));
|
||||||
}
|
}
|
||||||
@@ -408,7 +374,7 @@ sub kick {
|
|||||||
$src{svr} = $svr;
|
$src{svr} = $svr;
|
||||||
|
|
||||||
# Update chanusers.
|
# Update chanusers.
|
||||||
delete $chanusers{$svr}{$ex[2]}{$ex[3]} if defined $chanusers{$svr}{$ex[2]}{$ex[3]};
|
delete $State::IRC::chanusers{$svr}{$ex[2]}{$ex[3]} if defined $State::IRC::chanusers{$svr}{$ex[2]}{$ex[3]};
|
||||||
|
|
||||||
# Set $msg to the kick message.
|
# Set $msg to the kick message.
|
||||||
my $msg = 0;
|
my $msg = 0;
|
||||||
@@ -440,7 +406,7 @@ sub kick {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# We weren't. Update chanusers and trigger on_kick.
|
# We weren't. Update chanusers and trigger on_kick.
|
||||||
if (defined $chanusers{$svr}{$ex[2]}{$ex[3]}) { delete $chanusers{$svr}{$ex[2]}{$ex[3]}; }
|
if (defined $State::IRC::chanusers{$svr}{$ex[2]}{$ex[3]}) { delete $State::IRC::chanusers{$svr}{$ex[2]}{$ex[3]}; }
|
||||||
API::Std::event_run("on_kick", (\%src, $ex[2], $ex[3], $msg));
|
API::Std::event_run("on_kick", (\%src, $ex[2], $ex[3], $msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,26 +465,26 @@ sub mode {
|
|||||||
# It is a status mode, lets parse changes.
|
# It is a status mode, lets parse changes.
|
||||||
my $user = shift(@ex);
|
my $user = shift(@ex);
|
||||||
|
|
||||||
if (defined $chanusers{$svr}{$chan}{$user}) {
|
if (defined $State::IRC::chanusers{$svr}{$chan}{$user}) {
|
||||||
if ($op == 1) {
|
if ($op == 1) {
|
||||||
if ($chanusers{$svr}{$chan}{$user} eq 1) {
|
if ($State::IRC::chanusers{$svr}{$chan}{$user} eq 1) {
|
||||||
$chanusers{$svr}{$chan}{$user} = $maf;
|
$State::IRC::chanusers{$svr}{$chan}{$user} = $maf;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$chanusers{$svr}{$chan}{$user} .= $maf;
|
$State::IRC::chanusers{$svr}{$chan}{$user} .= $maf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ($op == 2) {
|
elsif ($op == 2) {
|
||||||
if (length($chanusers{$svr}{$chan}{$user}) == 1) {
|
if (length($State::IRC::chanusers{$svr}{$chan}{$user}) == 1) {
|
||||||
$chanusers{$svr}{$chan}{$user} = 1;
|
$State::IRC::chanusers{$svr}{$chan}{$user} = 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$chanusers{$svr}{$chan}{$user} =~ s/($maf)//gxsm;
|
$State::IRC::chanusers{$svr}{$chan}{$user} =~ s/($maf)//gxsm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$chanusers{$svr}{$chan}{$user} = $maf;
|
$State::IRC::chanusers{$svr}{$chan}{$user} = $maf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -560,10 +526,10 @@ sub nick {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# It isn't. Update chanusers and trigger on_nick.
|
# It isn't. Update chanusers and trigger on_nick.
|
||||||
foreach my $chk (keys %{ $chanusers{$svr} }) {
|
foreach my $chk (keys %{ $State::IRC::chanusers{$svr} }) {
|
||||||
if (defined $chanusers{$svr}{$chk}{$src{nick}}) {
|
if (defined $State::IRC::chanusers{$svr}{$chk}{$src{nick}}) {
|
||||||
$chanusers{$svr}{$chk}{$nex} = $chanusers{$svr}{$chk}{$src{nick}};
|
$State::IRC::chanusers{$svr}{$chk}{$nex} = $State::IRC::chanusers{$svr}{$chk}{$src{nick}};
|
||||||
delete $chanusers{$svr}{$chk}{$src{nick}};
|
delete $State::IRC::chanusers{$svr}{$chk}{$src{nick}};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
API::Std::event_run("on_nick", (\%src, $nex));
|
API::Std::event_run("on_nick", (\%src, $nex));
|
||||||
@@ -608,7 +574,7 @@ sub part {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# Delete them from chanusers.
|
# Delete them from chanusers.
|
||||||
delete $chanusers{$svr}{$ex[2]}{$src{nick}} if defined $chanusers{$svr}{$ex[2]}{$src{nick}};
|
delete $State::IRC::chanusers{$svr}{$ex[2]}{$src{nick}} if defined $State::IRC::chanusers{$svr}{$ex[2]}{$src{nick}};
|
||||||
|
|
||||||
# Set $msg to the part message.
|
# Set $msg to the part message.
|
||||||
my $msg = 0;
|
my $msg = 0;
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
# lib/State/IRC.pm - IRC state data.
|
||||||
|
# Copyright (C) 2010-2011 Xelhua Development Group, et al.
|
||||||
|
# This program is free software; rights to this code are stated in doc/LICENSE.
|
||||||
|
package State::IRC;
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use API::Std qw(hook_add);
|
||||||
|
our (%chanusers);
|
||||||
|
|
||||||
|
# Create on_namesreply hook.
|
||||||
|
hook_add('on_namesreply', 'state.irc.names', sub {
|
||||||
|
my ($svr, $chan, @data) = @_;
|
||||||
|
|
||||||
|
# Delete the old chanusers hash if it exists.
|
||||||
|
if (defined $chanusers{$svr}{$chan}) { delete $chanusers{$svr}{$chan} }
|
||||||
|
# Iterate through each user.
|
||||||
|
for (1..$#data) {
|
||||||
|
my $fi = 0;
|
||||||
|
PFITER: foreach my $spfx (keys %{ $Proto::IRC::csprefix{$svr} }) {
|
||||||
|
# Check if the user has status in the channel.
|
||||||
|
if (substr($data[$_], 0, 1) eq $Proto::IRC::csprefix{$svr}{$spfx}) {
|
||||||
|
# He/she does. Lets set that.
|
||||||
|
if (defined $chanusers{$svr}{$chan}{lc $data[$_]}) {
|
||||||
|
# If the user has multiple statuses.
|
||||||
|
$chanusers{$svr}{$chan}{lc substr $data[$_], 1} = $chanusers{$svr}{$chan}{lc $data[$_]}.$spfx;
|
||||||
|
delete $chanusers{$svr}{$chan}{lc $data[$_]};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# Or not.
|
||||||
|
$chanusers{$svr}{$chan}{lc substr $data[$_], 1} = $spfx;
|
||||||
|
}
|
||||||
|
$fi = 1;
|
||||||
|
$data[$_] = substr $data[$_], 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# Check if there's still a prefix.
|
||||||
|
foreach my $spfx (keys %{$Proto::IRC::csprefix{$svr}}) {
|
||||||
|
if (substr($data[$_], 0, 1) eq $Proto::IRC::csprefix{$svr}{$spfx}) { goto 'PFITER' }
|
||||||
|
}
|
||||||
|
# They had status, so go to the next user.
|
||||||
|
next if $fi;
|
||||||
|
# They didn't, set them as a normal user.
|
||||||
|
if (!defined $chanusers{$svr}{$chan}{lc $data[$_]}) {
|
||||||
|
$chanusers{$svr}{$chan}{lc $data[$_]} = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
Reference in new issue
Block a user