mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-22 20:09:43 +01:00
Move Storage and Utils into Core
This commit is contained in:
parent
1b15ba615b
commit
7b703ccffe
@ -50,13 +50,13 @@ use PBot::Core::Registry;
|
||||
use PBot::Core::Refresher;
|
||||
use PBot::Core::SelectHandler;
|
||||
use PBot::Core::StdinReader;
|
||||
use PBot::Core::Storage::HashObject;
|
||||
use PBot::Core::Storage::DualIndexHashObject;
|
||||
use PBot::Core::Storage::DualIndexSQLiteObject;
|
||||
use PBot::Core::Updater;
|
||||
use PBot::Core::Users;
|
||||
use PBot::Core::Utils::ParseDate;
|
||||
use PBot::Core::WebPaste;
|
||||
use PBot::Storage::HashObject;
|
||||
use PBot::Storage::DualIndexHashObject;
|
||||
use PBot::Storage::DualIndexSQLiteObject;
|
||||
use PBot::Utils::ParseDate;
|
||||
|
||||
use Encode;
|
||||
use File::Basename;
|
||||
@ -195,15 +195,15 @@ sub initialize {
|
||||
$self->{messagehistory} = PBot::Core::MessageHistory->new(pbot => $self, filename => "$conf{data_dir}/message_history.sqlite3", %conf);
|
||||
$self->{modules} = PBot::Core::Modules->new(pbot => $self, %conf);
|
||||
$self->{nicklist} = PBot::Core::NickList->new(pbot => $self, %conf);
|
||||
$self->{parsedate} = PBot::Utils::ParseDate->new(pbot => $self, %conf);
|
||||
$self->{parsedate} = PBot::Core::Utils::ParseDate->new(pbot => $self, %conf);
|
||||
$self->{plugins} = PBot::Core::Plugins->new(pbot => $self, %conf);
|
||||
$self->{process_manager} = PBot::Core::ProcessManager->new(pbot => $self, %conf);
|
||||
$self->{select_handler} = PBot::Core::SelectHandler->new(pbot => $self, %conf);
|
||||
$self->{stdin_reader} = PBot::Core::StdinReader->new(pbot => $self, %conf);
|
||||
$self->{webpaste} = PBot::Core::WebPaste->new(pbot => $self, %conf);
|
||||
|
||||
# register commands in Commands directory
|
||||
$self->{commands}->register_commands;
|
||||
# load commands in Commands directory
|
||||
$self->{commands}->load_commands;
|
||||
|
||||
# register command/factoid interpreters
|
||||
$self->{interpreter}->register(sub { $self->{commands}->interpreter(@_) });
|
||||
|
@ -15,9 +15,9 @@ sub initialize {
|
||||
|
||||
my $filename = $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/spam_keywords';
|
||||
|
||||
$self->{keywords} = PBot::Storage::DualIndexHashObject->new(
|
||||
pbot => $self->{pbot},
|
||||
name => 'SpamKeywords',
|
||||
$self->{keywords} = PBot::Core::Storage::DualIndexHashObject->new(
|
||||
pbot => $self->{pbot},
|
||||
name => 'SpamKeywords',
|
||||
filename => $filename,
|
||||
);
|
||||
|
||||
|
@ -33,20 +33,20 @@ sub initialize {
|
||||
|
||||
my $data_dir = $self->{pbot}->{registry}->get_value('general', 'data_dir');
|
||||
|
||||
$self->{'ban-exemptions'} = PBot::Storage::DualIndexHashObject->new(
|
||||
$self->{'ban-exemptions'} = PBot::Core::Storage::DualIndexHashObject->new(
|
||||
pbot => $self->{pbot},
|
||||
name => 'Ban exemptions',
|
||||
filename => "$data_dir/ban-exemptions",
|
||||
);
|
||||
|
||||
$self->{banlist} = PBot::Storage::DualIndexHashObject->new(
|
||||
$self->{banlist} = PBot::Core::Storage::DualIndexHashObject->new(
|
||||
pbot => $self->{pbot},
|
||||
name => 'Ban List',
|
||||
filename => "$data_dir/banlist",
|
||||
save_queue_timeout => 15,
|
||||
);
|
||||
|
||||
$self->{quietlist} = PBot::Storage::DualIndexHashObject->new(
|
||||
$self->{quietlist} = PBot::Core::Storage::DualIndexHashObject->new(
|
||||
pbot => $self->{pbot},
|
||||
name => 'Quiet List',
|
||||
filename => "$data_dir/quietlist",
|
||||
|
@ -17,7 +17,7 @@ sub initialize {
|
||||
my $filename = $conf{filename} // $self->{pbot}->{registry}->get_value('general', 'data_dir') . '/capabilities';
|
||||
|
||||
# capabilities hash table
|
||||
$self->{caps} = PBot::Storage::HashObject->new(
|
||||
$self->{caps} = PBot::Core::Storage::HashObject->new(
|
||||
pbot => $self->{pbot},
|
||||
name => 'Capabilities',
|
||||
filename => $filename,
|
||||
|
@ -13,7 +13,7 @@ use PBot::Imports;
|
||||
sub initialize {
|
||||
my ($self, %conf) = @_;
|
||||
|
||||
$self->{storage} = PBot::Storage::HashObject->new(
|
||||
$self->{storage} = PBot::Core::Storage::HashObject->new(
|
||||
pbot => $self->{pbot},
|
||||
name => 'Channels',
|
||||
filename => $conf{filename}
|
||||
|
@ -11,7 +11,7 @@ use parent 'PBot::Core::Class';
|
||||
|
||||
use PBot::Imports;
|
||||
|
||||
use PBot::Utils::LoadModules qw/load_modules/;
|
||||
use PBot::Core::Utils::LoadModules qw/load_modules/;
|
||||
|
||||
sub initialize {
|
||||
my ($self, %conf) = @_;
|
||||
@ -20,7 +20,7 @@ sub initialize {
|
||||
$self->{commands} = {};
|
||||
|
||||
# command metadata stored as a HashObject
|
||||
$self->{metadata} = PBot::Storage::HashObject->new(
|
||||
$self->{metadata} = PBot::Core::Storage::HashObject->new(
|
||||
pbot => $self->{pbot},
|
||||
name => 'Command metadata',
|
||||
filename => $conf{filename},
|
||||
|
@ -18,7 +18,7 @@ use Storable;
|
||||
use LWP::UserAgent;
|
||||
use JSON;
|
||||
|
||||
use PBot::Utils::SafeFilename;
|
||||
use PBot::Core::Utils::SafeFilename;
|
||||
|
||||
our %factoid_metadata_capabilities = (
|
||||
created_on => 'botowner',
|
||||
|
@ -12,7 +12,7 @@ use parent 'PBot::Core::Class';
|
||||
|
||||
use PBot::Imports;
|
||||
|
||||
use PBot::Utils::PriorityQueue;
|
||||
use PBot::Core::Utils::PriorityQueue;
|
||||
|
||||
sub initialize {
|
||||
my ($self, %conf) = @_;
|
||||
@ -47,7 +47,7 @@ sub register_handler {
|
||||
|
||||
# create new priority-queue for event-name if one doesn't exist
|
||||
if (not exists $self->{handlers}->{$event_name}) {
|
||||
$self->{handlers}->{$event_name} = PBot::Utils::PriorityQueue->new(pbot => $self->{pbot});
|
||||
$self->{handlers}->{$event_name} = PBot::Core::Utils::PriorityQueue->new(pbot => $self->{pbot});
|
||||
}
|
||||
|
||||
# add the event handler
|
||||
|
@ -13,13 +13,13 @@ use parent 'PBot::Core::Class';
|
||||
|
||||
use PBot::Imports;
|
||||
|
||||
use PBot::Utils::PriorityQueue;
|
||||
use PBot::Core::Utils::PriorityQueue;
|
||||
|
||||
use Time::HiRes qw/time/;
|
||||
|
||||
sub initialize {
|
||||
my ($self, %conf) = @_;
|
||||
$self->{event_queue} = PBot::Utils::PriorityQueue->new(pbot => $self->{pbot});
|
||||
$self->{event_queue} = PBot::Core::Utils::PriorityQueue->new(pbot => $self->{pbot});
|
||||
}
|
||||
|
||||
# returns seconds until upcoming event.
|
||||
|
@ -17,8 +17,8 @@ use POSIX qw(strftime);
|
||||
use Text::ParseWords;
|
||||
use JSON;
|
||||
|
||||
use PBot::Utils::Indefinite;
|
||||
use PBot::Utils::ValidateString;
|
||||
use PBot::Core::Utils::Indefinite;
|
||||
use PBot::Core::Utils::ValidateString;
|
||||
|
||||
our %factoid_metadata = (
|
||||
'action' => 'TEXT',
|
||||
@ -65,7 +65,7 @@ sub initialize {
|
||||
|
||||
$self->{pbot} = $self->{pbot};
|
||||
|
||||
$self->{storage} = PBot::Storage::DualIndexSQLiteObject->new(
|
||||
$self->{storage} = PBot::Core::Storage::DualIndexSQLiteObject->new(
|
||||
pbot => $self->{pbot},
|
||||
name => 'Factoids',
|
||||
filename => $filename,
|
||||
|
@ -10,7 +10,7 @@ use parent 'PBot::Core::Class';
|
||||
|
||||
use PBot::Imports;
|
||||
|
||||
use PBot::Utils::LoadModules qw/load_modules/;
|
||||
use PBot::Core::Utils::LoadModules qw/load_modules/;
|
||||
|
||||
sub initialize {
|
||||
my ($self, %conf) = @_;
|
||||
|
@ -17,7 +17,7 @@ sub initialize {
|
||||
|
||||
$self->{filename} = $conf{filename};
|
||||
|
||||
$self->{storage} = PBot::Storage::DualIndexHashObject->new(
|
||||
$self->{storage} = PBot::Core::Storage::DualIndexHashObject->new(
|
||||
pbot => $self->{pbot},
|
||||
name => 'IgnoreList',
|
||||
filename => $self->{filename}
|
||||
|
@ -22,7 +22,7 @@ use Time::Duration;
|
||||
use Encode;
|
||||
use Unicode::Truncate;
|
||||
|
||||
use PBot::Utils::ValidateString;
|
||||
use PBot::Core::Utils::ValidateString;
|
||||
|
||||
sub initialize {
|
||||
my ($self, %conf) = @_;
|
||||
|
@ -16,8 +16,8 @@ use PBot::Imports;
|
||||
|
||||
use PBot::Core::MessageHistory::Constants ':all';
|
||||
|
||||
use PBot::Utils::SQLiteLogger;
|
||||
use PBot::Utils::SQLiteLoggerLayer;
|
||||
use PBot::Core::Utils::SQLiteLogger;
|
||||
use PBot::Core::Utils::SQLiteLoggerLayer;
|
||||
|
||||
use DBI;
|
||||
use Carp qw/shortmess/;
|
||||
@ -60,7 +60,7 @@ sub sqlite_debug_trigger {
|
||||
my ($self, $section, $item, $newvalue) = @_;
|
||||
|
||||
if ($newvalue) {
|
||||
open $self->{trace_layer}, '>:via(PBot::Utils::SQLiteLoggerLayer)', PBot::Utils::SQLiteLogger->new(pbot => $self->{pbot});
|
||||
open $self->{trace_layer}, '>:via(PBot::Core::Utils::SQLiteLoggerLayer)', PBot::Core::Utils::SQLiteLogger->new(pbot => $self->{pbot});
|
||||
} else {
|
||||
close $self->{trace_layer} if $self->{trace_layer};
|
||||
delete $self->{trace_layer};
|
||||
@ -80,7 +80,7 @@ sub begin {
|
||||
eval {
|
||||
my $sqlite_debug = $self->{pbot}->{registry}->get_value('messagehistory', 'sqlite_debug');
|
||||
if ($sqlite_debug) {
|
||||
open $self->{trace_layer}, '>:via(PBot::Utils::SQLiteLoggerLayer)', PBot::Utils::SQLiteLogger->new(pbot => $self->{pbot});
|
||||
open $self->{trace_layer}, '>:via(PBot::Core::Utils::SQLiteLoggerLayer)', PBot::Core::Utils::SQLiteLogger->new(pbot => $self->{pbot});
|
||||
$self->{dbh}->trace($self->{dbh}->parse_trace_flags("SQL|$sqlite_debug"), $self->{trace_layer});
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ sub initialize {
|
||||
my $filename = $conf{filename} // Carp::croak("Missing filename configuration item in " . __FILE__);
|
||||
|
||||
# registry is stored as a dual-index hash object
|
||||
$self->{storage} = PBot::Storage::DualIndexHashObject->new(
|
||||
$self->{storage} = PBot::Core::Storage::DualIndexHashObject->new(
|
||||
pbot => $self->{pbot},
|
||||
name => 'Registry',
|
||||
filename => $filename,
|
||||
|
@ -10,12 +10,12 @@
|
||||
# Data is stored in working memory for lightning fast performance. If you have
|
||||
# a huge amount of data, consider using DualIndexSQLiteObject instead.
|
||||
#
|
||||
# If a filename is provided, data is written to a file after any modifications.
|
||||
# If a filename is provided, data is written to the file after any modifications.
|
||||
|
||||
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
package PBot::Storage::DualIndexHashObject;
|
||||
package PBot::Core::Storage::DualIndexHashObject;
|
||||
|
||||
use PBot::Imports;
|
||||
|
@ -11,12 +11,12 @@
|
||||
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
package PBot::Storage::DualIndexSQLiteObject;
|
||||
package PBot::Core::Storage::DualIndexSQLiteObject;
|
||||
|
||||
use PBot::Imports;
|
||||
|
||||
use PBot::Utils::SQLiteLogger;
|
||||
use PBot::Utils::SQLiteLoggerLayer;
|
||||
use PBot::Core::Utils::SQLiteLogger;
|
||||
use PBot::Core::Utils::SQLiteLoggerLayer;
|
||||
|
||||
use DBI;
|
||||
use Text::Levenshtein qw(fastdistance);
|
||||
@ -63,7 +63,7 @@ sub begin {
|
||||
|
||||
eval {
|
||||
my $sqlite_debug = $self->{pbot}->{registry}->get_value('dualindexsqliteobject', "debug_$self->{name}");
|
||||
open $self->{trace_layer}, '>:via(PBot::Utils::SQLiteLoggerLayer)', PBot::Utils::SQLiteLogger->new(pbot => $self->{pbot});
|
||||
open $self->{trace_layer}, '>:via(PBot::Core::Utils::SQLiteLoggerLayer)', PBot::Core::Utils::SQLiteLogger->new(pbot => $self->{pbot});
|
||||
$self->{dbh}->trace($self->{dbh}->parse_trace_flags("SQL|$sqlite_debug"), $self->{trace_layer});
|
||||
};
|
||||
|
@ -6,12 +6,12 @@
|
||||
# displaying index key.
|
||||
#
|
||||
# Data is stored in working memory for lightning fast performance. If a filename
|
||||
# is provided, data is written to a file after any modifications.
|
||||
# is provided, data is written to the file after any modifications.
|
||||
|
||||
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
package PBot::Storage::HashObject;
|
||||
package PBot::Core::Storage::HashObject;
|
||||
|
||||
use PBot::Imports;
|
||||
|
@ -13,7 +13,7 @@ use PBot::Imports;
|
||||
sub initialize {
|
||||
my ($self, %conf) = @_;
|
||||
|
||||
$self->{storage} = PBot::Storage::HashObject->new(
|
||||
$self->{storage} = PBot::Core::Storage::HashObject->new(
|
||||
pbot => $conf{pbot},
|
||||
name => 'Users',
|
||||
filename => $conf{filename},
|
||||
|
@ -2,7 +2,7 @@
|
||||
#
|
||||
# Purpose: Implements a/an inflexion for nouns.
|
||||
|
||||
package PBot::Utils::Indefinite;
|
||||
package PBot::Core::Utils::Indefinite;
|
||||
|
||||
use PBot::Imports;
|
||||
|
@ -7,7 +7,7 @@
|
||||
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
package PBot::Utils::LWPUserAgentCached;
|
||||
package PBot::Core::Utils::LWPUserAgentCached;
|
||||
|
||||
use PBot::Imports;
|
||||
|
@ -6,7 +6,7 @@
|
||||
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
package PBot::Utils::LoadModules;
|
||||
package PBot::Core::Utils::LoadModules;
|
||||
|
||||
use PBot::Imports;
|
||||
|
@ -6,7 +6,7 @@
|
||||
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
package PBot::Utils::ParseDate;
|
||||
package PBot::Core::Utils::ParseDate;
|
||||
|
||||
use PBot::Imports;
|
||||
|
@ -5,7 +5,7 @@
|
||||
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
package PBot::Utils::PriorityQueue;
|
||||
package PBot::Core::Utils::PriorityQueue;
|
||||
|
||||
use PBot::Imports;
|
||||
|
@ -6,7 +6,7 @@
|
||||
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
package PBot::Utils::SQLiteLogger;
|
||||
package PBot::Core::Utils::SQLiteLogger;
|
||||
|
||||
use PBot::Imports;
|
||||
|
@ -5,7 +5,7 @@
|
||||
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
package PBot::Utils::SQLiteLoggerLayer;
|
||||
package PBot::Core::Utils::SQLiteLoggerLayer;
|
||||
|
||||
use PBot::Imports;
|
||||
|
@ -6,7 +6,7 @@
|
||||
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
package PBot::Utils::SafeFilename;
|
||||
package PBot::Core::Utils::SafeFilename;
|
||||
|
||||
use PBot::Imports;
|
||||
|
@ -7,7 +7,7 @@
|
||||
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
package PBot::Utils::ValidateString;
|
||||
package PBot::Core::Utils::ValidateString;
|
||||
|
||||
use PBot::Imports;
|
||||
|
@ -1,6 +1,6 @@
|
||||
# File: ParseDate.pm
|
||||
#
|
||||
# Purpose: Just a simple interface to test/play with PBot::Utils::ParseDate
|
||||
# Purpose: Just a simple interface to test/play with PBot::Core::Utils::ParseDate
|
||||
# and make sure it's working properly.
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
||||
|
@ -20,7 +20,7 @@ use Getopt::Long qw(GetOptionsFromArray);
|
||||
|
||||
use PBot::Plugin::Quotegrabs::Storage::SQLite; # use SQLite backend for quotegrabs database
|
||||
#use PBot::Plugin::Quotegrabs::Storage::Hashtable; # use Perl hashtable backend for quotegrabs database
|
||||
use PBot::Utils::ValidateString;
|
||||
use PBot::Core::Utils::ValidateString;
|
||||
|
||||
use POSIX qw(strftime);
|
||||
|
||||
|
@ -10,7 +10,7 @@ use parent 'PBot::Plugin::Base';
|
||||
|
||||
use PBot::Imports;
|
||||
|
||||
use PBot::Utils::LWPUserAgentCached;
|
||||
use PBot::Core::Utils::LWPUserAgentCached;
|
||||
use XML::LibXML;
|
||||
use Getopt::Long qw(GetOptionsFromArray);
|
||||
|
||||
@ -72,7 +72,7 @@ sub get_weather {
|
||||
'default_expires_in' => 3600
|
||||
);
|
||||
|
||||
my $ua = PBot::Utils::LWPUserAgentCached->new(\%cache_opt, timeout => 10);
|
||||
my $ua = PBot::Core::Utils::LWPUserAgentCached->new(\%cache_opt, timeout => 10);
|
||||
my $response = $ua->get("http://rss.accuweather.com/rss/liveweather_rss.asp?metric=0&locCode=$location");
|
||||
|
||||
my $xml;
|
||||
|
@ -9,7 +9,7 @@ package PBot::Plugin::Wttr;
|
||||
use parent 'PBot::Plugin::Base';
|
||||
|
||||
use PBot::Imports;
|
||||
use PBot::Utils::LWPUserAgentCached;
|
||||
use PBot::Core::Utils::LWPUserAgentCached;
|
||||
|
||||
use JSON;
|
||||
use URI::Escape qw/uri_escape_utf8/;
|
||||
@ -113,7 +113,7 @@ sub get_wttr {
|
||||
|
||||
my $location_uri = uri_escape_utf8 $location;
|
||||
|
||||
my $ua = PBot::Utils::LWPUserAgentCached->new(\%cache_opt, timeout => 30);
|
||||
my $ua = PBot::Core::Utils::LWPUserAgentCached->new(\%cache_opt, timeout => 30);
|
||||
my $response = $ua->get("http://wttr.in/$location_uri?format=j1&m");
|
||||
|
||||
my $json;
|
||||
|
Loading…
Reference in New Issue
Block a user