From ace9991d945ca548aa3583911a4d00d9b32b6e78 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sun, 9 Nov 2025 21:07:16 -0800 Subject: [PATCH] Rename IsAbbrev to Abbrev; add deabbrev() deabbrev() operates on a list of items and returns an expansion list which can be used to detect items needing disambiguation. --- lib/PBot/Core/Commands/AntiSpam.pm | 2 +- lib/PBot/Core/Commands/BanList.pm | 2 +- lib/PBot/Core/Commands/BlackList.pm | 2 +- lib/PBot/Core/Commands/Capabilities.pm | 2 +- lib/PBot/Core/Commands/EventQueue.pm | 2 +- lib/PBot/Core/Utils/Abbrev.pm | 35 ++++++++++++++++++++++++++ lib/PBot/Core/Utils/IsAbbrev.pm | 21 ---------------- lib/PBot/Plugin/ActionTrigger.pm | 2 +- lib/PBot/Plugin/Battleship.pm | 2 +- lib/PBot/Plugin/WordMorph.pm | 2 +- lib/PBot/Plugin/Wordle.pm | 2 +- lib/PBot/VERSION.pm | 4 +-- 12 files changed, 46 insertions(+), 32 deletions(-) create mode 100644 lib/PBot/Core/Utils/Abbrev.pm delete mode 100644 lib/PBot/Core/Utils/IsAbbrev.pm diff --git a/lib/PBot/Core/Commands/AntiSpam.pm b/lib/PBot/Core/Commands/AntiSpam.pm index 0f87befd..91ff5ae3 100644 --- a/lib/PBot/Core/Commands/AntiSpam.pm +++ b/lib/PBot/Core/Commands/AntiSpam.pm @@ -9,7 +9,7 @@ package PBot::Core::Commands::AntiSpam; use parent 'PBot::Core::Class'; use PBot::Imports; -use PBot::Core::Utils::IsAbbrev; +use PBot::Core::Utils::Abbrev; use Time::HiRes qw/gettimeofday/; use POSIX qw/strftime/; diff --git a/lib/PBot/Core/Commands/BanList.pm b/lib/PBot/Core/Commands/BanList.pm index 68102a56..7b646274 100644 --- a/lib/PBot/Core/Commands/BanList.pm +++ b/lib/PBot/Core/Commands/BanList.pm @@ -10,7 +10,7 @@ use parent 'PBot::Core::Class'; use PBot::Imports; -use PBot::Core::Utils::IsAbbrev; +use PBot::Core::Utils::Abbrev; use PBot::Core::MessageHistory::Constants ':all'; use Time::HiRes qw/gettimeofday/; diff --git a/lib/PBot/Core/Commands/BlackList.pm b/lib/PBot/Core/Commands/BlackList.pm index e7acb308..95ea534d 100644 --- a/lib/PBot/Core/Commands/BlackList.pm +++ b/lib/PBot/Core/Commands/BlackList.pm @@ -10,7 +10,7 @@ package PBot::Core::Commands::BlackList; use parent 'PBot::Core::Class'; use PBot::Imports; -use PBot::Core::Utils::IsAbbrev; +use PBot::Core::Utils::Abbrev; sub initialize($self, %conf) { $self->{pbot}->{commands}->register(sub { $self->cmd_blacklist(@_) }, "blacklist", 1); diff --git a/lib/PBot/Core/Commands/Capabilities.pm b/lib/PBot/Core/Commands/Capabilities.pm index dc7a3f03..3678b8ea 100644 --- a/lib/PBot/Core/Commands/Capabilities.pm +++ b/lib/PBot/Core/Commands/Capabilities.pm @@ -10,7 +10,7 @@ package PBot::Core::Commands::Capabilities; use PBot::Imports; use parent 'PBot::Core::Class'; -use PBot::Core::Utils::IsAbbrev; +use PBot::Core::Utils::Abbrev; sub initialize($self, %conf) { $self->{pbot}->{commands}->register(sub { $self->cmd_cap(@_) }, "cap"); diff --git a/lib/PBot/Core/Commands/EventQueue.pm b/lib/PBot/Core/Commands/EventQueue.pm index 69cb0159..e6993822 100644 --- a/lib/PBot/Core/Commands/EventQueue.pm +++ b/lib/PBot/Core/Commands/EventQueue.pm @@ -10,7 +10,7 @@ package PBot::Core::Commands::EventQueue; use PBot::Imports; use parent 'PBot::Core::Class'; -use PBot::Core::Utils::IsAbbrev; +use PBot::Core::Utils::Abbrev; use Time::Duration; diff --git a/lib/PBot/Core/Utils/Abbrev.pm b/lib/PBot/Core/Utils/Abbrev.pm new file mode 100644 index 00000000..8d4100b4 --- /dev/null +++ b/lib/PBot/Core/Utils/Abbrev.pm @@ -0,0 +1,35 @@ +# File: Abbrev.pm +# +# Purpose: Utils to check is a string is an abbreviation of another string. + +# SPDX-FileCopyrightText: 2017-2023 Pragmatic Software +# SPDX-License-Identifier: MIT + +package PBot::Core::Utils::Abbrev; + +use PBot::Imports; + +require Exporter; +our @ISA = qw/Exporter/; +our @EXPORT = qw/isabbrev deabbrev/; + +sub isabbrev($str1, $str2) { + return 0 if !length $str1 || !length $str2; + return (substr($str1, 0, length $str1) eq substr($str2, 0, length $str1)); +} + +sub deabbrev($abbrev, @list) { + return () if !length $abbrev || !@list; + + my @expansions; + + foreach my $item (@list) { + if (isabbrev($abbrev, $item)) { + push @expansions, $item; + } + } + + return @expansions; +} + +1; diff --git a/lib/PBot/Core/Utils/IsAbbrev.pm b/lib/PBot/Core/Utils/IsAbbrev.pm deleted file mode 100644 index a4f2f8d7..00000000 --- a/lib/PBot/Core/Utils/IsAbbrev.pm +++ /dev/null @@ -1,21 +0,0 @@ -# File: IsAbbrev.pm -# -# Purpose: Check is a string is an abbreviation of another string. - -# SPDX-FileCopyrightText: 2017-2023 Pragmatic Software -# SPDX-License-Identifier: MIT - -package PBot::Core::Utils::IsAbbrev; - -use PBot::Imports; - -require Exporter; -our @ISA = qw/Exporter/; -our @EXPORT = qw/isabbrev/; - -sub isabbrev($str1, $str2) { - return 0 if !length $str1 || !length $str2; - return (substr($str1, 0, length $str1) eq substr($str2, 0, length $str1)); -} - -1; diff --git a/lib/PBot/Plugin/ActionTrigger.pm b/lib/PBot/Plugin/ActionTrigger.pm index 4705f274..64066f2b 100644 --- a/lib/PBot/Plugin/ActionTrigger.pm +++ b/lib/PBot/Plugin/ActionTrigger.pm @@ -38,7 +38,7 @@ package PBot::Plugin::ActionTrigger; use parent 'PBot::Plugin::Base'; use PBot::Imports; -use PBot::Core::Utils::IsAbbrev; +use PBot::Core::Utils::Abbrev; use DBI; use Time::Duration qw/duration/; diff --git a/lib/PBot/Plugin/Battleship.pm b/lib/PBot/Plugin/Battleship.pm index 6669d6ba..d1ce715f 100644 --- a/lib/PBot/Plugin/Battleship.pm +++ b/lib/PBot/Plugin/Battleship.pm @@ -28,7 +28,7 @@ package PBot::Plugin::Battleship; use parent 'PBot::Plugin::Base'; use PBot::Imports; -use PBot::Core::Utils::IsAbbrev; +use PBot::Core::Utils::Abbrev; use Time::Duration; use Time::HiRes qw/time/; diff --git a/lib/PBot/Plugin/WordMorph.pm b/lib/PBot/Plugin/WordMorph.pm index 96f1c566..e1398cfa 100644 --- a/lib/PBot/Plugin/WordMorph.pm +++ b/lib/PBot/Plugin/WordMorph.pm @@ -10,7 +10,7 @@ package PBot::Plugin::WordMorph; use parent 'PBot::Plugin::Base'; use PBot::Imports; -use PBot::Core::Utils::IsAbbrev; +use PBot::Core::Utils::Abbrev; use Storable; use Text::Levenshtein::XS 'distance'; diff --git a/lib/PBot/Plugin/Wordle.pm b/lib/PBot/Plugin/Wordle.pm index 75016f9e..ea317999 100644 --- a/lib/PBot/Plugin/Wordle.pm +++ b/lib/PBot/Plugin/Wordle.pm @@ -10,7 +10,7 @@ package PBot::Plugin::Wordle; use parent 'PBot::Plugin::Base'; use PBot::Imports; -use PBot::Core::Utils::IsAbbrev; +use PBot::Core::Utils::Abbrev; use Storable qw(dclone); use Time::HiRes qw/time/; diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index f8677f7b..2ef942cf 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 => 4923, - BUILD_DATE => "2025-11-05", + BUILD_REVISION => 4924, + BUILD_DATE => "2025-11-09", }; sub initialize {}