<commit_before># Description:
#   Card image fetcher for Magic: The Gathering cards
#
# Commands:
#   [[<card name>]]
#   [[<left name> // <right name>]]
#
# Notes:
#   Upon failure, returns Dismal Failure
#
# Author:
#   JacobGinsparg

cardDatabaseUrl = "http://mtgjson.com/json/AllCards.json"
urlBase = "http://gatherer.wizards.com/Handlers/Image.ashx?type=card&name="
replacements = [
  {
    needle : /“|”/,
    correction : "\""
  }
]

doReplacement = (str, pair) ->
  return str.replace pair.needle, pair.correction, "g"

verifyCard = (cardName, cardDB) ->
  for pair in replacements
    while pair.needle.test cardName
      cardName = doReplacement cardName, pair
  if cardName.search(" // ") isnt -1
    splitCards = cardName.split " // "
    return encodeURIComponent(cardName) if splitCards[0] of cardDB and splitCards[1] of cardDB
  else
    return encodeURIComponent(cardName) if cardName of cardDB
  "Dismal%20Failure"

getCardImageUrl = (cardName, cardDB) ->
  verifiedCard = verifyCard(cardName, cardDB)
  fullUrl = "#{urlBase}#{verifiedCard}"

module.exports = (robot) ->
  robot.hear /\[\[(.*)\]\]/i, (msg) ->
    robot.http(cardDatabaseUrl)
      .get() (err, res, body) ->
        cards = JSON.parse body
        msg.send getCardImageUrl(msg.match[1], cards)<commit_msg>Changed from double to single quotes<commit_after># Description:
#   Card image fetcher for Magic: The Gathering cards
#
# Commands:
#   [[<card name>]]
#   [[<left name> // <right name>]]
#
# Notes:
#   Upon failure, returns Dismal Failure
#
# Author:
#   JacobGinsparg

cardDatabaseUrl = 'http://mtgjson.com/json/AllCards.json'
urlBase = 'http://gatherer.wizards.com/Handlers/Image.ashx?type=card&name='
replacements = [
  {
    needle : /“|”/,
    correction : '\''
  }
]

doReplacement = (str, pair) ->
  return str.replace pair.needle, pair.correction, 'g'

verifyCard = (cardName, cardDB) ->
  for pair in replacements
    while pair.needle.test cardName
      cardName = doReplacement cardName, pair
  if cardName.search(' // ') isnt -1
    splitCards = cardName.split ' // '
    return encodeURIComponent(cardName) if splitCards[0] of cardDB and splitCards[1] of cardDB
  else
    return encodeURIComponent(cardName) if cardName of cardDB
  'Dismal%20Failure'

getCardImageUrl = (cardName, cardDB) ->
  verifiedCard = verifyCard(cardName, cardDB)
  fullUrl = '#{urlBase}#{verifiedCard}'

module.exports = (robot) ->
  robot.hear /\[\[(.*)\]\]/i, (msg) ->
    robot.http(cardDatabaseUrl)
      .get() (err, res, body) ->
        cards = JSON.parse body
        msg.send getCardImageUrl(msg.match[1], cards)
{'fraction_non_alphanumeric': 0.14829043411448328, 'fraction_numerical': 0.004610065309258548, 'mean_word_length': 3.5208333333333335, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3598274', 'n_tokens_mistral': 920, 'n_tokens_neox': 931, 'n_words': 208}