diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-04-14 14:57:03 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-04-14 14:57:03 -0700 |
commit | 0fee37a63b588d84b4d91e5ad5074ffb71f698a4 (patch) | |
tree | 3ba854e5610ff14d5bdf401313d2e2b6ddccbdb0 | |
parent | 64cc3ddcea4c6c45298d6e5e65f6b0c74e4d9b0a (diff) | |
download | dinobot-0fee37a63b588d84b4d91e5ad5074ffb71f698a4.tar.gz dinobot-0fee37a63b588d84b4d91e5ad5074ffb71f698a4.tar.xz |
Multithreading and timeout functionality.
-rw-r--r-- | admin.rb | 12 | ||||
-rw-r--r-- | dinobot.rb | 13 | ||||
-rw-r--r-- | test.rb | 6 |
3 files changed, 20 insertions, 11 deletions
@@ -36,15 +36,15 @@ module Dinobot end def load(user, channel, argument) - argument.split.map do |x| - [:load_module, x.intern] - end + return unless is_admin?(user) + + argument.split.map { |x| [:load_module, x.intern] } end def unload(user, channel, argument) - argument.split.map do |x| - [:unload_module, x.intern] - end + return unless is_admin?(user) + + argument.split.map { |x| [:unload_module, x.intern] } end end end @@ -1,4 +1,5 @@ require 'socket' +require 'timeout' module Dinobot class Bot @@ -44,10 +45,14 @@ module Dinobot str.chomp! puts "<< #{str.inspect}" - begin - parse_line(str) - rescue => e - puts "!! Error parsing line. (#{e})" + Thread.new do + begin + Timeout.timeout(30) do + parse_line(str) + end + rescue => e + puts "!! Error parsing line. (#{e})" + end end end @@ -5,7 +5,7 @@ module Dinobot def initialize super - @commands << :echo << :error + @commands << :echo << :error << :timeout end def echo(user, channel, argument) @@ -15,5 +15,9 @@ module Dinobot def error(user, channel, argument) x end + + def timeout(user, channel, argument) + sleep 60 + end end end |