<commit_before>import Discord from 'discord.js'
import Fuse from 'fuse.js'
import HearthstoneJSON from 'hearthstonejson'

import toMarkdown from 'to-markdown'

// RGB
const CLASS_COLORS = {
    'WARRIOR': [196, 30, 59],
    'SHAMAN': [0, 122, 222],
    'ROGUE': [0, 0, 0],
    'PALADIN': [255, 245, 105],
    'HUNTER': [171, 212, 115],
    'DRUID': [199, 156, 110],
    'WARLOCK': [148, 130, 201],
    'MAGE': [105, 204, 240],
    'PRIEST': [255, 255, 255],
    'NEUTRAL': [128, 128, 128]
}

export default class CardsHelper {
    static getAll() {
        const hsjson = new HearthstoneJSON()
        return new Promise((resolve, reject) => {
            try {
                hsjson.getLatest(cards => { resolve(cards) })
            } catch (ex) {
                reject(ex)
            }
        })
    }

    static detectMentions(text) {
        let pattern = /:{2}([^:\?]+)\??([^:]*):{2}/g
        let matches = []
        let match = pattern.exec(text)
        while (match) {
            matches.push(match)
            match = pattern.exec(text)
        }
        return matches
    }

    static async search(pattern) {
        let uncollectibleOnly = false
        if (pattern.startsWith('@')) {
            pattern = pattern.substring(1)
            uncollectibleOnly = true
        }
        let allCards = await this.getAll().catch(console.error)

        let uncollectibleFuse = new Fuse(
            allCards.filter(card => { return !card.collectible }),
            { keys: ['name'], include: ['score'] }
        )
        let foundUncollectible = uncollectibleFuse.search(pattern)
        if (uncollectibleOnly) { return foundUncollectible[0].item }

        let collectibleFuse = new Fuse(
            allCards.filter(card => { return card.collectible }),
            { keys: ['name'], include: ['score'] }
        )
        let foundCollectible = collectibleFuse.search(pattern)
        if (foundUncollectible[0].score < foundCollectible[0].score) { return foundUncollectible[0].item }
        return foundCollectible[0].item<commit_msg>Account for no matches in either collection<commit_after>import Discord from 'discord.js'
import Fuse from 'fuse.js'
import HearthstoneJSON from 'hearthstonejson'

import toMarkdown from 'to-markdown'

// RGB
const CLASS_COLORS = {
    'WARRIOR': [196, 30, 59],
    'SHAMAN': [0, 122, 222],
    'ROGUE': [0, 0, 0],
    'PALADIN': [255, 245, 105],
    'HUNTER': [171, 212, 115],
    'DRUID': [199, 156, 110],
    'WARLOCK': [148, 130, 201],
    'MAGE': [105, 204, 240],
    'PRIEST': [255, 255, 255],
    'NEUTRAL': [128, 128, 128]
}

export default class CardsHelper {
    static getAll() {
        const hsjson = new HearthstoneJSON()
        return new Promise((resolve, reject) => {
            try {
                hsjson.getLatest(cards => { resolve(cards) })
            } catch (ex) {
                reject(ex)
            }
        })
    }

    static detectMentions(text) {
        let pattern = /:{2}([^:\?]+)\??([^:]*):{2}/g
        let matches = []
        let match = pattern.exec(text)
        while (match) {
            matches.push(match)
            match = pattern.exec(text)
        }
        return matches
    }

    static async search(pattern) {
        let uncollectibleOnly = false
        if (pattern.startsWith('@')) {
            pattern = pattern.substring(1)
            uncollectibleOnly = true
        }
        let allCards = await this.getAll().catch(console.error)

        let uncollectibleFuse = new Fuse(
            allCards.filter(card => { return !card.collectible }),
            { keys: ['name'], include: ['score'] }
        )
        let foundUncollectible = uncollectibleFuse.search(pattern)
        if (uncollectibleOnly) { return foundUncollectible[0].item }

        let collectibleFuse = new Fuse(
            allCards.filter(card => { return card.collectible }),
            { keys: ['name'], include: ['score'] }
        )
        let foundCollectible = collectibleFuse.search(pattern)
        
        if (foundCollectible.length < 1 && foundUncollectible.length > 0) { return foundUncollectible[0].item }
        if (foundCollectible.length > 0 && foundUncollectible.length < 1) { return foundCollectible[0].item }
        if (foundUncollectible[0].score < foundCollectible[0].score) { return foundUncollectible[0].item }
        return foundCollectible[0].item
{'fraction_non_alphanumeric': 0.13936486177747315, 'fraction_numerical': 0.0415809915467215, 'mean_word_length': 2.2574404761904763, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '5689667', 'n_tokens_mistral': 1516, 'n_tokens_neox': 1353, 'n_words': 321}