From f2a8839707320aa3092dc479ef89e8b9260ee1dd Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Mon, 8 Jun 2015 04:43:00 -0700 Subject: [PATCH] Add $randomnick special factoid variable --- PBot/FactoidModuleLauncher.pm | 1 + PBot/Factoids.pm | 1 + PBot/NickList.pm | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/PBot/FactoidModuleLauncher.pm b/PBot/FactoidModuleLauncher.pm index 853dd370..6cd9f940 100644 --- a/PBot/FactoidModuleLauncher.pm +++ b/PBot/FactoidModuleLauncher.pm @@ -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); diff --git a/PBot/Factoids.pm b/PBot/Factoids.pm index ec5ba9b0..f0147e41 100644 --- a/PBot/Factoids.pm +++ b/PBot/Factoids.pm @@ -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 =~ /(?{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]);