summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-09-12 22:31:15 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-09-12 22:31:15 +0000
commit6f5528a63b44e610a3d25d7fe583399163d7d2da (patch)
tree0db7c1642d40bd68a85338f4cdbb87a03f5e7747 /lib
parent8efdfd2651a720e0dc1681e716d0a23b0429e4fd (diff)
namespaces: move rbot-specific classes and modules from Irc::* to Irc::Bot::*
Diffstat (limited to 'lib')
-rw-r--r--lib/rbot/botuser.rb32
-rw-r--r--lib/rbot/config.rb73
-rw-r--r--lib/rbot/core/auth.rb9
-rw-r--r--lib/rbot/core/config.rb8
-rw-r--r--lib/rbot/core/remote.rb12
-rw-r--r--lib/rbot/core/utils/httputil.rb22
-rw-r--r--lib/rbot/core/utils/utils.rb2
-rw-r--r--lib/rbot/ircbot.rb64
-rw-r--r--lib/rbot/language.rb6
-rw-r--r--lib/rbot/load-gettext.rb2
-rw-r--r--lib/rbot/message.rb35
-rw-r--r--lib/rbot/messagemapper.rb2
-rw-r--r--lib/rbot/plugins.rb18
-rw-r--r--lib/rbot/rbotconfig.rb2
-rw-r--r--lib/rbot/registry.rb16
15 files changed, 167 insertions, 136 deletions
diff --git a/lib/rbot/botuser.rb b/lib/rbot/botuser.rb
index a77765b8..146912b4 100644
--- a/lib/rbot/botuser.rb
+++ b/lib/rbot/botuser.rb
@@ -19,7 +19,7 @@ require 'set'
# class_eval {
# define_method(m) { |*a|
# r = super(*a)
-# Irc::Auth.authmanager.set_changed
+# Irc::Bot::Auth.authmanager.set_changed
# r
# }
# }
@@ -28,26 +28,27 @@ require 'set'
#
module Irc
+class Bot
# This module contains the actual Authentication stuff
#
module Auth
- BotConfig.register BotConfigStringValue.new( 'auth.password',
+ Config.register Config::StringValue.new( 'auth.password',
:default => 'rbotauth', :wizard => true,
:on_change => Proc.new {|bot, v| bot.auth.botowner.password = v},
:desc => _('Password for the bot owner'))
- BotConfig.register BotConfigBooleanValue.new( 'auth.login_by_mask',
+ Config.register Config::BooleanValue.new( 'auth.login_by_mask',
:default => 'true',
:desc => _('Set false to prevent new botusers from logging in without a password when the user netmask is known'))
- BotConfig.register BotConfigBooleanValue.new( 'auth.autologin',
+ Config.register Config::BooleanValue.new( 'auth.autologin',
:default => 'true',
:desc => _('Set false to prevent new botusers from recognizing IRC users without a need to manually login'))
- BotConfig.register BotConfigBooleanValue.new( 'auth.autouser',
+ Config.register Config::BooleanValue.new( 'auth.autouser',
:default => 'false',
:desc => _('Set true to allow new botusers to be created automatically'))
- # BotConfig.register BotConfigIntegerValue.new( 'auth.default_level',
+ # Config.register Config::IntegerValue.new( 'auth.default_level',
# :default => 10, :wizard => true,
# :desc => 'The default level for new/unknown users' )
@@ -62,7 +63,7 @@ module Irc
end
- # An Irc::Auth::Command defines a command by its "path":
+ # An Irc::Bot::Auth::Command defines a command by its "path":
#
# base::command::subcommand::subsubcommand::subsubsubcommand
#
@@ -110,13 +111,14 @@ module Irc
end
end
+end
class String
- # Returns an Irc::Auth::Comand from the receiver
+ # Returns an Irc::Bot::Auth::Comand from the receiver
def to_irc_auth_command
- Irc::Auth::Command.new(self)
+ Irc::Bot::Auth::Command.new(self)
end
end
@@ -124,15 +126,16 @@ end
class Symbol
- # Returns an Irc::Auth::Comand from the receiver
+ # Returns an Irc::Bot::Auth::Comand from the receiver
def to_irc_auth_command
- Irc::Auth::Command.new(self)
+ Irc::Bot::Auth::Command.new(self)
end
end
module Irc
+class Bot
module Auth
@@ -830,6 +833,7 @@ module Irc
end
end
+end
class User
@@ -837,7 +841,7 @@ module Irc
# associated with the receiver
#
def botuser
- Irc::Auth.authmanager.irc_to_botuser(self)
+ Irc::Bot::Auth.authmanager.irc_to_botuser(self)
end
# Bot-specific data can be stored with Irc::Users. This is
@@ -863,7 +867,7 @@ module Irc
def set_bot_data(key,value=nil,&block)
if not block_given?
self.botuser.data[key]=value
- Irc::Auth.authmanager.set_changed
+ Irc::Bot::Auth.authmanager.set_changed
return value
end
if value and not bot_data.has_key?(key)
@@ -873,7 +877,7 @@ module Irc
begin
r = yield bot_data(key)
ensure
- Irc::Auth.authmanager.set_changed
+ Irc::Bot::Auth.authmanager.set_changed
end
return r
end
diff --git a/lib/rbot/config.rb b/lib/rbot/config.rb
index eb342f7c..7ed019fe 100644
--- a/lib/rbot/config.rb
+++ b/lib/rbot/config.rb
@@ -1,20 +1,23 @@
require 'singleton'
-module Irc
-
- require 'yaml'
+require 'yaml'
- unless YAML.respond_to?(:load_file)
- def YAML.load_file( filepath )
- File.open( filepath ) do |f|
- YAML::load( f )
- end
- end
+unless YAML.respond_to?(:load_file)
+ def YAML.load_file( filepath )
+ File.open( filepath ) do |f|
+ YAML::load( f )
+ end
end
+end
+
- class BotConfigValue
+module Irc
+
+class Bot
+module Config
+ class Value
# allow the definition order to be preserved so that sorting by
- # definition order is possible. The BotConfigWizard does this to allow
+ # definition order is possible. The Wizard does this to allow
# the :wizard questions to be in a sensible order.
@@order = 0
attr_reader :type
@@ -27,7 +30,7 @@ module Irc
attr_reader :manager
attr_reader :auth_path
def initialize(key, params)
- @manager = BotConfig::configmanager
+ @manager = Config.manager
# Keys must be in the form 'module.name'.
# They will be internally passed around as symbols,
# but we accept them both in string and symbol form.
@@ -107,10 +110,10 @@ module Irc
end
end
- class BotConfigStringValue < BotConfigValue
+ class StringValue < Value
end
- class BotConfigBooleanValue < BotConfigValue
+ class BooleanValue < Value
def parse(string)
return true if string == "true"
return false if string == "false"
@@ -129,7 +132,7 @@ module Irc
end
end
- class BotConfigIntegerValue < BotConfigValue
+ class IntegerValue < Value
def parse(string)
return 1 if string == "true"
return 0 if string == "false"
@@ -146,14 +149,14 @@ module Irc
end
end
- class BotConfigFloatValue < BotConfigValue
+ class FloatValue < Value
def parse(string)
raise ArgumentError, "not a float #{string}" unless string =~ /^-?[\d.]+$/
string.to_f
end
end
- class BotConfigArrayValue < BotConfigValue
+ class ArrayValue < Value
def parse(string)
string.split(/,\s+/)
end
@@ -171,7 +174,7 @@ module Irc
end
end
- class BotConfigEnumValue < BotConfigValue
+ class EnumValue < Value
def initialize(key, params)
super
@values = params[:values]
@@ -195,7 +198,7 @@ module Irc
end
# container for bot configuration
- class BotConfigManagerClass
+ class ManagerClass
include Singleton
@@ -232,15 +235,15 @@ module Irc
end
end
# if we got here, we need to run the first-run wizard
- BotConfigWizard.new(@bot).run
+ Wizard.new(@bot).run
# save newly created config
@changed = true
save
end
def register(item)
- unless item.kind_of?(BotConfigValue)
- raise ArgumentError,"item must be a BotConfigValue"
+ unless item.kind_of?(Value)
+ raise ArgumentError,"item must be an Irc::Bot::Config::Value"
end
@items[item.key] = item
end
@@ -265,7 +268,7 @@ module Irc
return false
end
- # TODO should I implement this via BotConfigValue or leave it direct?
+ # TODO should I implement this via Value or leave it direct?
# def []=(key, value)
# end
@@ -301,23 +304,21 @@ module Irc
end
end
- module BotConfig
- # Returns the only BotConfigManagerClass
- #
- def BotConfig.configmanager
- return BotConfigManagerClass.instance
- end
+ # Returns the only Irc::Bot::Config::ManagerClass
+ #
+ def Config.manager
+ return ManagerClass.instance
+ end
- # Register a config value
- def BotConfig.register(item)
- BotConfig.configmanager.register(item)
- end
+ # Register a config value
+ def Config.register(item)
+ Config.manager.register(item)
end
- class BotConfigWizard
+ class Wizard
def initialize(bot)
@bot = bot
- @manager = BotConfig::configmanager
+ @manager = Config.manager
@questions = @manager.items.values.find_all {|i| i.wizard }
end
@@ -350,3 +351,5 @@ module Irc
end
end
+end
+end
diff --git a/lib/rbot/core/auth.rb b/lib/rbot/core/auth.rb
index 97429041..c6c55aff 100644
--- a/lib/rbot/core/auth.rb
+++ b/lib/rbot/core/auth.rb
@@ -11,6 +11,15 @@ class AuthModule < CoreBotModule
def initialize
super
+
+ # The namespace migration causes each Irc::Auth::PermissionSet to be
+ # unrecoverable, and we have to rename their class name to
+ # Irc::Bot::Auth::PermissionSet
+ @registry.recovery = Proc.new { |val|
+ patched = val.sub("o:\035Irc::Auth::PermissionSet", "o:\042Irc::Bot::Auth::PermissionSet")
+ Marshal.restore(patched)
+ }
+
load_array(:default, true)
debug "initialized auth. Botusers: #{@bot.auth.save_array.pretty_inspect}"
end
diff --git a/lib/rbot/core/config.rb b/lib/rbot/core/config.rb
index 717408a2..d929fb39 100644
--- a/lib/rbot/core/config.rb
+++ b/lib/rbot/core/config.rb
@@ -107,7 +107,7 @@ class ConfigModule < CoreBotModule
m.reply _("no such config key %{key}") % {:key => key}
return
end
- unless @bot.config.items[key].kind_of?(BotConfigArrayValue)
+ unless @bot.config.items[key].kind_of?(Config::ArrayValue)
m.reply _("config key %{key} is not an array") % {:key => key}
return
end
@@ -130,7 +130,7 @@ class ConfigModule < CoreBotModule
m.reply _("no such config key %{key}") % {:key => key}
return
end
- unless @bot.config.items[key].kind_of?(BotConfigArrayValue)
+ unless @bot.config.items[key].kind_of?(Config::ArrayValue)
m.reply _("config key %{key} is not an array") % {:key => key}
return
end
@@ -240,7 +240,7 @@ conf.map 'config list :module',
:auth_path => 'show'
# TODO this one is presently a security risk, since the bot
# stores the master password in the config. Do we need auth levels
-# on the BotConfig keys too?
+# on the Bot::Config keys too?
conf.map 'config get :key',
:action => 'handle_get',
:auth_path => 'show'
@@ -299,7 +299,7 @@ conf.map 'config help :topic',
conf.default_auth('*', false)
conf.default_auth('show::status', true)
# TODO these shouldn't be set here, we need a way to let the default
-# permission be specified together with the BotConfigValue
+# permission be specified together with the ConfigValue
conf.default_auth('key', true)
conf.default_auth('key::auth::password', false)
diff --git a/lib/rbot/core/remote.rb b/lib/rbot/core/remote.rb
index 7ced878f..52cfed4e 100644
--- a/lib/rbot/core/remote.rb
+++ b/lib/rbot/core/remote.rb
@@ -15,6 +15,7 @@
require 'drb/drb'
module ::Irc
+class Bot
module Auth
@@ -192,8 +193,6 @@ module ::Irc
end
- class Bot
-
# The Irc::Bot::RemoteObject class represents and object that will take care
# of interfacing with remote clients
#
@@ -260,8 +259,6 @@ module ::Irc
end
end
- end
-
module Plugins
# We create a new Ruby module that can be included by BotModules that want to
@@ -309,22 +306,23 @@ module ::Irc
end
end
+end
class RemoteModule < CoreBotModule
include RemoteCoreBotModule
- BotConfig.register BotConfigBooleanValue.new('remote.autostart',
+ Config.register Config::BooleanValue.new('remote.autostart',
:default => true,
:requires_rescan => true,
:desc => "Whether the remote service provider should be started automatically")
- BotConfig.register BotConfigIntegerValue.new('remote.port',
+ Config.register Config::IntegerValue.new('remote.port',
:default => 7268, # that's 'rbot'
:requires_rescan => true,
:desc => "Port on which the remote interface will be presented")
- BotConfig.register BotConfigStringValue.new('remote.host',
+ Config.register Config::StringValue.new('remote.host',
:default => '',
:requires_rescan => true,
:desc => "Port on which the remote interface will be presented")
diff --git a/lib/rbot/core/utils/httputil.rb b/lib/rbot/core/utils/httputil.rb
index 11f3cb41..a621a36b 100644
--- a/lib/rbot/core/utils/httputil.rb
+++ b/lib/rbot/core/utils/httputil.rb
@@ -137,35 +137,35 @@ module Utils
# this class can check the bot proxy configuration to determine if a proxy
# needs to be used, which includes support for per-url proxy configuration.
class HttpUtil
- BotConfig.register BotConfigBooleanValue.new('http.use_proxy',
+ Bot::Config.register Bot::Config::BooleanValue.new('http.use_proxy',
:default => false, :desc => "should a proxy be used for HTTP requests?")
- BotConfig.register BotConfigStringValue.new('http.proxy_uri', :default => false,
+ Bot::Config.register Bot::Config::StringValue.new('http.proxy_uri', :default => false,
:desc => "Proxy server to use for HTTP requests (URI, e.g http://proxy.host:port)")
- BotConfig.register BotConfigStringValue.new('http.proxy_user',
+ Bot::Config.register Bot::Config::StringValue.new('http.proxy_user',
:default => nil,
:desc => "User for authenticating with the http proxy (if required)")
- BotConfig.register BotConfigStringValue.new('http.proxy_pass',
+ Bot::Config.register Bot::Config::StringValue.new('http.proxy_pass',
:default => nil,
:desc => "Password for authenticating with the http proxy (if required)")
- BotConfig.register BotConfigArrayValue.new('http.proxy_include',
+ Bot::Config.register Bot::Config::ArrayValue.new('http.proxy_include',
:default => [],
:desc => "List of regexps to check against a URI's hostname/ip to see if we should use the proxy to access this URI. All URIs are proxied by default if the proxy is set, so this is only required to re-include URIs that might have been excluded by the exclude list. e.g. exclude /.*\.foo\.com/, include bar\.foo\.com")
- BotConfig.register BotConfigArrayValue.new('http.proxy_exclude',
+ Bot::Config.register Bot::Config::ArrayValue.new('http.proxy_exclude',
:default => [],
:desc => "List of regexps to check against a URI's hostname/ip to see if we should use avoid the proxy to access this URI and access it directly")
- BotConfig.register BotConfigIntegerValue.new('http.max_redir',
+ Bot::Config.register Bot::Config::IntegerValue.new('http.max_redir',
:default => 5,
:desc => "Maximum number of redirections to be used when getting a document")
- BotConfig.register BotConfigIntegerValue.new('http.expire_time',
+ Bot::Config.register Bot::Config::IntegerValue.new('http.expire_time',
:default => 60,
:desc => "After how many minutes since last use a cached document is considered to be expired")
- BotConfig.register BotConfigIntegerValue.new('http.max_cache_time',
+ Bot::Config.register Bot::Config::IntegerValue.new('http.max_cache_time',
:default => 60*24,
:desc => "After how many minutes since first use a cached document is considered to be expired")
- BotConfig.register BotConfigIntegerValue.new('http.no_expire_cache',
+ Bot::Config.register Bot::Config::IntegerValue.new('http.no_expire_cache',
:default => false,
:desc => "Set this to true if you want the bot to never expire the cached pages")
- BotConfig.register BotConfigIntegerValue.new('http.info_bytes',
+ Bot::Config.register Bot::Config::IntegerValue.new('http.info_bytes',
:default => 8192,
:desc => "How many bytes to download from a web page to find some information. Set to 0 to let the bot download the whole page.")
diff --git a/lib/rbot/core/utils/utils.rb b/lib/rbot/core/utils/utils.rb
index 65ba6651..a33f072f 100644
--- a/lib/rbot/core/utils/utils.rb
+++ b/lib/rbot/core/utils/utils.rb
@@ -676,4 +676,4 @@ module ::Irc
end
end
-Irc::Utils.bot = Irc::Plugins.manager.bot
+Irc::Utils.bot = Irc::Bot::Plugins.manager.bot
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb
index 4debf1cb..e2f3f28e 100644
--- a/lib/rbot/ircbot.rb
+++ b/lib/rbot/ircbot.rb
@@ -127,7 +127,7 @@ class Bot
# the bot's Auth data
attr_reader :auth
- # the bot's BotConfig data
+ # the bot's Config data
attr_reader :config
# the botclass for this bot (determines configdir among other things)
@@ -179,58 +179,58 @@ class Bot
# create a new Bot with botclass +botclass+
def initialize(botclass, params = {})
- # BotConfig for the core bot
+ # Config for the core bot
# TODO should we split socket stuff into ircsocket, etc?
- BotConfig.register BotConfigArrayValue.new('server.list',
+ Config.register Config::ArrayValue.new('server.list',
:default => ['irc://localhost'], :wizard => true,
:requires_restart => true,
:desc => "List of irc servers rbot should try to connect to. Use comma to separate values. Servers are in format 'server.doma.in:port'. If port is not specified, default value (6667) is used.")
- BotConfig.register BotConfigBooleanValue.new('server.ssl',
+ Config.register Config::BooleanValue.new('server.ssl',
:default => false, :requires_restart => true, :wizard => true,
:desc => "Use SSL to connect to this server?")
- BotConfig.register BotConfigStringValue.new('server.password',
+ Config.register Config::StringValue.new('server.password',
:default => false, :requires_restart => true,
:desc => "Password for connecting to this server (if required)",
:wizard => true)
- BotConfig.register BotConfigStringValue.new('server.bindhost',
+ Config.register Config::StringValue.new('server.bindhost',
:default => false, :requires_restart => true,
:desc => "Specific local host or IP for the bot to bind to (if required)",
:wizard => true)
- BotConfig.register BotConfigIntegerValue.new('server.reconnect_wait',
+ Config.register Config::IntegerValue.new('server.reconnect_wait',
:default => 5, :validate => Proc.new{|v| v >= 0},
:desc => "Seconds to wait before attempting to reconnect, on disconnect")
- BotConfig.register BotConfigFloatValue.new('server.sendq_delay',
+ Config.register Config::FloatValue.new('server.sendq_delay',
:default => 2.0, :validate => Proc.new{|v| v >= 0},
:desc => "(flood prevention) the delay between sending messages to the server (in seconds)",
:on_change => Proc.new {|bot, v| bot.socket.sendq_delay = v })
- BotConfig.register BotConfigIntegerValue.new('server.sendq_burst',
+ Config.register Config::IntegerValue.new('server.sendq_burst',
:default => 4, :validate => Proc.new{|v| v >= 0},
:desc => "(flood prevention) max lines to burst to the server before throttling. Most ircd's allow bursts of up 5 lines",
:on_change => Proc.new {|bot, v| bot.socket.sendq_burst = v })
- BotConfig.register BotConfigIntegerValue.new('server.ping_timeout',
+ Config.register Config::IntegerValue.new('server.ping_timeout',
:default => 30, :validate => Proc.new{|v| v >= 0},
:desc => "reconnect if server doesn't respond to PING within this many seconds (set to 0 to disable)")
- BotConfig.register BotConfigStringValue.new('irc.nick', :default => "rbot",
+ Config.register Config::StringValue.new('irc.nick', :default => "rbot",
:desc => "IRC nickname the bot should attempt to use", :wizard => true,
:on_change => Proc.new{|bot, v| bot.sendq "NICK #{v}" })
- BotConfig.register BotConfigStringValue.new('irc.name',
+ Config.register Config::StringValue.new('irc.name',
:default => "Ruby bot", :requires_restart => true,
:desc => "IRC realname the bot should use")
- BotConfig.register BotConfigBooleanValue.new('irc.name_copyright',
+ Config.register Config::BooleanValue.new('irc.name_copyright',
:default => true, :requires_restart => true,
:desc => "Append copyright notice to bot realname? (please don't disable unless it's really necessary)")
- BotConfig.register BotConfigStringValue.new('irc.user', :default => "rbot",
+ Config.register Config::StringValue.new('irc.user', :default => "rbot",
:requires_restart => true,
:desc => "local user the bot should appear to be", :wizard => true)
- BotConfig.register BotConfigArrayValue.new('irc.join_channels',
+ Config.register Config::ArrayValue.new('irc.join_channels',
:default => [], :wizard => true,
:desc => "What channels the bot should always join at startup. List multiple channels using commas to separate. If a channel requires a password, use a space after the channel name. e.g: '#chan1, #chan2, #secretchan secritpass, #chan3'")
- BotConfig.register BotConfigArrayValue.new('irc.ignore_users',
+ Config.register Config::ArrayValue.new('irc.ignore_users',
:default => [],
:desc => "Which users to ignore input from. This is mainly to avoid bot-wars triggered by creative people")
- BotConfig.register BotConfigIntegerValue.new('core.save_every',
+ Config.register Config::IntegerValue.new('core.save_every',
:default => 60, :validate => Proc.new{|v| v >= 0},
:on_change => Proc.new { |bot, v|
if @save_timer
@@ -249,73 +249,73 @@ class Bot
},
:desc => "How often the bot should persist all configuration to disk (in case of a server crash, for example)")
- BotConfig.register BotConfigBooleanValue.new('core.run_as_daemon',
+ Config.register Config::BooleanValue.new('core.run_as_daemon',
:default => false, :requires_restart => true,
:desc => "Should the bot run as a daemon?")
- BotConfig.register BotConfigStringValue.new('log.file',
+ Config.register Config::StringValue.new('log.file',
:default => false, :requires_restart => true,
:desc => "Name of the logfile to which console messages will be redirected when the bot is run as a daemon")
- BotConfig.register BotConfigIntegerValue.new('log.level',
+ Config.register Config::IntegerValue.new('log.level',
:default => 1, :requires_restart => false,
:validate => Proc.new { |v| (0..5).include?(v) },
:on_change => Proc.new { |bot, v|
$logger.level = v
},
:desc => "The minimum logging level (0=DEBUG,1=INFO,2=WARN,3=ERROR,4=FATAL) for console messages")
- BotConfig.register BotConfigIntegerValue.new('log.keep',
+ Config.register Config::IntegerValue.new('log.keep',
:default => 1, :requires_restart => true,
:validate => Proc.new { |v| v >= 0 },
:desc => "How many old console messages logfiles to keep")
- BotConfig.register BotConfigIntegerValue.new('log.max_size',
+ Config.register Config::IntegerValue.new('log.max_size',
:default => 10, :requires_restart => true,
:validate => Proc.new { |v| v > 0 },
:desc => "Maximum console messages logfile size (in megabytes)")
- BotConfig.register BotConfigArrayValue.new('plugins.path',
+ Config.register Config::ArrayValue.new('plugins.path',
:wizard => true, :default => ['(default)', '(default)/games', '(default)/contrib'],
:requires_restart => false,
:on_change => Proc.new { |bot, v| bot.setup_plugins_path },
:desc => "Where the bot should look for plugins. List multiple directories using commas to separate. Use '(default)' for default prepackaged plugins collection, '(default)/contrib' for prepackaged unsupported plugins collection")
- BotConfig.register BotConfigEnumValue.new('send.newlines',
+ Config.register Config::EnumValue.new('send.newlines',
:values => ['split', 'join'], :default => 'split',
:on_change => Proc.new { |bot, v|
bot.set_default_send_options :newlines => v.to_sym
},
:desc => "When set to split, messages with embedded newlines will be sent as separate lines. When set to join, newlines will be replaced by the value of join_with")
- BotConfig.register BotConfigStringValue.new('send.join_with',
+ Config.register Config::StringValue.new('send.join_with',
:default => ' ',
:on_change => Proc.new { |bot, v|
bot.set_default_send_options :join_with => v.dup
},
:desc => "String used to replace newlines when send.newlines is set to join")
- BotConfig.register BotConfigIntegerValue.new('send.max_lines',
+ Config.register Config::IntegerValue.new('send.max_lines',
:default => 5,
:validate => Proc.new { |v| v >= 0 },
:on_change => Proc.new { |bot, v|
bot.set_default_send_options :max_lines => v
},
:desc => "Maximum number of IRC lines to send for each message (set to 0 for no limit)")
- BotConfig.register BotConfigEnumValue.new('send.overlong',
+ Config.register Config::EnumValue.new('send.overlong',
:values => ['split', 'truncate'], :default => 'split',
:on_change => Proc.new { |bot, v|
bot.set_default_send_options :overlong => v.to_sym
},
:desc => "When set to split, messages which are too long to fit in a single IRC line are split into multiple lines. When set to truncate, long messages are truncated to fit the IRC line length")
- BotConfig.register BotConfigStringValue.new('send.split_at',
+ Config.register Config::StringValue.new('send.split_at',
:default => '\s+',
:on_change => Proc.new { |bot, v|
bot.set_default_send_options :split_at => Regexp.new(v)
},
:desc => "A regular expression that should match the split points for overlong messages (see send.overlong)")
- BotConfig.register BotConfigBooleanValue.new('send.purge_split',
+ Config.register Config::BooleanValue.new('send.purge_split',
:default => true,
:on_change => Proc.new { |bot, v|
bot.set_default_send_options :purge_split => v
},
:desc => "Set to true if the splitting boundary (set in send.split_at) should be removed when splitting overlong messages (see send.overlong)")
- BotConfig.register BotConfigStringValue.new('send.truncate_text',
+ Config.register Config::StringValue.new('send.truncate_text',
:default => "#{Reverse}...#{Reverse}",
:on_change => Proc.new { |bot, v|
bot.set_default_send_options :truncate_text => v.dup
@@ -376,7 +376,7 @@ class Bot
@startup_time = Time.new
begin
- @config = BotConfig.configmanager
+ @config = Config.manager
@config.bot_associate(self)
rescue Exception => e
fatal e
@@ -443,7 +443,7 @@ class Bot
pf << "#{$$}\n"
end
- @registry = BotRegistry.new self
+ @registry = Registry.new self
@timer = Timer.new
@save_mutex = Mutex.new
diff --git a/lib/rbot/language.rb b/lib/rbot/language.rb
index 7cf1ceb9..3e4c77f0 100644
--- a/lib/rbot/language.rb
+++ b/lib/rbot/language.rb
@@ -8,6 +8,7 @@
# .lang file etc.
module Irc
+class Bot
class Language
# This constant hash holds the mapping
@@ -54,8 +55,8 @@ module Irc
return 'english'
end
- BotConfig.register BotConfigEnumValue.new('core.language',
- :default => Irc::Language.from_locale, :wizard => true,
+ Config.register Config::EnumValue.new('core.language',
+ :default => Irc::Bot::Language.from_locale, :wizard => true,
:values => Proc.new{|bot|
Dir.new(Config::datadir + "/languages").collect {|f|
f =~ /\.lang$/ ? f.gsub(/\.lang$/, "") : nil
@@ -141,3 +142,4 @@ module Irc
end
end
+end
diff --git a/lib/rbot/load-gettext.rb b/lib/rbot/load-gettext.rb
index e95d4068..dd9961f5 100644
--- a/lib/rbot/load-gettext.rb
+++ b/lib/rbot/load-gettext.rb
@@ -22,7 +22,7 @@ begin
include GetText
- add_default_locale_path(File.join(Irc::Config.datadir, "../locale/%{locale}/LC_MESSAGES/%{name}.mo"))
+ add_default_locale_path(File.join(Irc::Bot::Config.datadir, "../locale/%{locale}/LC_MESSAGES/%{name}.mo"))
bindtextdomain 'rbot'
diff --git a/lib/rbot/message.rb b/lib/rbot/message.rb
index 969dbc7d..acfd5da3 100644
--- a/lib/rbot/message.rb
+++ b/lib/rbot/message.rb
@@ -4,20 +4,27 @@
# :title: IRC message datastructures
module Irc
- BotConfig.register BotConfigArrayValue.new('core.address_prefix',
- :default => [], :wizard => true,
- :desc => "what non nick-matching prefixes should the bot respond to as if addressed (e.g !, so that '!foo' is treated like 'rbot: foo')"
- )
-
- BotConfig.register BotConfigBooleanValue.new('core.reply_with_nick',
- :default => false, :wizard => true,
- :desc => "if true, the bot will prepend the nick to what he has to say when replying (e.g. 'markey: you can't do that!')"
- )
-
- BotConfig.register BotConfigStringValue.new('core.nick_postfix',
- :default => ':', :wizard => true,
- :desc => "when replying with nick put this character after the nick of the user the bot is replying to"
- )
+
+
+ class Bot
+ module Config
+ Config.register ArrayValue.new('core.address_prefix',
+ :default => [], :wizard => true,
+ :desc => "what non nick-matching prefixes should the bot respond to as if addressed (e.g !, so that '!foo' is treated like 'rbot: foo')"
+ )
+
+ Config.register BooleanValue.new('core.reply_with_nick',
+ :default => false, :wizard => true,
+ :desc => "if true, the bot will prepend the nick to what he has to say when replying (e.g. 'markey: you can't do that!')"
+ )
+
+ Config.register StringValue.new('core.nick_postfix',
+ :default => ':', :wizard => true,
+ :desc => "when replying with nick put this character after the nick of the user the bot is replying to"
+ )
+ end
+ end
+
# Define standard IRC attriubtes (not so standard actually,
# but the closest thing we have ...)
diff --git a/lib/rbot/messagemapper.rb b/lib/rbot/messagemapper.rb
index 7f13b7fb..8b52baa4 100644
--- a/lib/rbot/messagemapper.rb
+++ b/lib/rbot/messagemapper.rb
@@ -18,6 +18,7 @@ class Regexp
end
module Irc
+class Bot
# MessageMapper is a class designed to reduce the amount of regexps and
# string parsing plugins and bot modules need to do, in order to process
@@ -586,3 +587,4 @@ module Irc
end
end
end
+end
diff --git a/lib/rbot/plugins.rb b/lib/rbot/plugins.rb
index 96f61efc..5ad1ebb1 100644
--- a/lib/rbot/plugins.rb
+++ b/lib/rbot/plugins.rb
@@ -6,7 +6,8 @@
require 'singleton'
module Irc
- BotConfig.register BotConfigArrayValue.new('plugins.blacklist',
+class Bot
+ Config.register Config::ArrayValue.new('plugins.blacklist',
:default => [], :wizard => false, :requires_rescan => true,
:desc => "Plugins that should not be loaded")
module Plugins
@@ -17,7 +18,7 @@ module Plugins
functionality. Rather than subclassing BotModule, however, one should
subclass either CoreBotModule (reserved for system modules) or Plugin
(for user plugins).
-
+
A BotModule interacts with Irc events by defining one or more of the following
methods, which get called as appropriate when the corresponding Irc event
happens.
@@ -27,7 +28,7 @@ module Plugins
map is the new, cleaner way to respond to specific message formats without
littering your plugin code with regexps, and should be used instead of
#register() and #privmsg() (see below) when possible.
-
+
The difference between map and map! is that map! will not register the new
command as an alternative name for the plugin.
@@ -134,7 +135,7 @@ module Plugins
# the rbot instance
# @registry::
# the botmodule's registry, which can be used to store permanent data
- # (see BotRegistryAccessor for additional documentation)
+ # (see Registry::Accessor for additional documentation)
#
# Other instance variables which are defined and should not be overwritten
# byt the user, but aren't usually accessed directly, are:
@@ -153,7 +154,7 @@ module Plugins
@botmodule_triggers = Array.new
@handler = MessageMapper.new(self)
- @registry = BotRegistryAccessor.new(@bot, self.class.to_s.gsub(/^.*::/, ""))
+ @registry = Registry::Accessor.new(@bot, self.class.to_s.gsub(/^.*::/, ""))
@manager.add_botmodule(self)
if self.respond_to?('set_language')
@@ -683,9 +684,9 @@ module Plugins
key = $1
params = $2
- # Let's see if we can match a plugin by the given name
+ # Let's see if we can match a plugin by the given name
(core_modules + plugins).each { |p|
- next unless p.name == key
+ next unless p.name == key
begin
return p.help(key, params)
rescue Exception => err
@@ -694,7 +695,7 @@ module Plugins
end
}
- # Nope, let's see if it's a command, and ask for help at the corresponding botmodule
+ # Nope, let's see if it's a command, and ask for help at the corresponding botmodule
k = key.to_sym
if commands.has_key?(k)
p = commands[k][:botmodule]
@@ -792,3 +793,4 @@ module Plugins
end
end
+end
diff --git a/lib/rbot/rbotconfig.rb b/lib/rbot/rbotconfig.rb
index a282d770..1c10e5af 100644
--- a/lib/rbot/rbotconfig.rb
+++ b/lib/rbot/rbotconfig.rb
@@ -1,4 +1,5 @@
module Irc
+class Bot
module Config
unless defined?(@@datadir)
@@datadir = nil
@@ -66,3 +67,4 @@ module Irc
end
end
end
+end
diff --git a/lib/rbot/registry.rb b/lib/rbot/registry.rb
index 98c5b3ea..44756a35 100644
--- a/lib/rbot/registry.rb
+++ b/lib/rbot/registry.rb
@@ -1,10 +1,11 @@
require 'rbot/dbhash'
module Irc
+class Bot
- # this class is now used purely for upgrading from prior versions of rbot
+ # This class is now used purely for upgrading from prior versions of rbot
# the new registry is split into multiple DBHash objects, one per plugin
- class BotRegistry
+ class Registry
def initialize(bot)
@bot = bot
upgrade_data
@@ -71,7 +72,6 @@ module Irc
env.close
end
end
- end
# This class provides persistent storage for plugins via a hash interface.
@@ -94,7 +94,7 @@ module Irc
# in object store mode, don't make the mistake of treating it like a live
# object, e.g. (using the example above)
# @registry[:blah][:foo] = "flump"
- # will NOT modify the object in the registry - remember that BotRegistry#[]
+ # will NOT modify the object in the registry - remember that Registry#[]
# returns a Marshal.restore'd object, the object you just modified in place
# will disappear. You would need to:
# blah = @registry[:blah]
@@ -117,11 +117,11 @@ module Irc
# Your plugins section of the registry is private, it has its own namespace
# (derived from the plugin's class name, so change it and lose your data).
# Calls to registry.each etc, will only iterate over your namespace.
- class BotRegistryAccessor
+ class Accessor
attr_accessor :recovery
- # plugins don't call this - a BotRegistryAccessor is created for them and
+ # plugins don't call this - a Registry::Accessor is created for them and
# is accessible via @registry.
def initialize(bot, name)
@bot = bot
@@ -315,7 +315,7 @@ module Irc
end
def sub_registry(prefix)
- return BotRegistryAccessor.new(@bot, @name + "/" + prefix.to_s)
+ return Accessor.new(@bot, @name + "/" + prefix.to_s)
end
# returns the number of keys in your registry namespace
@@ -326,4 +326,6 @@ module Irc
end
+ end
+end
end