From 45dfebfddf4099b617eaf9ddd558596f60309b71 Mon Sep 17 00:00:00 2001 From: timriker Date: Thu, 17 Feb 2005 03:18:52 +0000 Subject: [PATCH] spell is now a forker git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@1129 c11ca15a-4712-0410-83d8-924469b57eb5 --- files/sample/blootbot.chan | 2 +- src/CommandStubs.pl | 3 ++ src/Modules/spell.pl | 76 ++++++++++++++++++++++++++++++++++++++ src/UserExtra.pl | 59 ----------------------------- 4 files changed, 80 insertions(+), 60 deletions(-) create mode 100644 src/Modules/spell.pl diff --git a/files/sample/blootbot.chan b/files/sample/blootbot.chan index e868c79..e7c9233 100644 --- a/files/sample/blootbot.chan +++ b/files/sample/blootbot.chan @@ -1,4 +1,4 @@ -#v1: blootbot -- infobot -- written Thu Feb 17 02:56:42 2005 +#v1: blootbot -- infobot -- written Thu Feb 17 03:17:32 2005 #botpark +RootWarn diff --git a/src/CommandStubs.pl b/src/CommandStubs.pl index 92793e7..b007d36 100644 --- a/src/CommandStubs.pl +++ b/src/CommandStubs.pl @@ -277,6 +277,9 @@ sub parseCmdHook { &addCmdHook("extra", 'wtf', ('CODEREF' => 'wtf::query', 'Identifier' => 'wtf', 'Cmdstats' => 'wtf', 'Forker' => 1, 'Help' => 'wtf') ); +&addCmdHook("extra", '[ia]?spell', ('CODEREF' => 'spell::query', + 'Identifier' => 'spell', 'Cmdstats' => 'spell', + 'Forker' => 1, 'Help' => 'spell') ); ### ### END OF ADDING HOOKS. ### diff --git a/src/Modules/spell.pl b/src/Modules/spell.pl new file mode 100644 index 0000000..b34b3e6 --- /dev/null +++ b/src/Modules/spell.pl @@ -0,0 +1,76 @@ +# +# spell.pl: interface to aspell/ispell/spell +# Author: Tim Riker +# Source: extracted from UserExtra +# Licensing: Artistic License (as perl itself) +# Version: v0.1 +# +# Copyright (c) 2005 Tim Riker +# + +package spell; + +use strict; + +sub spell::spell { + my $query = shift; + my $binary; + my @binaries = ( + '/usr/bin/aspell', + '/usr/bin/ispell', + '/usr/bin/spell' + ); + + foreach (@binaries) { + if (-x $_) { + $binary=$_; + last; + } + } + + if (!$binary) { + return("no binary found."); + } + + if (!&main::validExec($query)) { + return("argument appears to be fuzzy."); + } + + my $reply = "I can't find alternate spellings for '$query'"; + + foreach (`/bin/echo '$query' | $binary -a -S`) { + chop; + last if !length; # end of query. + + if (/^\@/) { # intro line. + next; + } elsif (/^\*/) { # possibly correct. + $reply = "'$query' may be spelled correctly"; + last; + } elsif (/^\&/) { # possible correction(s). + s/^\& (\S+) \d+ \d+: //; + my @array = split(/,? /); + + $reply = "possible spellings for $query: @array"; + last; + } elsif (/^\+/) { + &main::DEBUG("spell: '+' found => '$_'."); + last; + } elsif (/^# (.*?) 0$/) { + # none found. + last; + } else { + &main::DEBUG("spell: unknown: '$_'."); + } + } + + return($reply); +} + +sub spell::query { + &::performStrictReply(&spell(@_)); + return; +} + +1; +# vim: ts=2 sw=2 diff --git a/src/UserExtra.pl b/src/UserExtra.pl index f3138ad..584a43b 100644 --- a/src/UserExtra.pl +++ b/src/UserExtra.pl @@ -26,8 +26,6 @@ use vars qw(%channels %chanstats %cmdstats %count %ircstats %param &addCmdHook("main", 'help', ('CODEREF' => 'help', 'Cmdstats' => 'Help', ) ); &addCmdHook("main", 'karma', ('CODEREF' => 'karma', ) ); -&addCmdHook("main", 'i?spell', ('CODEREF' => 'ispell', - Help => 'spell', Identifier => 'spell', ) ); &addCmdHook("main", 'd?nslookup', ('CODEREF' => 'DNS', Help => 'nslookup', Identifier => 'allowDNS', Forker => "NULL", ) ); @@ -236,63 +234,6 @@ sub karma { } } -sub ispell { - my $query = shift; - my $binary; - my @binaries = ( - '/usr/bin/aspell', - '/usr/bin/ispell', - '/usr/bin/spell' - ); - - foreach (@binaries) { - if (-x $_) { - $binary=$_; - last; - } - } - - if (!$binary) { - &msg($who, "no binary found."); - return; - } - - if (!&validExec($query)) { - &msg($who,"argument appears to be fuzzy."); - return; - } - - my $reply = "I can't find alternate spellings for '$query'"; - - foreach (`/bin/echo '$query' | $binary -a -S`) { - chop; - last if !length; # end of query. - - if (/^\@/) { # intro line. - next; - } elsif (/^\*/) { # possibly correct. - $reply = "'$query' may be spelled correctly"; - last; - } elsif (/^\&/) { # possible correction(s). - s/^\& (\S+) \d+ \d+: //; - my @array = split(/,? /); - - $reply = "possible spellings for $query: @array"; - last; - } elsif (/^\+/) { - &DEBUG("spell: '+' found => '$_'."); - last; - } elsif (/^# (.*?) 0$/) { - # none found. - last; - } else { - &DEBUG("spell: unknown: '$_'."); - } - } - - &pSReply($reply); -} - sub nslookup { my $query = shift; &status("DNS Lookup: $query"); -- 2.39.5