diff --git a/slack-pixiv.rb b/slack-pixiv.rb index 860f370..8e1ddda 100644 --- a/slack-pixiv.rb +++ b/slack-pixiv.rb @@ -2,5 +2,6 @@ require 'slack-ruby-bot' require 'wolfram' require 'mechanize' require 'nokogiri' -require 'slack-pixiv/commands/pixiv' +require 'slack-pixiv/commands/illust' +require 'slack-pixiv/commands/member' require 'slack-pixiv/app' diff --git a/slack-pixiv/commands/pixiv.rb b/slack-pixiv/commands/illust.rb similarity index 89% rename from slack-pixiv/commands/pixiv.rb rename to slack-pixiv/commands/illust.rb index cb6bd42..641f657 100644 --- a/slack-pixiv/commands/pixiv.rb +++ b/slack-pixiv/commands/illust.rb @@ -1,7 +1,7 @@ # coding: utf-8 module SlackMathbot module Commands - class Pixiv < SlackRubyBot::Commands::Base + class Illust < SlackRubyBot::Commands::Base match /member_illust\.php(?.*)$/ do |client, _data, _match| # Initalize Mechanize @@ -23,11 +23,6 @@ module SlackMathbot ios_url = "pixiv://illusts/" + pixiv_url[/\d+/] puts ios_url - - # TODO: Create iOS Member URL, must find correct URL scheme - ios_mem_url = "pixiv://member/" + pixiv_url.split("?id=")[-1] - puts ios_mem_url - # Scrape page title title = Mechanize.new.get(pixiv_url).title puts title diff --git a/slack-pixiv/commands/member.rb b/slack-pixiv/commands/member.rb new file mode 100644 index 0000000..428053c --- /dev/null +++ b/slack-pixiv/commands/member.rb @@ -0,0 +1,69 @@ +# coding: utf-8 +module SlackMathbot + module Commands + class Member < SlackRubyBot::Commands::Base + match /member\.php(?.*)$/ do |client, _data, _match| + + # Initalize Mechanize + agent = Mechanize.new + + pixiv_url = "http://www.pixiv.net/member.php" + _match[:url][0..-2] + puts pixiv_url.split("?id=")[-1] + + # Scrape page title + title = Mechanize.new.get(pixiv_url).title + puts title + + # Scrape username + username = Mechanize.new.get(pixiv_url).at(".name").text + puts username + + # Scrape profile comment + profile_comment = Mechanize.new.get(pixiv_url).at(".profile-comment").text.split("br { display : none;}")[-1] + puts profile_comment + + # Scrape works count + #works = Mechanize.new.get(pixiv_url).at(".count") + works = agent.get(pixiv_url).links_with(:class => /int/) + puts works + + # Create iOS Member URL, must find correct URL scheme + ios_mem_url = "pixiv://users/" + pixiv_url.split("?id=")[-1] + puts ios_mem_url + + client.web_client.chat_postMessage( + channel: _data.channel, + as_user: true, + attachments: [ + { + fallback: title + " - " + pixiv_url, + text: "<" + ios_mem_url + "|Open in App>", + text: profile_comment, + title: username, + title_link: pixiv_url, + color: "#2684BD", + fields: [ + { + title: "Works", + value: works[0].text, + short: true, + }, + { + title: "Bookmarks", + value: works[1].text, + short: true, + }, + { + title: "Follow", + value: works[2].text, + short: true, + } + ] + } + ].to_json + ) + + end + end + end + end