A Slack Bot that pulls Pixiv information and posts the full image(s) into Slack, with iOS shortcuts.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1003 B

  1. # coding: utf-8
  2. module SlackMathbot
  3. module Commands
  4. class Pixiv < SlackRubyBot::Commands::Base
  5. match /pixiv\.net(?<url>.*)$/ do |client, _data, _match|
  6. # Initalize Mechanize
  7. agent = Mechanize.new
  8. # Create Pixiv URL
  9. pixiv_url = "http://www.pixiv.net" + _match[:url][0..-2]
  10. puts pixiv_url
  11. # Scrape page title
  12. title = Mechanize.new.get(pixiv_url).title
  13. puts title
  14. # Scrape image
  15. image_url = agent.get(pixiv_url).images_with(:src => /600x600\/img-master/)[0].to_s.sub! '600x600','480x960'
  16. puts image_url
  17. client.web_client.chat_postMessage(
  18. channel: _data.channel,
  19. as_user: true,
  20. attachments: [
  21. {
  22. fallback: title + " - " + pixiv_url,
  23. title: title,
  24. title_link: pixiv_url,
  25. image_url: image_url,
  26. color: "#2684BD"
  27. }
  28. ].to_json
  29. )
  30. end
  31. end
  32. end
  33. end