Class: Yarr::Bot

Inherits:
Object
  • Object
show all
Includes:
Message::Truncator
Defined in:
lib/yarr/bot.rb

Overview

Handles the incoming message string and returns a response string.

Constant Summary

Constants included from Message::Truncator

Message::Truncator::MAX_LENGTH, Message::Truncator::OMISSION, Message::Truncator::SEPARATOR

Instance Method Summary collapse

Methods included from Message::Truncator

first_line, split_point, truncate

Constructor Details

#initialize(irc_provider = NoIRC) ⇒ Bot

The YARR IRC bot


14
15
16
17
# File 'lib/yarr/bot.rb', line 14

def initialize(irc_provider = NoIRC)
  @parser = InputParser.new
  @irc = irc_provider
end

Instance Method Details

#reply_to(message) ⇒ String

Replies to a message

Examples:


bot = Yarr::Bot.new
bot.reply_to 'ri Array' # => "https://ruby-doc.org/core-2.5.1/Array.html"
bot.reply_to 'ast ast' # => "{:command=>\"ast\", :method_name=>\"ast\"}"

30
31
32
33
34
35
36
# File 'lib/yarr/bot.rb', line 30

def reply_to(message)
  ast, stuff = parse_input(message)
  response = Command.for_ast(ast, @irc).handle
  post_process(response, stuff)
rescue InputParser::ParseError => e
  e.report(message)
end