class Animal
Constants
- ANIMAL_TOKEN
- COMMAND
Public Class Methods
Source
# File plugins/animal.rb, line 19 def self.command_pattern /animal (#{ANIMAL_TOKEN})$/ end
Source
# File plugins/animal.rb, line 27 def self.location_pattern /animal (#{ANIMAL_TOKEN}) ((?![1-5]$)[a-zA-Z][a-zA-Z0-9\-_]*(?:[ \-_][a-zA-Z][a-zA-Z0-9\-_]*)*)$/ end
Source
# File plugins/animal.rb, line 23 def self.lookup_pattern /animal (#{ANIMAL_TOKEN}) ([1-5])$/ end
Public Instance Methods
Source
# File plugins/animal.rb, line 41 def batchexecute_post(uri, body) AnimalNews.batchexecute_post(uri, body) end
Source
# File plugins/animal.rb, line 45 def channel_key(message) target = message.channel || message.user target.respond_to?(:name) ? target.name : target.to_s end
Source
# File plugins/animal.rb, line 50 def execute(m, animal_text) animal = AnimalNews.parse_animal(animal_text) unless animal themed_flood_safe_reply(m, "Name an animal") return end fetch = method(:fetch_feed) items = AnimalNews.collect_news(animal, fetch: fetch) AnimalNews.store_recent_articles(channel_key(m), animal, items) text = items.empty? ? AnimalNews.no_news_message(animal) : AnimalNews.format_report(animal, items) themed_flood_safe_reply(m, text) rescue StandardError themed_flood_safe_reply(m, AnimalNews.fetch_error_message(animal_text)) end
Source
# File plugins/animal.rb, line 66 def execute_location(m, animal_text, location_text) animal = AnimalNews.parse_animal(animal_text) unless animal themed_flood_safe_reply(m, "Name an animal") return end location = AnimalNews.parse_location(location_text) unless location themed_flood_safe_reply(m, "Pick a story from 1 to 5") return end fetch = method(:fetch_feed) items = AnimalNews.collect_news_for_location(animal, location, fetch: fetch) AnimalNews.store_recent_articles(channel_key(m), animal, items) area = AnimalNews.format_location_name(location) text = items.empty? ? AnimalNews.no_news_message(animal) : AnimalNews.format_report(animal, items, center: area) themed_flood_safe_reply(m, text) rescue StandardError themed_flood_safe_reply(m, AnimalNews.fetch_error_message(animal)) end
Source
# File plugins/animal.rb, line 37 def fetch_feed(url) URI.parse(url).open("User-Agent" => AnimalNews::USER_AGENT).read end
Source
# File plugins/animal.rb, line 89 def lookup_article_command(m, animal_text, index_text) animal = AnimalNews.parse_animal(animal_text) unless animal themed_flood_safe_reply(m, "Name an animal") return end index = AnimalNews.parse_article_index(index_text) unless index themed_flood_safe_reply(m, "Pick a story from 1 to 5") return end articles = AnimalNews.recent_articles_snapshot(channel_key(m), animal) fetch = method(:fetch_feed) post = method(:batchexecute_post) text = AnimalNews.lookup_article(animal, index, articles: articles, command: COMMAND, fetch: fetch, post: post) themed_flood_safe_reply(m, text) end