class Crocodiles
Constants
- ANIMAL
- COMMAND
- EMOJI
- FEEDS
Public Class Methods
Source
# File plugins/crocodiles.rb, line 44 def self.batchexecute_post(uri, body) AnimalNews.batchexecute_post(uri, body) end
Source
# File plugins/crocodiles.rb, line 58 def self.clear_recent_articles! AnimalNews.clear_recent_articles! end
Source
# File plugins/crocodiles.rb, line 40 def self.collect_crocodile_news(fetch:) AnimalNews.collect_news(ANIMAL, fetch: fetch) end
Source
# File plugins/crocodiles.rb, line 20 def self.command_pattern AnimalNews.dedicated_command_pattern_for(COMMAND) end
Source
# File plugins/crocodiles.rb, line 36 def self.gather_crocodile_news(fetch:) AnimalNews.gather_news(ANIMAL, fetch: fetch, emoji: EMOJI) end
Source
# File plugins/crocodiles.rb, line 28 def self.location_pattern AnimalNews.dedicated_location_pattern_for(COMMAND) end
Source
# File plugins/crocodiles.rb, line 48 def self.lookup_crocodile_article(index, articles:, fetch:, post: method(:batchexecute_post)) return "Run !crocodiles first" if articles.empty? AnimalNews.lookup_article(ANIMAL, index, articles: articles, command: COMMAND, fetch: fetch, post: post) end
Source
# File plugins/crocodiles.rb, line 24 def self.lookup_pattern AnimalNews.dedicated_lookup_pattern_for(COMMAND) end
Source
# File plugins/crocodiles.rb, line 54 def self.parse_location(text) AnimalNews.parse_location(text) end
Source
# File plugins/crocodiles.rb, line 66 def self.recent_articles_snapshot(channel) AnimalNews.recent_articles_snapshot(channel, ANIMAL) end
Source
# File plugins/crocodiles.rb, line 62 def self.store_recent_articles(channel, items) AnimalNews.store_recent_articles(channel, ANIMAL, items) end
Public Instance Methods
Source
# File plugins/crocodiles.rb, line 79 def batchexecute_post(uri, body) self.class.batchexecute_post(uri, body) end
Source
# File plugins/crocodiles.rb, line 74 def channel_key(message) target = message.channel || message.user target.respond_to?(:name) ? target.name : target.to_s end
Source
# File plugins/crocodiles.rb, line 83 def execute(m) fetch = method(:fetch_feed) items = self.class.collect_crocodile_news(fetch: fetch) self.class.store_recent_articles(channel_key(m), items) text = items.empty? ? AnimalNews.no_news_message(ANIMAL) : AnimalNews.format_report(ANIMAL, items, emoji: EMOJI) flood_safe_reply(m, text) rescue StandardError flood_safe_reply(m, AnimalNews.fetch_error_message(ANIMAL)) end
Source
# File plugins/crocodiles.rb, line 93 def execute_location(m, location_text) location = self.class.parse_location(location_text) unless location 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) self.class.store_recent_articles(channel_key(m), items) area = AnimalNews.format_location_name(location) text = items.empty? ? AnimalNews.no_news_message(ANIMAL) : AnimalNews.format_report(ANIMAL, items, center: area, emoji: EMOJI) flood_safe_reply(m, text) rescue StandardError flood_safe_reply(m, AnimalNews.fetch_error_message(ANIMAL)) end
Source
# File plugins/crocodiles.rb, line 70 def fetch_feed(url) URI.parse(url).open("User-Agent" => AnimalNews::USER_AGENT).read end
Source
# File plugins/crocodiles.rb, line 110 def lookup_article_command(m, index_text) index = AnimalNews.parse_article_index(index_text) unless index flood_safe_reply(m, "Pick a story from 1 to 5") return end articles = self.class.recent_articles_snapshot(channel_key(m)) fetch = method(:fetch_feed) post = method(:batchexecute_post) text = self.class.lookup_crocodile_article(index, articles: articles, fetch: fetch, post: post) flood_safe_reply(m, text) end