require_relative "../../lesson" class Plugin class LessonPlugin < Plugin attr_reader :lessons def initialize(ika) super @lessons = {} end def handle_message(message) super Message.new(self, message).handle end def can_handle_message?(message) return true if message.content == "!lesson" return true if message.content == "!stoplesson" return false unless lessons[message.channel.id] true end class Message attr_reader :plugin, :message def initialize(plugin, message) @plugin = plugin @message = message end def content message.content end def responder message.responder end def respond(response) responder.call response end def handle return handle_lesson if content == "!lesson" return handle_stoplesson if content == "!stoplesson" lesson.handle_message(message) end def lesson lsn = plugin.lessons[message.channel.id] return lsn if lsn lsn = Lesson.new responder: responder plugin.lessons[message.channel.id] = lsn end def handle_lesson if lesson.running? respond "There's already a lesson running!" else respond "Starting a lesson now!" lesson.start! end end def handle_stoplesson if lesson.running? respond "Ending the current lesson" lesson.stop! else respond "There's no lesson running" end end end end end