From 3b2efd4aed3b464535aaf7992beae6586b2c5d78 Mon Sep 17 00:00:00 2001 From: Andreas Scherbaum Date: Fri, 25 May 2012 23:18:47 +0200 Subject: [PATCH] - proper identify channel names, don't rely on '#' --- docbot.pl | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/docbot.pl b/docbot.pl index cf04e0b..97d3761 100755 --- a/docbot.pl +++ b/docbot.pl @@ -1396,7 +1396,7 @@ sub translate_text_for_channel { my $text = $default_text; # translate text - if (substr($channel, 0, 1) eq '#') { + if (is_a_channel($channe)) { my $channel_language = config_get_key3('channels', $channel, 'language'); if (defined($channel_language)) { $text = translate_with_default($channel_language, $text_key, $default_text); @@ -1609,6 +1609,63 @@ sub find_nick { } +# is_a_channel() +# +# find out if a nick/channel string is really a channel name +# +# parameter: +# - nick/channel string +# return: +# - 0/1 +sub is_a_channel { + my $string = shift; + + my $channel = extract_channel($string); + + + if (length($channel) == 0) { + return 0; + } + + return 1; +} + + +# extract_channel() +# +# extract a channel name from a nick/channel string +# +# parameter: +# - nick/channel string +# return: +# - channel name, without prefix, or '' +sub extract_channel { + my $string = shift; + + if (substr($string, 0, 1) eq '#') { + return substr($string, 1); + } + if (substr($string, 0, 1) eq '&') { + return substr($string, 1); + } + if (substr($string, 0, 1) eq '!') { + return substr($string, 1); + } + if (substr($string, 0, 1) eq '+') { + return substr($string, 1); + } + if (substr($string, 0, 1) eq '.') { + return substr($string, 1); + } + if (substr($string, 0, 1) eq '~') { + return substr($string, 1); + } + + + return ''; +} + + # handle_command() # # wrapper to handle all commands -- 2.39.5