mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-23 04:19:27 +01:00
Add $randomnick special factoid variable
This commit is contained in:
parent
c81612c58c
commit
f2a8839707
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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]);
|
||||
|
Loading…
Reference in New Issue
Block a user