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

split_point, truncate

Constructor Details

#initialize(irc_provider = NoIRC) ⇒ Bot

The YARR IRC bot

Parameters:

  • irc_provider (Cinch::Bot) (defaults to: NoIRC)

    IRC functionality provider.


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\"}"

Parameters:

  • message (String)

    incoming message (without IRC command prefix)

Returns:

  • (String)

    response string


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

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