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.

68 lines
1.8 KiB

  1. # coding: utf-8
  2. module SlackMathbot
  3. module Commands
  4. class Member < SlackRubyBot::Commands::Base
  5. match /member\.php(?<url>.*)$/ do |client, _data, _match|
  6. # Initalize Mechanize
  7. agent = Mechanize.new
  8. pixiv_url = "http://www.pixiv.net/member.php" + _match[:url][0..-2]
  9. # Scrape page title
  10. title = agent.get(pixiv_url).title
  11. puts title
  12. # Scrape username
  13. username = agent.get(pixiv_url).at(".name").text
  14. puts username
  15. # Scrape profile comment
  16. profile_comment = agent.get(pixiv_url).at(".profile-comment").text.split("br { display : none;}")[-1]
  17. puts profile_comment
  18. # Scrape works count
  19. works = agent.get(pixiv_url).links_with(:class => /int/)
  20. puts works
  21. # Create iOS Member URL, must find correct URL scheme
  22. ios_mem_url = "pixiv://users/" + pixiv_url.split("?id=")[-1]
  23. puts ios_mem_url
  24. client.web_client.chat_postMessage(
  25. channel: _data.channel,
  26. as_user: true,
  27. attachments: [
  28. {
  29. fallback: title + " - " + pixiv_url,
  30. text: "<" + ios_mem_url + "|Open in App>",
  31. text: profile_comment,
  32. title: username,
  33. title_link: pixiv_url,
  34. color: "#2684BD",
  35. fields: [
  36. {
  37. title: "Works",
  38. value: works[0].text,
  39. short: true,
  40. },
  41. {
  42. title: "Bookmarks",
  43. value: works[1].text,
  44. short: true,
  45. },
  46. {
  47. title: "Follow",
  48. value: works[2].text,
  49. short: true,
  50. }
  51. ]
  52. }
  53. ].to_json
  54. )
  55. end
  56. end
  57. end
  58. end