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
35 self.class.reconfigure_filter(@bot)
39 debug "cleaning up encodings"
40 @bot.socket.filter = nil
44 def UnicodePlugin.reconfigure_filter(bot)
45 debug "configuring encodings"
46 charset = bot.config['encoding.charset']
47 if bot.config['encoding.enable']
48 bot.socket.filter = UnicodeFilter.new charset
50 bot.socket.filter = nil