summaryrefslogtreecommitdiff
path: root/lib/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-10-15 19:34:58 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2006-10-15 19:34:58 +0000
commit21af4682361be8d6218d1ea9575da9e311b675a7 (patch)
tree30e76c2930f313a3168d36cc53d6c643924bb686 /lib/rbot
parent72f035baa45e2428891924ac863f811317d28f5f (diff)
Allow plugins to do things when the language is changed. Will be used e.g. by lart to use language-specific lart files
Diffstat (limited to 'lib/rbot')
-rw-r--r--lib/rbot/ircbot.rb3
-rw-r--r--lib/rbot/language.rb15
-rw-r--r--lib/rbot/plugins.rb7
3 files changed, 23 insertions, 2 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb
index 432b61c4..ac7aa829 100644
--- a/lib/rbot/ircbot.rb
+++ b/lib/rbot/ircbot.rb
@@ -346,7 +346,8 @@ class IrcBot
@httputil = Utils::HttpUtil.new(self)
- @lang = Language::Language.new(@config['core.language'])
+ @plugins = nil
+ @lang = Language::Language.new(self, @config['core.language'])
begin
@auth = Auth::authmanager
diff --git a/lib/rbot/language.rb b/lib/rbot/language.rb
index 1a4a889a..edb3cafa 100644
--- a/lib/rbot/language.rb
+++ b/lib/rbot/language.rb
@@ -12,9 +12,11 @@ module Language
:on_change => Proc.new {|bot, v| bot.lang.set_language v},
:desc => "Which language file the bot should use")
- def initialize(language)
+ def initialize(bot, language)
+ @bot = bot
set_language language
end
+ attr_reader :language
def set_language(language)
file = Config::datadir + "/languages/#{language}.lang"
@@ -24,6 +26,17 @@ module Language
@language = language
@file = file
scan
+ return if @bot.plugins.nil?
+ @bot.plugins.core_modules.each { |p|
+ if p.respond_to?('set_language')
+ p.set_language(@language)
+ end
+ }
+ @bot.plugins.plugins.each { |p|
+ if p.respond_to?('set_language')
+ p.set_language(@language)
+ end
+ }
end
def scan
diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb
index 8aa75d20..66a7d842 100644
--- a/lib/rbot/plugins.rb
+++ b/lib/rbot/plugins.rb
@@ -88,6 +88,10 @@ module Plugins
connect():: Called when a server is joined successfully, but
before autojoin channels are joined (no params)
+ set_language(String)::
+ Called when the user sets a new language
+ whose name is the given String
+
save:: Called when you are required to save your plugin's
state, if you maintain data between sessions
@@ -111,6 +115,9 @@ module Plugins
@registry = BotRegistryAccessor.new(@bot, self.class.to_s.gsub(/^.*::/, ""))
@manager.add_botmodule(self)
+ if self.respond_to?('set_language')
+ self.set_language(@bot.lang.language)
+ end
end
def botmodule_class