diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2017-04-18 19:32:36 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2017-04-18 19:32:36 +0200 |
| commit | 1805e6d82a54a527323b14f47f31f35967541ce3 (patch) | |
| tree | c505f831f9516c1c018176a4b28d9cefec0e4d57 | |
| parent | ad88b9a19cd5438d18be061db08511183b6a20bf (diff) | |
| download | discordbot-1805e6d82a54a527323b14f47f31f35967541ce3.tar.gz discordbot-1805e6d82a54a527323b14f47f31f35967541ce3.zip | |
fix undefineds; add simple account-ign storage
| -rw-r--r-- | api.js | 2 | ||||
| -rw-r--r-- | commands/vainsocial/match.js | 1 | ||||
| -rw-r--r-- | commands/vainsocial/matches.js | 1 | ||||
| -rw-r--r-- | commands/vainsocial/me.js | 35 | ||||
| -rw-r--r-- | commands/vainsocial/user.js | 1 | ||||
| -rw-r--r-- | responses.js | 63 |
6 files changed, 93 insertions, 10 deletions
@@ -68,7 +68,7 @@ async function getMappings() { ["gamemode"], async (table) => { mapping[table] = new Map(); (await getMap(table)).map( - (map) => mapping[table]["id"] = map["name"]) + (map) => mapping[table][map["id"]] = map["name"]) } ); return mapping; diff --git a/commands/vainsocial/match.js b/commands/vainsocial/match.js index 08f52f5..ba24baf 100644 --- a/commands/vainsocial/match.js +++ b/commands/vainsocial/match.js @@ -23,6 +23,7 @@ module.exports = class ShowMatchCommand extends Commando.Command { label: "name", prompt: "Please specify your in game name (Case Sensitive).", type: "string", + default: "?", min: 3, max: 16 }, { diff --git a/commands/vainsocial/matches.js b/commands/vainsocial/matches.js index adce644..7eaa513 100644 --- a/commands/vainsocial/matches.js +++ b/commands/vainsocial/matches.js @@ -22,6 +22,7 @@ module.exports = class ShowMatchesCommand extends Commando.Command { label: "name", prompt: "Please specify your in game name (Case Sensitive).", type: "string", + default: "?", min: 3, max: 16 } ] diff --git a/commands/vainsocial/me.js b/commands/vainsocial/me.js new file mode 100644 index 0000000..4de7c8f --- /dev/null +++ b/commands/vainsocial/me.js @@ -0,0 +1,35 @@ +#!/usr/bin/node +/* jshint esnext:true */ +"use strict"; + +const Commando = require("discord.js-commando"), + oneLine = require("common-tags").oneLine, + responses = require("../../responses"); + +module.exports = class RememberUserCommand extends Commando.Command { + constructor(client) { + super(client, { + name: "vainsocial-me", + aliases: ["vme"], + group: "vainsocial", + memberName: "vainsocial-me", + description: "Remembers a users's in game name.", + details: oneLine` +Store your in game name for quicker access to other commands. + `, + examples: ["vme shutterfly"], + + args: [ { + key: "name", + label: "name", + prompt: "Please specify your in game name (Case Sensitive).", + type: "string", + min: 3, + max: 16 + } ] + }); + } + async run(msg, args) { + await responses.rememberUser(msg, args); + } +}; diff --git a/commands/vainsocial/user.js b/commands/vainsocial/user.js index 95bb86f..43aecac 100644 --- a/commands/vainsocial/user.js +++ b/commands/vainsocial/user.js @@ -24,6 +24,7 @@ Display VainSocial lifetime statistics from Vainglory label: "name", prompt: "Please specify your in game name (Case Sensitive).", type: "string", + default: "?", min: 3, max: 16 } ] diff --git a/responses.js b/responses.js index 9137af0..d1284e5 100644 --- a/responses.js +++ b/responses.js @@ -98,7 +98,7 @@ function formatPlayer(player) { `; if (player.picks.length > 0) picks = oneLine` - Favorite | \`${player.picks[0].name}\`, \`${player.picks[0].hero_pick} picks\` + Favorite | \`${player.picks[0].actor.replace(/\*/g, "")}\`, \`${player.picks[0].hero_pick} picks\` `; return ` ${stats} @@ -183,14 +183,41 @@ Currently running on ${msg.client.guilds.size} servers.`) ); } +// return the sqlite stored ign for this user +function nameByUser(msg) { + return msg.guild.settings.get("remember+" + msg.author.id); +} + +// tell the user that they need to store their name +function formatSorryUnknown(msg) { + return `You're unknown to our service. Try ${usg(msg, "help vme")}.`; +} + +module.exports.rememberUser = async (msg, args) => { + const ign = args.name; + await msg.guild.settings.set("remember+" + msg.author.id, ign); + await msg.reply( +`You are now able to use ${usg(msg, "v")} to access your profile faster.`); +} + // show player profile and last match module.exports.showUser = async (msg, args) => { - const ign = args.name, - waiter = api.subscribeUpdates(ign); let responded = false, response, + ign = args.name, reactionsAdded = false; + // shorthand + // "?" is not accepted as user input, but the default for empty + if (ign == "?") { + ign = nameByUser(msg); + if (ign == undefined) { + await msg.reply(formatSorryUnknown(msg)); + return; + } + } + + const waiter = api.subscribeUpdates(ign); while (await waiter.next() != undefined) { const [player, matches] = await Promise.all([ api.getPlayer(ign), @@ -253,12 +280,21 @@ async function respondMatch(msg, ign, id, response=undefined) { } module.exports.showMatch = async (msg, args) => { - const ign = args.name, - index = args.number, - waiter = api.subscribeUpdates(ign); + const index = args.number; let responded = false, + ign = args.name, response; + // shorthand + if (ign == "?") { + ign = nameByUser(msg); + if (ign == undefined) { + await msg.reply(formatSorryUnknown(msg)); + return; + } + } + + const waiter = api.subscribeUpdates(ign); while (await waiter.next() != undefined) { let matches = await api.getMatches(ign); if (matches == undefined || matches.data.length == 0) { @@ -315,11 +351,20 @@ Last ${matches_num} casual and ranked matches. } module.exports.showMatches = async (msg, args) => { - const ign = args.name, - waiter = api.subscribeUpdates(ign); - let responded = false, + let ign = args.name, + responded = false, response; + // shorthand + if (ign == "?") { + ign = nameByUser(msg); + if (ign == undefined) { + await msg.reply(formatSorryUnknown(msg)); + return; + } + } + + const waiter = api.subscribeUpdates(ign); while (await waiter.next() != undefined) { let matches = await api.getMatches(ign); if (matches == undefined || matches.data.length == 0) { |
