<commit_before># Description:
#   Returns clip art images from openclipart.org API.
#
# Commands:
#   hubot clipart me <query> - Queries openclipart for <query> and returns a random result.
#
# Author:
#   desmondmorris

module.exports = (robot) ->
  robot.respond /clipart(?: me)? (.*)/i, (msg) ->
    clipartMe msg, (url) ->
      msg.send encodeURI(url)

clipartMe = (msg, cb) ->

  q = query: msg.match[1]

  msg.http('https://openclipart.org/search/json/')
    .query(q)
    .get() (err, res, body) ->
      data = JSON.parse(body)
      images = data.payload
      if images?.length > 0
        image  = msg.random images
        cb "#{image.svg.png_full_lossy}"
<commit_msg>(Hopefully) Improves the results of clipart by sorting by downloads and only getting top 5.<commit_after># Description:
#   Returns clip art images from openclipart.org API.
#
# Commands:
#   hubot clipart me <query> - Queries openclipart for <query> and returns a random result.
#   Aliases:
#     hubot clipart <query>
#     hubot clip me <query>
#     hubot clip <query>
#
# Author:
#   Original - desmondmorris
#   Improved by <NAME>

module.exports = (robot) ->
  robot.respond /(?: clip|clipart)(?: me)? (.*)/i, (msg) ->
    clipartMe msg, (url) ->
      msg.send encodeURI(url)

clipartMe = (msg, cb) ->

  q = query: msg.match[1], amount: 5, sort: 'downloads'

  msg.http('https://openclipart.org/search/json/')
    .query(q)
    .get() (err, res, body) ->
      data = JSON.parse(body)
      images = data.payload
      if images?.length > 0
        image  = msg.random images
        cb "#{image.svg.png_full_lossy}"

{'fraction_non_alphanumeric': 0.14987562189054726, 'fraction_numerical': 0.0037313432835820895, 'mean_word_length': 2.821852731591449, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5898883', 'n_tokens_mistral': 570, 'n_tokens_neox': 559, 'n_words': 155}