require_relative "drill" class DrillPlugin COMMANDS = %w[ init start end ] attr_reader :bot, :drills def initialize(bot) @bot = bot @drills = Hash.new { Drill::Empty.new } end def handle_message(message) puts "[#{self.class.name}] Handling \"#{message.content}\" from #{message.author.display_name}" command = strip_prefix(message.content).split.first p command if command.nil? || command == "" || command == "help" || command == "!drill" handle_help message elsif COMMANDS.include? command drill = drills[message.channel.id] send("handle_#{command}", message, drill) else message.respond "Unknown command #{command}" end end def handle_init(message, drill) if drill.exists? message.respond "You've already got a drill running in this channel" else drills[message.channel.id] = Drill.new message.channel message.respond "New drill created!" end end def handle_start(message, drill) if drill.started? message.respond "This drill has already started!" elsif drill.exists? drill.start! message.respond "Drill started!" else message.respond "You have to `!drill init` before you can start the drill" end end def handle_end(message, drill) if !drill.exists? message.respond "There's no drill to end" elsif drill.started? drills.delete message.channel.id message.respond "Ending the drill now!" else message.respond "You have to `!drill start` before you can end the drill" end end def handle_help(message) message.respond "Insert help message here" end def strip_prefix(content) if content.start_with? "!drill" content.sub("!drill ", "") else content end end end