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.

67 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 Profile in App>\n" + profile_comment,
  31. title: "" + username + "",
  32. title_link: pixiv_url,
  33. color: "#2684BD",
  34. fields: [
  35. {
  36. title: "Works",
  37. value: works[0].text,
  38. short: true,
  39. },
  40. {
  41. title: "Bookmarks",
  42. value: works[1].text,
  43. short: true,
  44. },
  45. {
  46. title: "Follow",
  47. value: works[2].text,
  48. short: true,
  49. }
  50. ]
  51. }
  52. ].to_json
  53. )
  54. end
  55. end
  56. end
  57. end