# Type: Input # Category: Reusable # Description: Catches answers (Yes or No) and notifies corresponding contexts # Note: Contains foreign handlers # Uses: Cancel (and others which has registered) # Copied: Yes # Scheduler: Everyday at 3:00 # Author: Andriy Lesyuk use utf8; new Orangutan::Context( response => [ '^(?:Yes|Yup|Yep|Sure|Of course)\b', '^(?:Please )?do(?: it)?!*\.*$', '^Go ahead!*\.*$', '^Ok(?:ay)?!*\.*', '^(?:No|Nope)\b' ], handler => sub { my ($context, $user, $item) = @_; if (!$context->CallForeignHandler($user, -1, ($item > 4) ? 'N' : 'Y')) { if ($item == 5) { my $cancel = $user->GetResponse('Cancel'); if ($cancel) { $cancel->CallHandler($user, $item); return; } } if ($item != 4) { $user->SendMessage([ 'What? Seems I did not ask any questions... :S', 'Oops!.. Seems I forgot what I asked...', 'Great! Answer is given but no question was asked! ;)', 'Did I ask you something?' ]); } } }, schedule => sub { my ($context, $scheduler, $arg) = @_; if ($arg eq 'clean') { foreach my $username ($main::users->GetUsers) { my $user = $main::users->GetUser($username); my $ucontext = $user->GetResponse($context->GetID); if (defined($ucontext)) { $ucontext->CleanForeignHandlers; } } } my ($hour, $day, $month, $year) = (localtime(time))[2..5]; if ($hour >= 3) { ($day, $month, $year) = (localtime(time + 86400))[3..5]; } my $time = POSIX::mktime(0, 0, 3, $day, $month, $year); $scheduler->Schedule($time, $context, 'clean'); }, filter => sub { my ($context, $user, $message) = @_; if ((${$message} =~ s/^тщ\b.*$/no/i) || (${$message} =~ s/^ну[іы]\b.*$/yes/i)) { my $format = Orangutan::Context::Random( 'You forgot to switch language... ;)', 'I guess you meant "%s"...', 'Getting this as "%s"...', 'Treating as "%s"...' ); $user->SendMessage(sprintf($format, ${$message})); return 1; } else { return 0; } }, weight => [ undef, -50, 0 ], copy => 1 ); # kate: syntax perl