From 376b34ee7249525b0adb49e8c8043ab2fa0d8347 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 14 Apr 2014 05:12:50 -0700 Subject: Rename Echo to Test and add error testing. --- dinobot.rb | 9 ++++----- echo.rb | 15 --------------- example.rb | 2 +- test.rb | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+), 21 deletions(-) delete mode 100644 echo.rb create mode 100644 test.rb diff --git a/dinobot.rb b/dinobot.rb index 01b9735..01eeeab 100644 --- a/dinobot.rb +++ b/dinobot.rb @@ -46,7 +46,8 @@ module Dinobot begin parse_line(str) - rescue + rescue => e + puts "== Error parsing line. (#{e})" end end @@ -111,17 +112,15 @@ module Dinobot mod = mod.downcase.intern puts "== Loading module: #{mod}" - file = "#{mod}.rb" - begin - load file + load "#{mod}.rb" m = Dinobot.const_get(Dinobot.constants.find { |x| x.downcase == mod }) @modules[mod] = m.new puts "== Loaded module: #{mod} (#{m})" rescue LoadError, StandardError => e - puts "== Failed to load module: #{mod} (#{e.message})" + puts "== Failed to load module: #{mod} (#{e})" end end diff --git a/echo.rb b/echo.rb deleted file mode 100644 index 34b9770..0000000 --- a/echo.rb +++ /dev/null @@ -1,15 +0,0 @@ -require_relative 'module' - -module Dinobot - class Echo < Module - def initialize - super - - @commands << :echo - end - - def echo(user, channel, argument) - [[:say, channel, argument]] - end - end -end diff --git a/example.rb b/example.rb index c161af5..fe2b0ef 100644 --- a/example.rb +++ b/example.rb @@ -5,7 +5,7 @@ require_relative 'dinobot' bot = Dinobot::Bot.new('irc.example.org', 6667, 'dinobot') do join '#dinobot' - load_module :echo + load_module :test end loop do diff --git a/test.rb b/test.rb new file mode 100644 index 0000000..f2010a0 --- /dev/null +++ b/test.rb @@ -0,0 +1,19 @@ +require_relative 'module' + +module Dinobot + class Test < Module + def initialize + super + + @commands << :echo << :error + end + + def echo(user, channel, argument) + [[:say, channel, argument]] + end + + def error(user, channel, argument) + x + end + end +end -- cgit v1.2.3-70-g09d2