From 805832d97701033208fa8ee05c5fbecf2d041f75 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sun, 30 Jan 2011 03:22:00 +0000 Subject: [PATCH] pbot: allowed bot trigger to be customizable from pbot.pl; bot registry coming soon... --- PBot/IRCHandlers.pm | 2 +- PBot/Interpreter.pm | 2 +- PBot/PBot.pm | 28 +++++++++++++++------------- PBot/VERSION.pm | 2 +- pbot.pl | 3 +++ 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/PBot/IRCHandlers.pm b/PBot/IRCHandlers.pm index 1ced6c7c..afa2d282 100644 --- a/PBot/IRCHandlers.pm +++ b/PBot/IRCHandlers.pm @@ -79,7 +79,7 @@ sub on_msg { my ($nick, $host) = ($event->nick, $event->host); my $text = $event->{args}[0]; - $text =~ s/^!?(.*)/\!$1/; + $text =~ s/^\Q$self->{pbot}->{trigger}\E?(.*)/$self->{pbot}->{trigger}$1/; $event->{to}[0] = $nick; $event->{args}[0] = $text; $self->on_public($conn, $event); diff --git a/PBot/Interpreter.pm b/PBot/Interpreter.pm index e041c1a6..e00087f5 100644 --- a/PBot/Interpreter.pm +++ b/PBot/Interpreter.pm @@ -79,7 +79,7 @@ sub process_line { $command = "$1" . (defined $2 and length $2 >= 2 ? substr $2, 1, 1 : ""); } elsif($text =~ /^(.*?),?\s+$mynick([?]*)$/i) { $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 : ""); } elsif($text =~ /http:\/\/([^\s]+)/i) { $has_url = $1; diff --git a/PBot/PBot.pm b/PBot/PBot.pm index 0059a2f3..7610197a 100644 --- a/PBot/PBot.pm +++ b/PBot/PBot.pm @@ -67,19 +67,21 @@ sub initialize { my $log_file = delete $conf{log_file}; - $self->{conf_dir} = delete $conf{conf_dir} || "$ENV{HOME}/pbot/config"; - $self->{data_dir} = delete $conf{data_dir} || "$ENV{HOME}/pbot/data"; - $self->{module_dir} = delete $conf{module_dir} || "$ENV{HOME}/pbot/modules"; + $self->{conf_dir} = delete $conf{conf_dir} // "$ENV{HOME}/pbot/config"; + $self->{data_dir} = delete $conf{data_dir} // "$ENV{HOME}/pbot/data"; + $self->{module_dir} = delete $conf{module_dir} // "$ENV{HOME}/pbot/modules"; - $self->{ircserver} = delete $conf{ircserver} || "irc.freenode.net"; - $self->{botnick} = delete $conf{botnick} || "pbot3"; - $self->{username} = delete $conf{username} || "pbot3"; - $self->{ircname} = delete $conf{ircname} || "http://code.google.com/p/pbot2-pl/"; - $self->{identify_password} = delete $conf{identify_password} || ""; + $self->{ircserver} = delete $conf{ircserver} // "irc.freenode.net"; + $self->{botnick} = delete $conf{botnick} // "pbot3"; + $self->{username} = delete $conf{username} // "pbot3"; + $self->{ircname} = delete $conf{ircname} // "http://code.google.com/p/pbot2-pl/"; + $self->{identify_password} = delete $conf{identify_password} // ""; - $self->{max_msg_len} = delete $conf{max_msg_len} || 430; - $self->{MAX_FLOOD_MESSAGES} = delete $conf{MAX_FLOOD_MESSAGES} || 4; - $self->{MAX_NICK_MESSAGES} = delete $conf{MAX_NICK_MESSAGES} || 12; + $self->{max_msg_len} = delete $conf{max_msg_len} // 430; + $self->{MAX_FLOOD_MESSAGES} = delete $conf{MAX_FLOOD_MESSAGES} // 4; + $self->{MAX_NICK_MESSAGES} = delete $conf{MAX_NICK_MESSAGES} // 12; + + $self->{trigger} = delete $conf{trigger} // '!'; my $channels_file = delete $conf{channels_file}; my $admins_file = delete $conf{admins_file}; @@ -226,10 +228,10 @@ sub check_stdin { if($input =~ m/^~([^ ]+)\s+(.*)/) { $from = $1; - $text = "!$2"; + $text = "$self->{trigger}$2"; } else { $from = undef; - $text = "!$input"; + $text = "$self->{trigger}$input"; } return $self->interpreter->process_line($from, $self->{botnick}, "stdin", "localhost", $text); diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 2fe69cc5..c518b056 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,7 +13,7 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 283, + BUILD_REVISION => 284, BUILD_DATE => "2011-01-29", }; diff --git a/pbot.pl b/pbot.pl index 279cbf6a..de8f4601 100755 --- a/pbot.pl +++ b/pbot.pl @@ -40,6 +40,9 @@ my %config = ( # (channels will not be auto-joined until identified) 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 # document. If you run a webserver or something similiar, you may