Parent

Class/Module Index [+]

Quicksearch

ConfigModule

Author

Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>

Public Instance Methods

bot_nick(m, param) click to toggle source
# File lib/rbot/core/config.rb, line 186
def bot_nick(m, param)
  @bot.nickchg(param[:nick])
  @bot.wanted_nick = param[:nick]
end
bot_rescan(m, param) click to toggle source
# File lib/rbot/core/config.rb, line 178
def bot_rescan(m, param)
  m.reply _("saving ...")
  @bot.save
  m.reply _("rescanning ...")
  @bot.rescan
  m.reply _("done. %{plugin_status}") % {:plugin_status => @bot.plugins.status(true)}
end
bot_save(m, param) click to toggle source
# File lib/rbot/core/config.rb, line 173
def bot_save(m, param)
  @bot.save
  m.okay
end
bot_status(m, param) click to toggle source
# File lib/rbot/core/config.rb, line 191
def bot_status(m, param)
  m.reply @bot.status
end
bot_version(m, param) click to toggle source

TODO is this one of the methods that disappeared when the bot was moved from the single-file to the multi-file registry?

def bot_reg_stat(m, param)
  m.reply @registry.stat.inspect
end
# File lib/rbot/core/config.rb, line 202
def bot_version(m, param)
  m.reply version_string
end
ctcp_listen(m) click to toggle source
# File lib/rbot/core/config.rb, line 206
def ctcp_listen(m)
  who = m.private? ? "me" : m.target
  case m.ctcp.intern
  when :VERSION
    m.ctcp_reply version_string
  when :SOURCE
    m.ctcp_reply Irc::Bot::SOURCE_URL
  end
end
handle_add(m, params) click to toggle source
# File lib/rbot/core/config.rb, line 123
def handle_add(m, params)
  key = params[:key].to_s.intern
  values = params[:value].to_s.split(/,\s+/)
  unless @bot.config.items.has_key?(key)
    m.reply _("no such config key %{key}") % {:key => key}
    return
  end
  unless @bot.config.items[key].kind_of?(Config::ArrayValue)
    m.reply _("config key %{key} is not an array") % {:key => key}
    return
  end
  return if !@bot.auth.allow?(@bot.config.items[key].auth_path, m.source, m.replyto)
  values.each do |value|
    begin
      @bot.config.items[key].add(value)
    rescue ArgumentError => e
      m.reply _("failed to add %{value} to %{key}: %{error}") % {:value => value, :key => key, :error => e.message}
      next
    end
  end
  handle_get(m,{:key => key})
  m.reply _("this config change will take effect on the next restart") if @bot.config.items[key].requires_restart
  m.reply _("this config change will take effect on the next rescan") if @bot.config.items[key].requires_rescan
end
handle_desc(m, params) click to toggle source
# File lib/rbot/core/config.rb, line 63
def handle_desc(m, params)
  key = params[:key].to_s.intern
  unless @bot.config.items.has_key?(key)
    m.reply _("no such config key %{key}") % {:key => key}
  end
  m.reply "#{key}: #{@bot.config.items[key].desc}"
end
handle_get(m, params) click to toggle source
# File lib/rbot/core/config.rb, line 52
def handle_get(m, params)
  key = params[:key].to_s.intern
  unless @bot.config.items.has_key?(key)
    m.reply _("no such config key %{key}") % {:key => key}
    return
  end
  return if !@bot.auth.allow?(@bot.config.items[key].auth_path, m.source, m.replyto)
  value = @bot.config.items[key].to_s
  m.reply "#{key}: #{value}"
end
handle_help(m, params) click to toggle source
# File lib/rbot/core/config.rb, line 216
def handle_help(m, params)
  m.reply help(params[:topic])
end
handle_list(m, params) click to toggle source
# File lib/rbot/core/config.rb, line 30
def handle_list(m, params)
  modules = []
  if params[:module]
    @bot.config.items.each_key do |key|
      mod, name = key.to_s.split('.')
      next unless mod == params[:module]
      modules.push key unless modules.include?(name)
    end
    if modules.empty?
      m.reply _("no such module %{module}") % {:module => params[:module]}
    else
      m.reply modules.join(", ")
    end
  else
    @bot.config.items.each_key do |key|
      name = key.to_s.split('.').first
      modules.push name unless modules.include?(name)
    end
    m.reply "modules: " + modules.join(", ")
  end
end
handle_rm(m, params) click to toggle source
# File lib/rbot/core/config.rb, line 148
def handle_rm(m, params)
  key = params[:key].to_s.intern
  values = params[:value].to_s.split(/,\s+/)
  unless @bot.config.items.has_key?(key)
    m.reply _("no such config key %{key}") % {:key => key}
    return
  end
  unless @bot.config.items[key].kind_of?(Config::ArrayValue)
    m.reply _("config key %{key} is not an array") % {:key => key}
    return
  end
  return if !@bot.auth.allow?(@bot.config.items[key].auth_path, m.source, m.replyto)
  values.each do |value|
    begin
      @bot.config.items[key].rm(value)
    rescue ArgumentError => e
      m.reply _("failed to remove %{value} from %{key}: %{error}") % {:value => value, :key => key, :error => e.message}
      next
    end
  end
  handle_get(m,{:key => key})
  m.reply _("this config change will take effect on the next restart") if @bot.config.items[key].requires_restart
  m.reply _("this config change will take effect on the next rescan") if @bot.config.items[key].requires_rescan
