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.9 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. pixiv_url = CGI.unescapeHTML(pixiv_url)
  10. puts pixiv_url
  11. # Scrape page title
  12. title = agent.get(pixiv_url).title
  13. puts title
  14. # Scrape username
  15. username = agent.get(pixiv_url).at(".name").text
  16. puts username
  17. # Scrape profile comment
  18. profile_comment = agent.get(pixiv_url).at(".profile-comment").text.split("br { display : none;}")[-1]
  19. puts profile_comment
  20. # Scrape works count
  21. works = agent.get(pixiv_url).links_with(:class => /int/)
  22. puts works
  23. # Create iOS Member URL, must find correct URL scheme
  24. ios_mem_url = "pixiv://users/" + pixiv_url.split("?id=")[-1]
  25. puts ios_mem_url
  26. client.web_client.chat_postMessage(
  27. channel: _data.channel,
  28. as_user: true,
  29. attachments: [
  30. {
  31. fallback: title + " - " + pixiv_url,
  32. text: "<" + ios_mem_url + "|Open Profile in App>\n" + profile_comment,
  33. title: "" + username + "",
  34. title_link: pixiv_url,
  35. color: "#2684BD",
  36. fields: [
  37. {
  38. title: "Works",
  39. value: works[0].text,
  40. short: true,
  41. },
  42. {
  43. title: "Bookmarks",
  44. value: works[1].text,
  45. short: true,
  46. },
  47. {
  48. title: "Follow",
  49. value: works[2].text,
  50. short: true,
  51. }
  52. ]
  53. }
  54. ].to_json
  55. )
  56. end
  57. end
  58. end
  59. end