class Ducks
Constants
- ANIMAL
- COMMAND
- EMOJI
- FEEDS
Public Class Methods
Source
# File plugins/ducks.rb, line 57 def self.batchexecute_post(uri, body) AnimalNews.batchexecute_post(uri, body) end
Source
# File plugins/ducks.rb, line 40 def self.build_execute_text(items) items.empty? ? AnimalNews.no_news_message(ANIMAL) : format_report(items) end
Source
# File plugins/ducks.rb, line 44 def self.build_location_execute_text(location, items) area = AnimalNews.format_location_name(location) items.empty? ? AnimalNews.no_news_message(ANIMAL) : format_report(items, center: area) end
Source
# File plugins/ducks.rb, line 71 def self.clear_recent_articles! AnimalNews.clear_recent_articles! end
Source
# File plugins/ducks.rb, line 53 def self.collect_duck_news(fetch:) AnimalNews.collect_news(ANIMAL, fetch: fetch) end
Source
# File plugins/ducks.rb, line 20 def self.command_pattern AnimalNews.dedicated_command_pattern_for(COMMAND) end
Source
# File plugins/ducks.rb, line 36 def self.format_report(items, center: nil) AnimalNews.format_report(ANIMAL, items, center: center, emoji: EMOJI) end
Source
# File plugins/ducks.rb, line 49 def self.gather_duck_news(fetch:) AnimalNews.gather_news(ANIMAL, fetch: fetch, emoji: EMOJI) end
Source
# File plugins/ducks.rb, line 28 def self.location_pattern AnimalNews.dedicated_location_pattern_for(COMMAND) end
Source
# File plugins/ducks.rb, line 61 def self.lookup_duck_article(index, articles:, fetch:, post: method(:batchexecute_post)) return "Run !#{COMMAND} first" if articles.empty? AnimalNews.lookup_article(ANIMAL, index, articles: articles, command: COMMAND, fetch: fetch, post: post) end
Source
# File plugins/ducks.rb, line 24 def self.lookup_pattern AnimalNews.dedicated_lookup_pattern_for(COMMAND) end
Source
# File plugins/ducks.rb, line 67 def self.parse_location(text) AnimalNews.parse_location(text) end
Source
# File plugins/ducks.rb, line 79 def self.recent_articles_snapshot(channel) AnimalNews.recent_articles_snapshot(channel, ANIMAL) end
Source
# File plugins/ducks.rb, line 75 def self.store_recent_articles(channel, items) AnimalNews.store_recent_articles(channel, ANIMAL, items) end
Public Instance Methods
Source
# File plugins/ducks.rb, line 92 def batchexecute_post(uri, body) self.class.batchexecute_post(uri, body) end
Source
# File plugins/ducks.rb, line 87 def channel_key(message) target = message.channel || message.user target.respond_to?(:name) ? target.name : target.to_s end
Source
# File plugins/ducks.rb, line 96 def execute(m) fetch = method(:fetch_feed) items = self.class.collect_duck_news(fetch: fetch) self.class.store_recent_articles(channel_key(m), items) flood_safe_reply(m, self.class.build_execute_text(items)) rescue StandardError flood_safe_reply(m, AnimalNews.fetch_error_message(ANIMAL)) end
Source
# File plugins/ducks.rb, line 105 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) flood_safe_reply(m, self.class.build_location_execute_text(location, items)) rescue StandardError flood_safe_reply(m, AnimalNews.fetch_error_message(ANIMAL)) end
Source
# File plugins/ducks.rb, line 83 def fetch_feed(url) URI.parse(url).open("User-Agent" => AnimalNews::USER_AGENT).read end
Source
# File plugins/ducks.rb, line 120 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_duck_article(index, articles: articles, fetch: fetch, post: post) flood_safe_reply(m, text) end