end
handle_search(m, params) click to toggle source
# File lib/rbot/core/config.rb, line 71
def handle_search(m, params)
  rx = Regexp.new(params[:rx].to_s, true)
  cfs = []
  @bot.config.items.each do |k, v|
    cfs << [Bold + k.to_s + Bold, v.desc] if k.to_s.match(rx) or (v.desc.match(rx) rescue false)
  end
  if cfs.empty?
    m.reply _("no config key found matching %{r}") % { :r => params[:rx].to_s}
  else
    m.reply _("possible keys: %{kl}") % { :kl => cfs.map { |c| c.first}.sort.join(', ') } if cfs.length > 1
    m.reply cfs.map { |c| c.join(': ') }.join("\n")
  end
end
handle_set(m, params) click to toggle source
# File lib/rbot/core/config.rb, line 97
def handle_set(m, params)
  key = params[:key].to_s.intern
  value = params[:value].join(" ")
  unless @bot.config.items.has_key?(key)
    m.reply _("no such config key %{key}") % {:key => key} unless params[:silent]
    return false
  end
  return false if !@bot.auth.allow?(@bot.config.items[key].auth_path, m.source, m.replyto)
  begin
    @bot.config.items[key].set_string(value)
  rescue ArgumentError => e
    m.reply _("failed to set %{key}: %{error}") % {:key => key, :error => e.message} unless params[:silent]
    return false
  end
  if @bot.config.items[key].requires_restart
    m.reply _("this config change will take effect on the next restart") unless params[:silent]
    return :restart
  elsif @bot.config.items[key].requires_rescan
    m.reply _("this config change will take effect on the next rescan") unless params[:silent]
    return :rescan
  else
    m.okay unless params[:silent]
    return true
  end
end
handle_unset(m, params) click to toggle source
# File lib/rbot/core/config.rb, line 85
def handle_unset(m, params)
  key = params[:key].to_s.intern
  unless @bot.config.items.has_key?(key)
    m.reply _("no such config key %{key}") % {:key => key}
  end
  return if !@bot.auth.allow?(@bot.config.items[key].auth_path, m.source, m.replyto)
  @bot.config.items[key].unset
  handle_get(m, params)
  m.reply _("this config change will take effect on the next restart") if @bot.config.items[key].requires_restart
  m.reply _("this config change will take effect on the next rescan") if @bot.config.items[key].requires_rescan
end
help(plugin, topic="") click to toggle source
# File lib/rbot/core/config.rb, line 220
def help(plugin, topic="")
  case plugin
  when "config"
    case topic
    when "list"
    _("config list => list configuration modules, config list <module> => list configuration keys for module <module>")
    when "get"
    _("config get <key> => get configuration value for key <key>")
    when "unset"
    _("reset key <key> to the default")
    when "set"
    _("config set <key> <value> => set configuration value for key <key> to <value>")
    when "desc"
    _("config desc <key> => describe what key <key> configures")
    when "add"
    _("config add <values> to <key> => add values <values> to key <key> if <key> is an array")
    when "rm"
    _("config rm <value> from <key> => remove value <value> from key <key> if <key> is an array")
    else
    _("config module - bot configuration. usage: list, desc, get, set, unset, add, rm")
    # else
    #   "no help for config #{topic}"
    end
  when "nick"
    _("nick <newnick> => change the bot nick to <newnick>, if possible")
  when "status"
    _("status => display some information on the bot's status")
  when "save"
    _("save => save current dynamic data and configuration")
  when "rescan"
    _("rescan => reload modules and static facts")
  when "version"
    _("version => describes software version")
  else
    _("config-related tasks: config, save, rescan, version, nick, status")
  end
end
save() click to toggle source
# File lib/rbot/core/config.rb, line 26
def save
  @bot.config.save
end
version_string() click to toggle source
# File lib/rbot/core/config.rb, line 10
def version_string
  if $version_timestamp.to_i > 0
    ago = _(" [%{secs} ago]") % {
      :secs => Utils.secs_to_string(Time.now.to_i - $version_timestamp.to_i)
    }
  else
    ago = ''
  end
  _("I'm a v. %{version}%{ago} rubybot%{copyright}%{url}") % {
    :version => $version,
    :ago => ago,
    :copyright => ", #{Irc::Bot::COPYRIGHT_NOTICE}",
    :url => " - #{Irc::Bot::SOURCE_URL}"
  }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.