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