Method: ConfigModule#handle_add

Defined in:
lib/rbot/core/config.rb

#handle_add(m, params) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# 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