Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
253 lines (230 sloc) 6.01 KB
#! ========================================
#! Smash
Discord = require 'discord.js'
r = require "#{__dirname}/../helpers/fetch"
fuzzysort = require 'fuzzysort'
# Map series slugs to series names
seriesMap = {
"mario": "Super Mario"
"donkeykong": "Donkey Kong"
"zelda": "Zelda"
"metroid": "Metroid"
"yoshi": "Yoshi"
"kirby": "Kirby"
"starfox": "Star Fox"
"pokemon": "Pokémon"
"mother": "EarthBound"
"f-zero": "F-Zero"
"iceclimber": "Ice Climber"
"fireemblem": "Fire Emblem"
"gamewatch": "Game & Watch"
"palutena": "Kid Icarus"
"wario": "WarioWare"
"metalgear": "Metal Gear"
"sonic": "Sonic"
"pikmin": "Pikmin"
"famicomrobot": "R.O.B."
"doubutsu": "Animal Crossing"
"rockman": "Mega Man"
"wii_fit": "Wii Fit"
"punch_out": "Punch-Out!!"
"mii": "Mii"
"pacman": "PAC-MAN"
"xenoblade": "Xenoblade Chronicles"
"duckhunt": "Duck Hunt"
"streetfighter": "Street Fighter"
"finalfantasy": "Final Fantasy"
"bayonetta": "Bayonetta"
"splatoon": "Splatoon"
"dracula": "Castlevania"
"persona": "Persona"
"dragonquest": "Dragon Quest"
"banjo_and_kazooie": "Banjo-Kazooie"
"garou": "Fatal Fury"
# Map fighters to their names
fNameMap = [
"Donkey Kong"
"Dark Samus"
"Captain Falcon"
"Ice Climbers"
"Dr. Mario"
"Young Link"
"Mr. Game & Watch"
"Meta Knight"
"Dark Pit"
"Zero Suit Samus"
"Pokémon Trainer"
"Diddy Kong"
"King Dedede"
"Toon Link"
"Mega Man"
"Wii Fit Trainer"
"Rosalina & Luma"
"Little Mac"
"Mii Fighter"
"Bowser Jr."
"Duck Hunt"
"King K. Rool"
"Piranha Plant"
"Banjo & Kazooie"
root = ''
frameDataURL = ''
fighterPath = root + '/data/fighter.json'
handler = (msg, match, Haruka) ->
args = match.input.tokenize()[1]
if not args
return msg.reply [
"You didn’t enter a search term, so I couldn’t
search for a fighter."
"You need to enter a search term to search a fighter."
"Provide a search term when using this command. :)"
fdata = r(frameDataURL)
.then (json) -> ( (c) -> {
name: c.DisplayName
url: c.FullUrl
}).reduce ((acc, v, i, arr) ->
acc[] = v.url
return acc
), {}
r fighterPath
.then (fighters) ->
fighters = fighters.fighters, i) ->
f._name = fNameMap[i]
# "I'm feeling lucky" style search
lucky = fuzzysort.go(args, fighters, {
keys: [
return msg.reply [
'Sorry, but I couldn’t find that fighter.'
'I couldn’t find that fighter, sorry.'
].choose() if not lucky
# Mapped name or default to the one in the JSON.
# Falcon, G&W, and Pkmn Trainer include an html <br> element.
# Get rid of it.
name = (
lucky._name or
.replace(/\<\S[\s\S]*?\>/gi, '')
.replace(/\s+/g, ' ')
url = lucky.url and "{lucky.url}.html
imgHead = "#{root}/img/fighter/pict/#{lucky.file}.png"
imgPanoramic = "#{root}/img/fighter/series/#{lucky.file}.png"
title =
# Format the name like "21e – Lucina"
(lucky.displayNumEn or lucky.displayNum) + "" + name
series = ((seriesMap[lucky.series] or "`#{lucky.series}`") + " series")
echo = do ->
out = ''
if lucky.dash
out += "Yes, #{name} is "
out += fNameMap[fighters.indexOf(lucky) - 1]
out += '’s echo fighter.'
else if fighters[fighters.indexOf(lucky) + 1]?.dash
out += fNameMap[fighters.indexOf(lucky) + 1]
out += " is #{name}’s echo fighter."
out += 'None'
return out
fdata = do ->
url = (await fdata)[name]
if url
"Not available (yet)"
dlc = (
if lucky.dlc
"Yes, give Mr. Sakurai your money."
"No, comes with the game."
embed = new Discord.RichEmbed()
.setColor lucky.color
.setAuthor title, imgHead, (url or undefined)
.addField 'Echo', echo, true
.addField 'Series', series, true
.addField 'Frame data', (await fdata), true
.addField 'DLC', dlc, true
.setImage imgPanoramic embed
module.exports = {
name: "Smash"
regex: /^(smash|ssbu)(\s+|$)/i
handler: handler
short: "-h ssbu <f> ::
Returns some info regarding some SSBU Fighter."
long: """
=== Help for Smash ===
*Aliases*: ssbu, smash
-h ssbu <fighter> :: Retrieves information on that specific fighter.
You can’t perform that action at this time.