Class: Elephrame::Bots::MarkovBot

Inherits:
GenerativeBot show all
Defined in:
lib/elephrame/mix/bots.rb

Overview

A more general purpose markov bot. Reads in data from a supplied source

Constant Summary

Constants inherited from GenerativeBot

GenerativeBot::SavedFileName, GenerativeBot::SavedFilterFileName

Constants inherited from BaseBot

BaseBot::FNGabLink, BaseBot::NoBotRegex

Instance Attribute Summary

Attributes inherited from GenerativeBot

#char_limit, #cw, #filter, #filter_by, #filter_filename, #filter_words, #following, #model, #model_filename, #model_hash, #retry_limit, #visibility

Attributes included from Command

#cmd_hash, #cmd_regex, #commands, #not_found, #prefix

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 inherited from GenerativeBot

#add_filter_word, #add_privileged_command, #default_help, #filter_and_post, #load_file, #run, #save_file

Methods included from Command

#add_command, #if_not_found, #run_commands, #set_help, #set_prefix, #setup_command

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, *sources, **options) ⇒ MarkovBot

Creates a new Ebooks bot

Parameters:

  • interval (String)

    how often should the bot post on it’s own

  • sources (Array)

    all of the sources for the bot. either folders or files

  • opts (Hash)

    options for the bot

  • opt (Hash)

    a customizable set of options



357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/elephrame/mix/bots.rb', line 357

def initialize(interval, *sources, **options)
  super(interval, options)

  raise 'no sources provided!' if sources.empty?
  
  # initialize the model to contain the specified source text
  if @model_hash[:model].tokens.empty?
    sources.each do |source|
      if Dir.exists? source
        Dir.open source do |file|
          next if file =~ /^\.\.?$/
          read_and_consume "#{source}/#{file}"
        end
      elsif File.exists? source
        read_and_consume source
      else
        raise "source #{source} could not be loaded"
      end
    end

    save_file(@model_filename,
              @model_hash[:model].to_hash.to_yaml)
  end
end