2010-03-22 07:33:44 +00:00
|
|
|
# File: Channels.pm
|
|
|
|
#
|
|
|
|
# Purpose: Manages list of channels and auto-joins.
|
|
|
|
|
2021-07-10 15:00:22 -07:00
|
|
|
# SPDX-FileCopyrightText: 2021 Pragmatic Software <pragma78@gmail.com>
|
|
|
|
# SPDX-License-Identifier: MIT
|
2017-03-05 21:33:31 +00:00
|
|
|
|
2021-07-20 22:44:51 -07:00
|
|
|
package PBot::Core::Channels;
|
|
|
|
use parent 'PBot::Core::Class';
|
2010-03-22 07:33:44 +00:00
|
|
|
|
2021-06-18 21:23:34 -07:00
|
|
|
use PBot::Imports;
|
2019-07-10 18:40:53 -07:00
|
|
|
|
2010-03-22 07:33:44 +00:00
|
|
|
sub initialize {
|
2020-02-15 14:38:32 -08:00
|
|
|
my ($self, %conf) = @_;
|
2021-07-23 18:26:45 -07:00
|
|
|
|
2021-07-23 19:22:25 -07:00
|
|
|
$self->{storage} = PBot::Core::Storage::HashObject->new(
|
2021-07-23 18:26:45 -07:00
|
|
|
pbot => $self->{pbot},
|
|
|
|
name => 'Channels',
|
|
|
|
filename => $conf{filename}
|
|
|
|
);
|
|
|
|
|
2021-07-09 14:39:35 -07:00
|
|
|
$self->{storage}->load;
|
2014-03-05 14:28:58 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 21:33:49 -07:00
|
|
|
sub join {
|
|
|
|
my ($self, $channels) = @_;
|
|
|
|
|
2021-07-13 14:02:14 -07:00
|
|
|
return if not $channels;
|
|
|
|
|
2020-04-28 21:33:49 -07:00
|
|
|
$self->{pbot}->{conn}->join($channels);
|
|
|
|
|
|
|
|
foreach my $channel (split /,/, $channels) {
|
|
|
|
$channel = lc $channel;
|
2021-07-23 18:26:45 -07:00
|
|
|
|
2020-04-28 21:33:49 -07:00
|
|
|
$self->{pbot}->{event_dispatcher}->dispatch_event('pbot.join', {channel => $channel});
|
|
|
|
|
|
|
|
delete $self->{pbot}->{chanops}->{is_opped}->{$channel};
|
|
|
|
delete $self->{pbot}->{chanops}->{op_requested}->{$channel};
|
|
|
|
|
2021-07-09 14:39:35 -07:00
|
|
|
if ($self->{storage}->exists($channel) and $self->{storage}->get_data($channel, 'permop')) {
|
2020-05-03 19:27:04 -07:00
|
|
|
$self->{pbot}->{chanops}->gain_ops($channel);
|
2020-04-28 21:33:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$self->{pbot}->{conn}->mode($channel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub part {
|
|
|
|
my ($self, $channel) = @_;
|
|
|
|
$channel = lc $channel;
|
|
|
|
$self->{pbot}->{event_dispatcher}->dispatch_event('pbot.part', {channel => $channel});
|
|
|
|
$self->{pbot}->{conn}->part($channel);
|
|
|
|
delete $self->{pbot}->{chanops}->{is_opped}->{$channel};
|
|
|
|
delete $self->{pbot}->{chanops}->{op_requested}->{$channel};
|
|
|
|
}
|
|
|
|
|
2019-12-21 19:43:05 -08:00
|
|
|
sub autojoin {
|
2020-02-15 14:38:32 -08:00
|
|
|
my ($self) = @_;
|
2021-07-13 14:02:14 -07:00
|
|
|
|
2020-02-15 14:38:32 -08:00
|
|
|
return if $self->{pbot}->{joined_channels};
|
2021-07-13 14:02:14 -07:00
|
|
|
|
2020-02-15 14:38:32 -08:00
|
|
|
my $channels;
|
2021-07-09 14:39:35 -07:00
|
|
|
foreach my $channel ($self->{storage}->get_keys) {
|
|
|
|
if ($self->{storage}->get_data($channel, 'enabled')) {
|
|
|
|
$channels .= $self->{storage}->get_key_name($channel) . ',';
|
2020-04-28 21:33:49 -07:00
|
|
|
}
|
2019-12-21 19:43:05 -08:00
|
|
|
}
|
2021-07-13 14:02:14 -07:00
|
|
|
|
|
|
|
return if not $channels;
|
|
|
|
|
2020-02-15 14:38:32 -08:00
|
|
|
$self->{pbot}->{logger}->log("Joining channels: $channels\n");
|
2020-04-28 21:33:49 -07:00
|
|
|
$self->join($channels);
|
2020-02-15 14:38:32 -08:00
|
|
|
$self->{pbot}->{joined_channels} = 1;
|
2019-12-21 19:43:05 -08:00
|
|
|
}
|
|
|
|
|
2016-07-01 12:58:29 -07:00
|
|
|
sub is_active {
|
2020-02-15 14:38:32 -08:00
|
|
|
my ($self, $channel) = @_;
|
|
|
|
# returns undef if channel doesn't exist; otherwise, the value of 'enabled'
|
2021-07-09 14:39:35 -07:00
|
|
|
return $self->{storage}->get_data($channel, 'enabled');
|
2016-07-01 12:58:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
sub is_active_op {
|
2020-02-15 14:38:32 -08:00
|
|
|
my ($self, $channel) = @_;
|
2021-07-09 14:39:35 -07:00
|
|
|
return $self->is_active($channel) && $self->{storage}->get_data($channel, 'chanop');
|
2016-07-01 12:58:29 -07:00
|
|
|
}
|
|
|
|
|
2018-08-05 22:44:46 -07:00
|
|
|
sub get_meta {
|
2020-02-15 14:38:32 -08:00
|
|
|
my ($self, $channel, $key) = @_;
|
2021-07-09 14:39:35 -07:00
|
|
|
return $self->{storage}->get_data($channel, $key);
|
2010-03-22 07:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|