# Type: Input # Category: Aliases # Description: Allows to remove alias # Author: Andriy Lesyuk new Orangutan::Context( response => sub { my ($self, $user, $dummy, $message) = @_; my @result = ( ); my @regexps = ( '(?:Remove|delete) (?:(?:the )?(?:(?:message|(words?|substring|text)) )?alias )?["\']?(.+?)["\']?!*\.*', '(?:Never|do(?: not|n\'t)?) (?:replace|treat) (?:(?:the )?(?:(?:message|(words?|substring|text)) )?alias )?'. '["\']?(.+?)["\']?(?: (?:with|as) anything(?: (?:else|different))?)?!*\.*' ); $message =~ s!\n! !sg; $message =~ s!^\s+!!; $message =~ s!\s+$!!; $message =~ s!\s{2,}! !g; my $context = $user->GetResponse('Aliases'); my $aliases = $context->GetField('aliases'); if ($aliases) { foreach my $regexp (@regexps) { if ($message =~ /^$regexp$/i) { my ($substring, $string) = ($1, $2); $string =~ s!^\s+!!; $string =~ s!\s+$!!; $string =~ s!\s{2,}! !g; my $alias; if ($substring) { $alias = '(\A| )'.quotemeta($string).'( |\Z)'; } else { $alias = '^'.quotemeta($string).'$'; } foreach my $key (keys %{$aliases}) { if (lc($key) eq lc($alias)) { push(@result, 1); push(@result, $key); last; } } } } } return @result; }, handler => sub { my ($self, $user, $item, $alias) = @_; my $context = $user->GetResponse('Aliases'); my $aliases = $context->GetField('aliases'); delete($aliases->{$alias}); Aliases_Save($user, $aliases); $user->SendMessage([ "Got it! Won't use it any more.", 'Ok... Removed.', 'Removed.', 'Got it.' ]); }, help => { title => 'How can I remove an alias?', question => '^(?:How )?(?:(?:can|do) I |to )(?:remove|delete|drop|cancel) (?:(?:the|an?) )?alias(?:es)?\?*!*\.*$', answer => "You can remove aliases. ". "When removing an alias you can specify its type.\n". "Some samples:\n". " o Don't treat \"todo\" as anything else\n". " o Never replace \"Researching\"\n". " o Remove word alias \"Bye\"\n". " o Remove FB\n". "To indicate that an alias is a substring alias specify \"word alias\" or \"substring alias\"...", weight => 1230 } ); # kate: syntax perl