1
0
Fork 0
mirror of https://github.com/perlbot/perlbuut synced 2025-06-07 15:55:42 -04:00

Allow different defaults per channel

This commit is contained in:
Ryan Voots 2016-10-01 18:47:34 -04:00
parent 2c593cb8c5
commit ae81c8dff8
4 changed files with 56 additions and 6 deletions

View file

@ -33,7 +33,7 @@ http_plugin_port 1092
# Change this to be bot specific? # Change this to be bot specific?
<plugin_manager> <plugin_manager>
default_plugin factoids default_plugin default
</plugin_manager> </plugin_manager>
<bot perlbot> <bot perlbot>

View file

@ -24,14 +24,12 @@ server "*" {
plugin "eval" {addressed: false; } plugin "eval" {addressed: false; }
plugin "deparse" {addressed: false; } plugin "deparse" {addressed: false; }
plugin "badfacts" {addressed: false; } plugin "badfacts" {addressed: false; }
plugin "default" {plugin: "nfacts"}
} }
channel "#buubot" { channel "#buubot" {
plugin "eval" {addressed: false; } plugin "eval" {addressed: false; }
plugin "deparse" {addressed: false; } plugin "deparse" {addressed: false; }
} }
channel "#regex" {
plugin "badfacts" {addressed: false; }
}
} }
server "*.freenode.net" { server "*.freenode.net" {
channel "#perlbot" { channel "#perlbot" {
@ -53,5 +51,6 @@ server "*.freenode.net" {
plugins: false; plugins: false;
filtersep: true; filtersep: true;
} }
plugin "default" {plugin: "nfacts"; }
} }
} }

51
plugins/default.pm Normal file
View file

@ -0,0 +1,51 @@
package Bot::BB3::Plugin::Default;
use strict;
no warnings 'void';
use Data::Dumper;
our $pname = "default";
sub get_conf_for_channel {
my ($self, $pm, $server, $channel) = @_;
my $conf = $pm->plugin_conf($pname, $server, $channel);
return $conf;
}
sub new {
my( $class ) = @_;
my $self = bless {}, $class;
$self->{name} = $pname;
$self->{opts} = {
command => 1,
};
return $self;
}
sub command {
my ($self, $_said, $pm) = @_;
my $said = {%$_said}; # copy it so we can mutate it later
my $conf = $self->get_conf_for_channel($pm, $said->{server}, $said->{channel});
if ($said->{addressed}) {
my $plug_name = $conf->{plugin} // 'fact';
my $plugin = $pm->get_plugin( $plug_name );
$said->{body} =~ s/^default //g;
$said->{recommended_args} = [ split /\s+/, $said->{body} ];
local $@;
my( $status, $results ) = eval { $plugin->command( $said, $pm ) };
my $err = $@;
return ($status, $results);
}
return;
}
"Bot::BB3::Plugin::Default";
__DATA__
default plugin handler that supports per channel configurations

View file

@ -95,9 +95,9 @@ sub handle {
my $prefix = $conf->{prefix} || "!"; my $prefix = $conf->{prefix} || "!";
my $regex = qr/^\Q$prefix\E(?<fact>[^@].*?)(?:\s@\s*(?<user>\S*))?$/; my $regex = qr/^\Q$prefix\E(?<fact>[^@].*?)(?:\s@\s*(?<user>\S*)\s*)?$/;
if ($said->{body} =~ /^\Q$prefix\E(?<fact>[^@].*?)(?:\s@\s*(?<user>\S*))?$/ || if ($said->{body} =~ /^\Q$prefix\E(?<fact>[^@].*?)(?:\s@\s*(?<user>\S*)\s*)?$/ ||
$said->{body} =~ /^\Q$prefix\E!@(?<user>\S+)\s+(?<fact>.+)$/) { $said->{body} =~ /^\Q$prefix\E!@(?<user>\S+)\s+(?<fact>.+)$/) {
my $fact = $+{fact}; my $fact = $+{fact};
my $user = $+{user}; my $user = $+{user};