<commit_before># Description
#   Archive.today Public API
#
# Configuration:
#   None
#
# Commands:
#   hubot archive <url> - Archives the contents of <url> and returns the Archive.today link
#
# Notes:
#   TODO: Error checking
#   Dummy proofing
#
# Author:
#   MrSaints

ARCHIVE_TODAY_SUBMIT_URL = "https://archive.today/submit/"

module.exports = (robot) ->
    PATTERNS =
        FOUND: /https:\/\/archive.is\/.{5}/i
        NOT_FOUND: /Invalid URL:/i

    robot.respond /archive (.+)/i, (msg) ->
        data = "url=#{msg.match[1]}"
        msg.http(ARCHIVE_TODAY_SUBMIT_URL)
            .header("content-type", "application/x-www-form-urlencoded")
            .post(data) (err, res, body) ->
                robot.logger.debug body

                if err or body.match(PATTERNS.NOT_FOUND)
                    return msg.reply "#{msg.match[1]} is not a valid URL."

                links = body.match PATTERNS.FOUND
                msg.reply links[0]<commit_msg>Fixed bug with link containing params (issue #1)<commit_after># Description
#   Archive.today Public API
#
# Configuration:
#   None
#
# Commands:
#   hubot archive <url> - Archives the contents of <url> and returns the Archive.today link
#
# Notes:
#   TODO: Error checking
#   Dummy proofing
#
# Author:
#   MrSaints

ARCHIVE_TODAY_SUBMIT_URL = "https://archive.today/submit/"

module.exports = (robot) ->
    PATTERNS =
        FOUND: /https:\/\/archive.is\/.{5}/i
        NOT_FOUND: /Invalid URL:/i

    robot.respond /archive (.+)/i, (msg) ->
        data = "url=#{encodeURIComponent(msg.match[1])}"
        msg.http(ARCHIVE_TODAY_SUBMIT_URL)
            .header("content-type", "application/x-www-form-urlencoded")
            .post(data) (err, res, body) ->
                robot.logger.debug body

                if err or body.match(PATTERNS.NOT_FOUND)
                    return msg.reply "#{msg.match[1]} is not a valid URL."

                links = body.match PATTERNS.FOUND
                msg.reply links[0]
{'fraction_non_alphanumeric': 0.13611250627825214, 'fraction_numerical': 0.0045203415369161224, 'mean_word_length': 2.2233009708737863, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '4914443', 'n_tokens_mistral': 684, 'n_tokens_neox': 651, 'n_words': 148}