ika_bot/lib/message.rb

110 lines
1.8 KiB
Ruby

class Message
attr_reader :responder
def initialize(responder)
@responder = responder
end
def content
# TODO: figure out how to delegate
discord_message.content
end
def author
# TODO: figure out how to delegate
discord_message.author
end
def channel
# TODO: figure out how to delegate
discord_message.channel
end
def respond(response)
# TODO: figure out how to delegate
discord_message.respond response
end
def message
discord_message
end
def words
content.split(" ")
end
def first_word
words.first
end
def command_message?
first_word.start_with? "!"
end
def command
command_message? ? first_word[1..] : nil
end
def subcommand
command_message? ? words[1] : nil
end
def params
command_message? ? words[2..] : []
end
class Console < Message
attr_reader :content
def initialize(responder, content)
super(responder)
@content = content
end
def author
OpenStruct.new(display_name: "CHANGE ME")
end
def channel
OpenStruct.new(id: nil)
end
def respond(response)
responder.call response
end
end
class Discord < Message
attr_reader :discord_message
def initialize(responder, discord_message)
super(responder)
@discord_message = discord_message
end
def content
# TODO: figure out how to delegate
discord_message.content
end
def author
# TODO: figure out how to delegate
discord_message.author
end
def channel
# TODO: figure out how to delegate
discord_message.channel
end
def respond(response)
# TODO: figure out how to delegate
discord_message.respond response
end
def message
discord_message
end
end
end