- proper identify channel names, don't rely on '#'
authorAndreas Scherbaum <andreas@scherbaum.biz>
Fri, 25 May 2012 21:18:47 +0000 (23:18 +0200)
committerAndreas Scherbaum <andreas@scherbaum.biz>
Fri, 25 May 2012 21:18:47 +0000 (23:18 +0200)
docbot.pl

index cf04e0bd53f8c6d5de99d6e42531d1824ff70620..97d3761876c9892a6ac3b9c6339354ce8c86a2d3 100755 (executable)
--- 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