3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-26 12:42:49 +01:00

Rename IRCHandlers to Handlers

This commit is contained in:
Pragmatic Software 2021-07-23 16:57:33 -07:00
parent 0e8e642ff3
commit 98598e4203
10 changed files with 41 additions and 53 deletions

View File

@ -35,6 +35,7 @@ use PBot::Core::EventDispatcher;
use PBot::Core::EventQueue;
use PBot::Core::Factoids;
use PBot::Core::Functions;
use PBot::Core::Handlers;
use PBot::Core::IgnoreList;
use PBot::Core::Interpreter;
use PBot::Core::IRC;
@ -186,6 +187,7 @@ sub initialize {
$self->{factoids} = PBot::Core::Factoids->new(pbot => $self, filename => "$conf{data_dir}/factoids.sqlite3", %conf);
$self->{functions} = PBot::Core::Functions->new(pbot => $self, %conf);
$self->{refresher} = PBot::Core::Refresher->new(pbot => $self);
$self->{handlers} = PBot::Core::Handlers->new(pbot => $self, %conf);
$self->{ignorelist} = PBot::Core::IgnoreList->new(pbot => $self, filename => "$conf{data_dir}/ignorelist", %conf);
$self->{irchandlers} = PBot::Core::IRCHandlers->new(pbot => $self, %conf);
$self->{interpreter} = PBot::Core::Interpreter->new(pbot => $self, %conf);

View File

@ -5,7 +5,7 @@
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
# SPDX-License-Identifier: MIT
package PBot::Core::IRCHandlers::Cap;
package PBot::Core::Handlers::Cap;
use PBot::Imports;
use parent 'PBot::Core::Class';

View File

@ -5,7 +5,7 @@
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
# SPDX-License-Identifier: MIT
package PBot::Core::IRCHandlers::Channel;
package PBot::Core::Handlers::Channel;
use parent 'PBot::Core::Class';
use PBot::Imports;

View File

@ -5,7 +5,7 @@
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
# SPDX-License-Identifier: MIT
package PBot::Core::IRCHandlers::Chat;
package PBot::Core::Handlers::Chat;
use PBot::Imports;
use parent 'PBot::Core::Class';

View File

@ -5,7 +5,7 @@
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
# SPDX-License-Identifier: MIT
package PBot::Core::IRCHandlers::NickList;
package PBot::Core::Handlers::NickList;
use PBot::Imports;
use parent 'PBot::Core::Class';

View File

@ -5,7 +5,7 @@
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
# SPDX-License-Identifier: MIT
package PBot::Core::IRCHandlers::NickServ;
package PBot::Core::Handlers::NickServ;
use PBot::Imports;
use parent 'PBot::Core::Class';

View File

@ -5,7 +5,7 @@
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
# SPDX-License-Identifier: MIT
package PBot::Core::IRCHandlers::SASL;
package PBot::Core::Handlers::SASL;
use PBot::Imports;
use parent 'PBot::Core::Class';

View File

@ -5,7 +5,7 @@
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
# SPDX-License-Identifier: MIT
package PBot::Core::IRCHandlers::Server;
package PBot::Core::Handlers::Server;
use PBot::Imports;
use parent 'PBot::Core::Class';

View File

@ -5,7 +5,7 @@
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
# SPDX-License-Identifier: MIT
package PBot::Core::IRCHandlers::Users;
package PBot::Core::Handlers::Users;
use PBot::Imports;
use parent 'PBot::Core::Class';

View File

@ -1,7 +1,7 @@
# File: IRCHandlers.pm
#
# Purpose: Pipes the PBot::Core::IRC default handler through PBot::Core::EventDispatcher,
# and loads all the modules in the IRCHandlers directory.
# and registers default IRC handlers.
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
# SPDX-License-Identifier: MIT
@ -11,53 +11,10 @@ use parent 'PBot::Core::Class';
use PBot::Imports;
use PBot::Utils::LoadModules;
use Data::Dumper;
sub initialize {
my ($self, %conf) = @_;
# register all the IRC handlers in the IRCHandlers directory
$self->register_handlers(%conf);
}
# registers handlers with a PBot::Core::IRC connection
sub add_handlers {
my ($self) = @_;
# set up handlers for the IRC engine
$self->{pbot}->{conn}->add_default_handler(
sub { $self->default_handler(@_) }, 1);
# send these events to on_init()
$self->{pbot}->{conn}->add_handler([251, 252, 253, 254, 255, 302],
sub { $self->{modules}->{Server}->on_init(@_) });
# ignore these events
$self->{pbot}->{conn}->add_handler(
[
'myinfo',
'whoisserver',
'whoiscountry',
'whoischannels',
'whoisidle',
'motdstart',
'endofmotd',
'away',
],
sub { }
);
}
# registers all the IRC handler files in the IRCHandlers directory
sub register_handlers {
my ($self, %conf) = @_;
$self->{pbot}->{logger}->log("Registering IRC handlers:\n");
load_modules($self, 'PBot::Core::IRCHandlers');
# nothing to do here
}
# this default handler prepends 'irc.' to the event-type and then dispatches
@ -83,6 +40,35 @@ sub default_handler {
}
}
# registers handlers with a PBot::Core::IRC connection
sub add_handlers {
my ($self) = @_;
# set up handlers for the IRC engine
$self->{pbot}->{conn}->add_default_handler(
sub { $self->default_handler(@_) }, 1);
# send these events to on_init()
$self->{pbot}->{conn}->add_handler([251, 252, 253, 254, 255, 302],
sub { $self->{pbot}->{handlers}->{modules}->{Server}->on_init(@_) });
# ignore these events
$self->{pbot}->{conn}->add_handler(
[
'myinfo',
'whoisserver',
'whoiscountry',
'whoischannels',
'whoisidle',
'motdstart',
'endofmotd',
'away',
],
sub { }
);
}
# replace randomized gibberish in certain hostmasks with identifying information
sub normalize_hostmask {