]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/core/unicode.rb
utils: support hex HTML entities
[user/henk/code/ruby/rbot.git] / lib / rbot / core / unicode.rb
index a24a19984206ed4d54ebe06be421d56b47c50f40..ece8e64409c62598013a7f7493f89caf30d260f4 100644 (file)
@@ -4,14 +4,15 @@
 # :title: Unicode plugin
 #
 # Author:: jsn (Dmitry Kim) <dmitry dot kim at gmail dot org>
-# Copyright:: (C) 2007 Dmitry Kim
-# License:: public domain
 #
 # This plugin adds unicode-awareness to rbot. When it's loaded, all the
 # character strings inside of rbot are assumed to be in proper utf-8
 # encoding. The plugin takes care of translation to/from utf-8 on server IO,
 # if necessary (translation charsets are configurable).
 
+# TODO autoconfigure using server-provided allowed charset when these are
+# available, see also comment in irc.rb
+
 require 'iconv'
 
 class UnicodePlugin < CoreBotModule
@@ -23,6 +24,7 @@ class UnicodePlugin < CoreBotModule
     Config.register Config::ArrayValue.new(
     'encoding.charsets', :default => ['utf-8', 'cp1252', 'iso-8859-15'],
     :desc => "Ordered list of iconv(3) charsets the bot should try",
+    :validate_item => Proc.new { |x| !!(Iconv.new('utf-8', x) rescue nil) },
     :on_change => Proc.new { |bot, v| reconfigure_filter(bot) })
 
     class UnicodeFilter
@@ -64,14 +66,14 @@ class UnicodePlugin < CoreBotModule
 
     def initialize(*a)
         super
-        @old_kcode = $KCODE
+        @@old_kcode = $KCODE
         self.class.reconfigure_filter(@bot)
     end
 
     def cleanup
         debug "cleaning up encodings"
         @bot.socket.filter = nil
-        $KCODE = @old_kcode
+        $KCODE = @@old_kcode
         super
     end
 
@@ -80,7 +82,7 @@ class UnicodePlugin < CoreBotModule
         enable = bot.config['encoding.enable']
         if not enable
             bot.socket.filter = nil
-            $KCODE = @old_kcode
+            $KCODE = @@old_kcode
             return
         end
         charsets = bot.config['encoding.charsets']