# Type: Input # Category: Extra # Description: Gives the list of users which believe they are free # Author: Andriy Lesyuk new Orangutan::Context( response => '^Who(?:\'| i)s free\?*\.*', handler => sub { my ($context, $requester, $item) = @_; my @users = ( ); foreach my $username ($main::users->GetUsers) { my $user = $main::users->GetUser($username); if ($user->GetField('free')) { if ($username eq $requester->GetJID) { push(@users, 'you'); } else { push(@users, $user->GetLogin); } } } if (scalar @users > 0) { if (scalar @users == 1) { my $format = Orangutan::Context::Random( 'The only one is %s', 'Seems only %s', 'Only %s...', 'Just %s', ); $requester->SendMessage(sprintf($format, $users[0])); } else { my $format = Orangutan::Context::Random( 'Users who believe they are free are: %s...', 'Free users are: %s' ); $requester->SendMessage(sprintf($format, join(', ', @users))); } } else { $requester->SendMessage([ 'Hm... Seems everybody is busy', 'No free users... Sorry', 'No body... Sorry', 'No one...' ]); } } ); # kate: syntax perl