diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-04-14 02:06:53 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-04-14 02:06:53 -0700 |
commit | f35ae6761d9656ec51bd9176a83320c5dcf44278 (patch) | |
tree | c0ae3eccc5dacbcddc91c0152ff5e99783299e7a /dinobot.rb | |
parent | 3446d5f2ec4263fc097d4d5c7996d88daf220693 (diff) | |
download | dinobot-f35ae6761d9656ec51bd9176a83320c5dcf44278.tar.gz dinobot-f35ae6761d9656ec51bd9176a83320c5dcf44278.tar.xz |
Add support for modules.
Diffstat (limited to 'dinobot.rb')
-rw-r--r-- | dinobot.rb | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -55,6 +55,27 @@ module Dinobot def parse_line(str) out str.sub('PING', 'PONG') if str =~ /^PING / + + if str =~ /(\S+) PRIVMSG (\S+) :(.*)/ + user, channel, message = str.scan(/(\S+) PRIVMSG (\S+) :(.*)/).first + + if @modules.has_key?(message.split.first.sub(/^#{Regexp.escape(@trigger)}/, '').downcase.intern) + ret = @modules[message.split.first.sub(/^#{Regexp.escape(@trigger)}/, '').downcase.intern].call(user, channel, message) + + exec_commands(ret) + end + end + end + + def exec_commands(commands) + commands.each do |command| + case command.first + when :say + send(*command) if command.length == 3 + when :join, :part + send(*command) if command.length == 2 + end + end end def out(str) @@ -80,5 +101,16 @@ module Dinobot out "PART #{channel}" end + + def load_module(mod) + file = Dir.entries(File.dirname(__FILE__)).find { |x| x == mod.to_s.downcase + ".rb" } + + if file + puts "== Loading #{mod}." + + load file + @modules[mod.downcase] = eval("Dinobot::#{mod}").new + end + end end end |