3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-23 11:12:42 +01:00

Add $randomnick special factoid variable

This commit is contained in:
Pragmatic Software 2015-06-08 04:43:00 -07:00
parent c81612c58c
commit f2a8839707
3 changed files with 18 additions and 1 deletions

View File

@ -58,6 +58,7 @@ sub execute_module {
$arguments =~ s/\$nick/$nick/g;
$arguments =~ s/\$channel/$from/g;
$arguments =~ s/\$randomnick/my $random = $self->{pbot}->{nicklist}->random_nick($from); $random ? $random : $nick/ge;
$arguments = quotemeta($arguments);

View File

@ -501,6 +501,7 @@ sub interpreter {
$action =~ s/\$nick/$nick/g;
$action =~ s/\$channel/$from/g;
$action =~ s/\$randomnick/my $random = $self->{pbot}->{nicklist}->random_nick($from); $random ? $random : $nick/ge;
while ($action =~ /(?<!\\)\$([a-zA-Z0-9_\-]+)/g) {
my $v = $1;

View File

@ -84,13 +84,28 @@ sub get_channels {
sub is_present {
my ($self, $channel, $nick) = @_;
if (exists $self->{nicklist}->{lc $channel} and exists $self->{nicklist}->{lc $channel}->{lc $nick}) {
$channel = lc $channel;
if (exists $self->{nicklist}->{$channel} and exists $self->{nicklist}->{$channel}->{lc $nick}) {
return 1;
} else {
return 0;
}
}
sub random_nick {
my ($self, $channel) = @_;
$channel = lc $channel;
if (exists $self->{nicklist}->{$channel}) {
my @nicks = keys $self->{nicklist}->{$channel};
return $nicks[rand @nicks];
} else {
return undef;
}
}
sub on_namreply {
my ($self, $event_type, $event) = @_;
my ($channel, $nicks) = ($event->{event}->{args}[2], $event->{event}->{args}[3]);