mirror of
https://github.com/pragma-/pbot.git
synced 2025-11-13 04:57:26 +01:00
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.
This commit is contained in:
parent
2afc6210c5
commit
ace9991d94
@ -9,7 +9,7 @@ package PBot::Core::Commands::AntiSpam;
|
|||||||
use parent 'PBot::Core::Class';
|
use parent 'PBot::Core::Class';
|
||||||
|
|
||||||
use PBot::Imports;
|
use PBot::Imports;
|
||||||
use PBot::Core::Utils::IsAbbrev;
|
use PBot::Core::Utils::Abbrev;
|
||||||
|
|
||||||
use Time::HiRes qw/gettimeofday/;
|
use Time::HiRes qw/gettimeofday/;
|
||||||
use POSIX qw/strftime/;
|
use POSIX qw/strftime/;
|
||||||
|
|||||||
@ -10,7 +10,7 @@ use parent 'PBot::Core::Class';
|
|||||||
|
|
||||||
use PBot::Imports;
|
use PBot::Imports;
|
||||||
|
|
||||||
use PBot::Core::Utils::IsAbbrev;
|
use PBot::Core::Utils::Abbrev;
|
||||||
use PBot::Core::MessageHistory::Constants ':all';
|
use PBot::Core::MessageHistory::Constants ':all';
|
||||||
|
|
||||||
use Time::HiRes qw/gettimeofday/;
|
use Time::HiRes qw/gettimeofday/;
|
||||||
|
|||||||
@ -10,7 +10,7 @@ package PBot::Core::Commands::BlackList;
|
|||||||
use parent 'PBot::Core::Class';
|
use parent 'PBot::Core::Class';
|
||||||
|
|
||||||
use PBot::Imports;
|
use PBot::Imports;
|
||||||
use PBot::Core::Utils::IsAbbrev;
|
use PBot::Core::Utils::Abbrev;
|
||||||
|
|
||||||
sub initialize($self, %conf) {
|
sub initialize($self, %conf) {
|
||||||
$self->{pbot}->{commands}->register(sub { $self->cmd_blacklist(@_) }, "blacklist", 1);
|
$self->{pbot}->{commands}->register(sub { $self->cmd_blacklist(@_) }, "blacklist", 1);
|
||||||
|
|||||||
@ -10,7 +10,7 @@ package PBot::Core::Commands::Capabilities;
|
|||||||
use PBot::Imports;
|
use PBot::Imports;
|
||||||
use parent 'PBot::Core::Class';
|
use parent 'PBot::Core::Class';
|
||||||
|
|
||||||
use PBot::Core::Utils::IsAbbrev;
|
use PBot::Core::Utils::Abbrev;
|
||||||
|
|
||||||
sub initialize($self, %conf) {
|
sub initialize($self, %conf) {
|
||||||
$self->{pbot}->{commands}->register(sub { $self->cmd_cap(@_) }, "cap");
|
$self->{pbot}->{commands}->register(sub { $self->cmd_cap(@_) }, "cap");
|
||||||
|
|||||||
@ -10,7 +10,7 @@ package PBot::Core::Commands::EventQueue;
|
|||||||
use PBot::Imports;
|
use PBot::Imports;
|
||||||
use parent 'PBot::Core::Class';
|
use parent 'PBot::Core::Class';
|
||||||
|
|
||||||
use PBot::Core::Utils::IsAbbrev;
|
use PBot::Core::Utils::Abbrev;
|
||||||
|
|
||||||
use Time::Duration;
|
use Time::Duration;
|
||||||
|
|
||||||
|
|||||||
35
lib/PBot/Core/Utils/Abbrev.pm
Normal file
35
lib/PBot/Core/Utils/Abbrev.pm
Normal file
@ -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 <pragma78@gmail.com>
|
||||||
|
# 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;
|
||||||
@ -1,21 +0,0 @@
|
|||||||
# File: IsAbbrev.pm
|
|
||||||
#
|
|
||||||
# Purpose: Check is a string is an abbreviation of another string.
|
|
||||||
|
|
||||||
# SPDX-FileCopyrightText: 2017-2023 Pragmatic Software <pragma78@gmail.com>
|
|
||||||
# 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;
|
|
||||||
@ -38,7 +38,7 @@ package PBot::Plugin::ActionTrigger;
|
|||||||
use parent 'PBot::Plugin::Base';
|
use parent 'PBot::Plugin::Base';
|
||||||
|
|
||||||
use PBot::Imports;
|
use PBot::Imports;
|
||||||
use PBot::Core::Utils::IsAbbrev;
|
use PBot::Core::Utils::Abbrev;
|
||||||
|
|
||||||
use DBI;
|
use DBI;
|
||||||
use Time::Duration qw/duration/;
|
use Time::Duration qw/duration/;
|
||||||
|
|||||||
@ -28,7 +28,7 @@ package PBot::Plugin::Battleship;
|
|||||||
use parent 'PBot::Plugin::Base';
|
use parent 'PBot::Plugin::Base';
|
||||||
|
|
||||||
use PBot::Imports;
|
use PBot::Imports;
|
||||||
use PBot::Core::Utils::IsAbbrev;
|
use PBot::Core::Utils::Abbrev;
|
||||||
|
|
||||||
use Time::Duration;
|
use Time::Duration;
|
||||||
use Time::HiRes qw/time/;
|
use Time::HiRes qw/time/;
|
||||||
|
|||||||
@ -10,7 +10,7 @@ package PBot::Plugin::WordMorph;
|
|||||||
use parent 'PBot::Plugin::Base';
|
use parent 'PBot::Plugin::Base';
|
||||||
|
|
||||||
use PBot::Imports;
|
use PBot::Imports;
|
||||||
use PBot::Core::Utils::IsAbbrev;
|
use PBot::Core::Utils::Abbrev;
|
||||||
|
|
||||||
use Storable;
|
use Storable;
|
||||||
use Text::Levenshtein::XS 'distance';
|
use Text::Levenshtein::XS 'distance';
|
||||||
|
|||||||
@ -10,7 +10,7 @@ package PBot::Plugin::Wordle;
|
|||||||
use parent 'PBot::Plugin::Base';
|
use parent 'PBot::Plugin::Base';
|
||||||
|
|
||||||
use PBot::Imports;
|
use PBot::Imports;
|
||||||
use PBot::Core::Utils::IsAbbrev;
|
use PBot::Core::Utils::Abbrev;
|
||||||
|
|
||||||
use Storable qw(dclone);
|
use Storable qw(dclone);
|
||||||
use Time::HiRes qw/time/;
|
use Time::HiRes qw/time/;
|
||||||
|
|||||||
@ -25,8 +25,8 @@ use PBot::Imports;
|
|||||||
# These are set by the /misc/update_version script
|
# These are set by the /misc/update_version script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 4923,
|
BUILD_REVISION => 4924,
|
||||||
BUILD_DATE => "2025-11-05",
|
BUILD_DATE => "2025-11-09",
|
||||||
};
|
};
|
||||||
|
|
||||||
sub initialize {}
|
sub initialize {}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user