4 # :title: Unicode plugin
5 # To set the encoding of strings coming from the irc server.
7 class UnicodePlugin < CoreBotModule
8 Config.register Config::BooleanValue.new('encoding.enable',
10 :desc => "Support for non-ascii charsets",
11 :on_change => Proc.new { |bot, v| reconfigure_filter(bot) })
13 Config.register Config::StringValue.new('encoding.charset',
15 :desc => 'Server encoding.',
16 :on_change => Proc.new { |bot, v| reconfigure_filter(bot) })
19 def initialize(charset)
24 data.force_encoding @charset if data
25 data.encode('UTF-16le', :invalid => :replace, :replace => '').encode('UTF-8')
36 self.class.reconfigure_filter(@bot)
40 debug "cleaning up encodings"
41 @bot.socket.filter = nil
45 def UnicodePlugin.reconfigure_filter(bot)
46 debug "configuring encodings"
47 charset = bot.config['encoding.charset']
48 if bot.config['encoding.enable']
49 bot.socket.filter = UnicodeFilter.new charset
51 bot.socket.filter = nil