Browse Source

Added members command

master
Daniel Muckerman 8 years ago
parent
commit
c1ec39828b
3 changed files with 72 additions and 7 deletions
  1. +2
    -1
      slack-pixiv.rb
  2. +1
    -6
      slack-pixiv/commands/illust.rb
  3. +69
    -0
      slack-pixiv/commands/member.rb

+ 2
- 1
slack-pixiv.rb View File

@ -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'

slack-pixiv/commands/pixiv.rb → slack-pixiv/commands/illust.rb View File

@ -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(?<url>.*)$/ 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

+ 69
- 0
slack-pixiv/commands/member.rb View File

@ -0,0 +1,69 @@
# coding: utf-8
module SlackMathbot
module Commands
class Member < SlackRubyBot::Commands::Base
match /member\.php(?<url>.*)$/ 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

Loading…
Cancel
Save