3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-01 16:39:27 +01:00
pbot/lib/PBot/Core/Commands/Channels.pm

98 lines
3.8 KiB
Perl
Raw Normal View History

2021-07-21 21:43:30 +02:00
# File: Channels.pm
#
# Purpose: Commands to manage list of channels, and channel metadata.
2023-02-21 06:31:52 +01:00
# SPDX-FileCopyrightText: 2010-2023 Pragmatic Software <pragma78@gmail.com>
2021-07-21 21:43:30 +02:00
# SPDX-License-Identifier: MIT
package PBot::Core::Commands::Channels;
use PBot::Imports;
use parent 'PBot::Core::Class';
2021-07-21 21:43:30 +02:00
sub initialize($self, %conf) {
2021-07-21 21:43:30 +02:00
# register commands
$self->{pbot}->{commands}->register(sub { $self->cmd_join(@_) }, "join", 1);
$self->{pbot}->{commands}->register(sub { $self->cmd_part(@_) }, "part", 1);
$self->{pbot}->{commands}->register(sub { $self->cmd_set(@_) }, "chanset", 1);
$self->{pbot}->{commands}->register(sub { $self->cmd_unset(@_) }, "chanunset", 1);
$self->{pbot}->{commands}->register(sub { $self->cmd_add(@_) }, "chanadd", 1);
$self->{pbot}->{commands}->register(sub { $self->cmd_remove(@_) }, "chanrem", 1);
$self->{pbot}->{commands}->register(sub { $self->cmd_list(@_) }, "chanlist", 1);
# add capabilities to admin group
$self->{pbot}->{capabilities}->add('admin', 'can-join', 1);
$self->{pbot}->{capabilities}->add('admin', 'can-part', 1);
$self->{pbot}->{capabilities}->add('admin', 'can-chanlist', 1);
}
sub cmd_join($self, $context) {
2021-07-21 21:43:30 +02:00
foreach my $channel (split /[\s+,]/, $context->{arguments}) {
$self->{pbot}->{logger}->log("$context->{hostmask} made me join $channel\n");
$self->{pbot}->{channels}->join($channel);
}
return "/msg $context->{nick} Joining $context->{arguments}";
}
sub cmd_part($self, $context) {
2021-07-21 21:43:30 +02:00
$context->{arguments} = $context->{from} if not $context->{arguments};
foreach my $channel (split /[\s+,]/, $context->{arguments}) {
$self->{pbot}->{logger}->log("$context->{hostmask} made me part $channel\n");
$self->{pbot}->{channels}->part($channel);
}
return "/msg $context->{nick} Parting $context->{arguments}";
}
sub cmd_set($self, $context) {
2021-07-21 21:43:30 +02:00
my ($channel, $key, $value) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 3);
return "Usage: chanset <channel> [key [value]]" if not defined $channel;
return $self->{pbot}->{channels}->{storage}->set($channel, $key, $value);
}
sub cmd_unset($self, $context) {
2021-07-21 21:43:30 +02:00
my ($channel, $key) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
return "Usage: chanunset <channel> <key>" if not defined $channel or not defined $key;
return $self->{pbot}->{channels}->{storage}->unset($channel, $key);
}
sub cmd_add($self, $context) {
2021-07-21 21:43:30 +02:00
return "Usage: chanadd <channel>" if not length $context->{arguments};
my $data = {
enabled => 1,
chanop => 0,
permop => 0
};
return $self->{pbot}->{channels}->{storage}->add($context->{arguments}, $data);
}
sub cmd_remove($self, $context) {
2021-07-21 21:43:30 +02:00
return "Usage: chanrem <channel>" if not length $context->{arguments};
# clear banlists
$self->{pbot}->{banlist}->{banlist}->remove($context->{arguments});
$self->{pbot}->{banlist}->{quietlist}->remove($context->{arguments});
$self->{pbot}->{event_queue}->dequeue_event("unban $context->{arguments} .*");
$self->{pbot}->{event_queue}->dequeue_event("unmute $context->{arguments} .*");
# TODO: ignores, etc?
2022-01-02 06:30:20 +01:00
return $self->{pbot}->{channels}->{storage}->remove($context->{arguments});
2021-07-21 21:43:30 +02:00
}
sub cmd_list($self, $context) {
2021-07-21 21:43:30 +02:00
my $result;
foreach my $channel (sort $self->{pbot}->{channels}->{storage}->get_keys) {
$result .= $self->{pbot}->{channels}->{storage}->get_key_name($channel) . ': {';
my $comma = ' ';
foreach my $key (sort $self->{pbot}->{channels}->{storage}->get_keys($channel)) {
$result .= "$comma$key => " . $self->{pbot}->{channels}->{storage}->get_data($channel, $key);
$comma = ', ';
}
$result .= " }\n";
}
return $result;
}
1;