Class: Elephrame::Bots::TraceryBot

Inherits:
BaseBot
  • Object
show all
Includes:
Reply, Scheduler, Streaming, Trace
Defined in:
lib/elephrame/mix/bots.rb

Overview

a bot that posts things on an interval but can also respond to interactions, providing a grammer object and a few helper methods to easily create bots with tracery.

set on_reply before running, otherwise the bot won’t react to mentions

Constant Summary

Constants inherited from BaseBot

BaseBot::FNGabLink, BaseBot::NoBotRegex

Instance Attribute Summary

Attributes included from Trace

#grammar

Attributes included from Reply

#on_reply

Attributes included from Scheduler

#schedule, #scheduler

Attributes included from Streaming

#streamer

Attributes inherited from BaseBot

#client, #failed, #max_retries, #strip_html, #username

Instance Method Summary collapse

Methods included from Trace

#expand_and_post, #setup_tracery

Methods included from Reply

#reply, #reply_with_mentions, #run_reply

Methods included from Scheduler

#run_scheduled, #setup_scheduler

Methods included from Streaming

#setup_streaming

Methods inherited from BaseBot

backup_method, #fetch_account_id, #fetch_list_id, #find_ancestor, #no_bot?, #post

Constructor Details

#initialize(interval, *dirs) ⇒ Elephrame::Bots::TraceryBot

create a new TraceryBot

Parameters:

  • interval (String)

    a string representing the interval to post

  • dirs (Array<String>)

    an array of strings with paths to directories containing tracery grammer rules



70
71
72
73
74
75
76
77
# File 'lib/elephrame/mix/bots.rb', line 70

def initialize interval, *dirs
  super()

  # set up our bot stuff
  setup_scheduler interval
  setup_streaming
  setup_tracery *dirs
end

Instance Method Details

#runObject

Runs the bot. requires a block for periodic post logic, but relies on on_* functions for interaction logic. See Elephrame::AllInteractions for more details.



84
85
86
87
88
89
90
91
# File 'lib/elephrame/mix/bots.rb', line 84

def run
  run_scheduled &Proc.new

  # if we have any logic for on_reply, we run that
  #  otherwise we go past it and wait for our scheduler to finish
  run_reply unless @on_reply.nil?
  @scheduler.join
end