From 0196e61b72f7b8b769a939c3521c7955c603b727 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Tue, 6 Sep 2022 08:02:07 -0700 Subject: [PATCH] Plugin/WordMorph: add `check` command to check if a word exists --- lib/PBot/Plugin/WordMorph.pm | 16 +++++++++++++++- lib/PBot/VERSION.pm | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/PBot/Plugin/WordMorph.pm b/lib/PBot/Plugin/WordMorph.pm index d8c75e05..0130c78a 100644 --- a/lib/PBot/Plugin/WordMorph.pm +++ b/lib/PBot/Plugin/WordMorph.pm @@ -35,7 +35,7 @@ sub unload { } use constant { - USAGE => 'Usage: wordmorph start [steps to solve [word length]] | custom | solve | show | hint [from direction] | giveup', + USAGE => 'Usage: wordmorph start [steps to solve [word length]] | custom | solve | hint [from direction] | check | show | giveup', NO_MORPH_AVAILABLE => "There is no word morph available. Use `wordmorph start [steps to solve [word length]]` to create one.", DB_UNAVAILABLE => "Word morph database not available.", LEFT => 0, @@ -56,6 +56,20 @@ sub wordmorph { my $channel = $context->{from}; given ($command) { + when ('check') { + if (!@args || @args > 1) { + return 'Usage: wordmorph check ; check if a word exists in the Word Morph database'; + } + + return DB_UNAVAILABLE if not $self->{db}; + + if (not exists $self->{db}->{length $args[0]}->{$args[0]}) { + return "I do not know this word `$args[0]`."; + } else { + return "Yes, `$args[0]` is a word I know."; + } + } + when ('hint') { if (not defined $self->{$channel}->{morph}) { return NO_MORPH_AVAILABLE; diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index ca2ea9b6..a0e0da63 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -25,8 +25,8 @@ use PBot::Imports; # These are set by the /misc/update_version script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 4581, - BUILD_DATE => "2022-09-04", + BUILD_REVISION => 4582, + BUILD_DATE => "2022-09-06", }; sub initialize {}