Browse Source

Change regex to catch based on instead, narrowing the potential matches

master
Daniel Muckerman 8 years ago
parent
commit
68e6ce01b5
1 changed files with 8 additions and 2 deletions
  1. +8
    -2
      slack-pixiv/commands/pixiv.rb

+ 8
- 2
slack-pixiv/commands/pixiv.rb View File

@ -2,13 +2,19 @@
module SlackMathbot
module Commands
class Pixiv < SlackRubyBot::Commands::Base
match /pixiv\.net(?<url>.*)$/ do |client, _data, _match|
match /member_illust\.php(?<url>.*)$/ do |client, _data, _match|
# Initalize Mechanize
agent = Mechanize.new
# Create Pixiv URL
pixiv_url = "http://www.pixiv.net" + _match[:url][0..-2]
# If a full URL is given, extra characters are appended for some reason.
# This ensures we catch them better
if (_data[:text].include? "pixiv.net")
pixiv_url = "http://www.pixiv.net/member_illust.php" + _match[:url][0..-2]
else
pixiv_url = "http://www.pixiv.net/member_illust.php" + _match[:url][0..-1]
end
puts pixiv_url
# Create iOS Illustration URL, regex pixiv_url to

Loading…
Cancel
Save