3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-20 02:49:49 +01:00

pbot: allowed bot trigger to be customizable from pbot.pl; bot registry coming soon...

This commit is contained in:
Pragmatic Software 2011-01-30 03:22:00 +00:00
parent cb2c17f636
commit 805832d977
5 changed files with 21 additions and 16 deletions

View File

@ -79,7 +79,7 @@ sub on_msg {
my ($nick, $host) = ($event->nick, $event->host); my ($nick, $host) = ($event->nick, $event->host);
my $text = $event->{args}[0]; my $text = $event->{args}[0];
$text =~ s/^!?(.*)/\!$1/; $text =~ s/^\Q$self->{pbot}->{trigger}\E?(.*)/$self->{pbot}->{trigger}$1/;
$event->{to}[0] = $nick; $event->{to}[0] = $nick;
$event->{args}[0] = $text; $event->{args}[0] = $text;
$self->on_public($conn, $event); $self->on_public($conn, $event);

View File

@ -79,7 +79,7 @@ sub process_line {
$command = "$1" . (defined $2 and length $2 >= 2 ? substr $2, 1, 1 : ""); $command = "$1" . (defined $2 and length $2 >= 2 ? substr $2, 1, 1 : "");
} elsif($text =~ /^(.*?),?\s+$mynick([?]*)$/i) { } elsif($text =~ /^(.*?),?\s+$mynick([?]*)$/i) {
$command = "$1" . (defined $2 and length $2 >= 2 ? substr $2, 1, 1 : ""); $command = "$1" . (defined $2 and length $2 >= 2 ? substr $2, 1, 1 : "");
} elsif($text =~ /^!(.*?)([?]*)$/) { } elsif($text =~ /^\Q$pbot->{trigger}\E(.*?)([?]*)$/) {
$command = "$1" . (defined $2 and length $2 >= 2 ? substr $2, 1, 1 : ""); $command = "$1" . (defined $2 and length $2 >= 2 ? substr $2, 1, 1 : "");
} elsif($text =~ /http:\/\/([^\s]+)/i) { } elsif($text =~ /http:\/\/([^\s]+)/i) {
$has_url = $1; $has_url = $1;

View File

@ -67,19 +67,21 @@ sub initialize {
my $log_file = delete $conf{log_file}; my $log_file = delete $conf{log_file};
$self->{conf_dir} = delete $conf{conf_dir} || "$ENV{HOME}/pbot/config"; $self->{conf_dir} = delete $conf{conf_dir} // "$ENV{HOME}/pbot/config";
$self->{data_dir} = delete $conf{data_dir} || "$ENV{HOME}/pbot/data"; $self->{data_dir} = delete $conf{data_dir} // "$ENV{HOME}/pbot/data";
$self->{module_dir} = delete $conf{module_dir} || "$ENV{HOME}/pbot/modules"; $self->{module_dir} = delete $conf{module_dir} // "$ENV{HOME}/pbot/modules";
$self->{ircserver} = delete $conf{ircserver} || "irc.freenode.net"; $self->{ircserver} = delete $conf{ircserver} // "irc.freenode.net";
$self->{botnick} = delete $conf{botnick} || "pbot3"; $self->{botnick} = delete $conf{botnick} // "pbot3";
$self->{username} = delete $conf{username} || "pbot3"; $self->{username} = delete $conf{username} // "pbot3";
$self->{ircname} = delete $conf{ircname} || "http://code.google.com/p/pbot2-pl/"; $self->{ircname} = delete $conf{ircname} // "http://code.google.com/p/pbot2-pl/";
$self->{identify_password} = delete $conf{identify_password} || ""; $self->{identify_password} = delete $conf{identify_password} // "";
$self->{max_msg_len} = delete $conf{max_msg_len} || 430; $self->{max_msg_len} = delete $conf{max_msg_len} // 430;
$self->{MAX_FLOOD_MESSAGES} = delete $conf{MAX_FLOOD_MESSAGES} || 4; $self->{MAX_FLOOD_MESSAGES} = delete $conf{MAX_FLOOD_MESSAGES} // 4;
$self->{MAX_NICK_MESSAGES} = delete $conf{MAX_NICK_MESSAGES} || 12; $self->{MAX_NICK_MESSAGES} = delete $conf{MAX_NICK_MESSAGES} // 12;
$self->{trigger} = delete $conf{trigger} // '!';
my $channels_file = delete $conf{channels_file}; my $channels_file = delete $conf{channels_file};
my $admins_file = delete $conf{admins_file}; my $admins_file = delete $conf{admins_file};
@ -226,10 +228,10 @@ sub check_stdin {
if($input =~ m/^~([^ ]+)\s+(.*)/) { if($input =~ m/^~([^ ]+)\s+(.*)/) {
$from = $1; $from = $1;
$text = "!$2"; $text = "$self->{trigger}$2";
} else { } else {
$from = undef; $from = undef;
$text = "!$input"; $text = "$self->{trigger}$input";
} }
return $self->interpreter->process_line($from, $self->{botnick}, "stdin", "localhost", $text); return $self->interpreter->process_line($from, $self->{botnick}, "stdin", "localhost", $text);

View File

@ -13,7 +13,7 @@ use warnings;
# These are set automatically by the build/commit script # These are set automatically by the build/commit script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 283, BUILD_REVISION => 284,
BUILD_DATE => "2011-01-29", BUILD_DATE => "2011-01-29",
}; };

View File

@ -40,6 +40,9 @@ my %config = (
# (channels will not be auto-joined until identified) # (channels will not be auto-joined until identified)
identify_password => '*', identify_password => '*',
# The bot is triggered by using its name, or the following trigger SINGLE character
trigger => '.',
# ----------------------------------------------------- # -----------------------------------------------------
# The bot can export the latest factoids and quotegrabs to an HTML # The bot can export the latest factoids and quotegrabs to an HTML
# document. If you run a webserver or something similiar, you may # document. If you run a webserver or something similiar, you may