aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-14 14:18:01 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-14 14:18:01 -0700
commit64cc3ddcea4c6c45298d6e5e65f6b0c74e4d9b0a (patch)
tree182a4565b48548e1cbd4e41a534efe26b50bb37b
parent29cc359a91d8f73f9a2f4e47646e691bfe117346 (diff)
downloaddinobot-64cc3ddcea4c6c45298d6e5e65f6b0c74e4d9b0a.tar.gz
dinobot-64cc3ddcea4c6c45298d6e5e65f6b0c74e4d9b0a.tar.xz
Load/unload modules via admin commands.
-rw-r--r--admin.rb18
-rw-r--r--dinobot.rb10
2 files changed, 23 insertions, 5 deletions
diff --git a/admin.rb b/admin.rb
index 3fc0338..61e454b 100644
--- a/admin.rb
+++ b/admin.rb
@@ -5,7 +5,7 @@ module Dinobot
def initialize
super
- @commands << :join << :part
+ @commands << :join << :part << :listadmins << :load << :unload
@admins = Array.new
end
@@ -30,5 +30,21 @@ module Dinobot
def part(user, channel, argument)
[[:part, argument]] if is_admin?(user)
end
+
+ def listadmins(user, channel, argument)
+ [[:say, channel, @admins.join(' ')]] if is_admin?(user)
+ end
+
+ def load(user, channel, argument)
+ argument.split.map do |x|
+ [:load_module, x.intern]
+ end
+ end
+
+ def unload(user, channel, argument)
+ argument.split.map do |x|
+ [:unload_module, x.intern]
+ end
+ end
end
end
diff --git a/dinobot.rb b/dinobot.rb
index 4828aac..052bb10 100644
--- a/dinobot.rb
+++ b/dinobot.rb
@@ -47,7 +47,7 @@ module Dinobot
begin
parse_line(str)
rescue => e
- puts "== Error parsing line. (#{e})"
+ puts "!! Error parsing line. (#{e})"
end
end
@@ -77,10 +77,12 @@ module Dinobot
def exec_commands(commands)
commands.each do |command|
+ puts "== Executing command: #{command.inspect}"
+
case command.first
when :say
send(*command) if command.length == 3
- when :join, :part
+ when :join, :part, :load_module, :unload_module
send(*command) if command.length == 2
end
end
@@ -122,7 +124,7 @@ module Dinobot
puts "== Loaded module: #{mod} (#{m})"
rescue LoadError, StandardError => e
- puts "== Failed to load module: #{mod} (#{e})"
+ puts "!! Failed to load module: #{mod} (#{e})"
end
end
@@ -131,7 +133,7 @@ module Dinobot
puts "== Unloading module: #{mod}"
unless @modules.has_key?(mod)
- puts "== Failed to unload module: #{mod} (module not loaded)"
+ puts "!! Failed to unload module: #{mod} (module not loaded)"
return
end