From the archive
This commit is contained in:
29
game/commands/alias.js
Normal file
29
game/commands/alias.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const scenarios = require('../scenario/scenario.js');
|
||||
const _ = require('underscore');
|
||||
|
||||
const helptext = `The \`!alias\` command can be used to find alternative commands that cannot be found with \`!help\``;
|
||||
|
||||
function alias(context) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if(context.isHelpRequest) {
|
||||
context.message.reply(helptext)
|
||||
.then(() => {
|
||||
console.info(`[${context.id}] ? alias`);
|
||||
resolve();
|
||||
}).catch(err => reject(err));
|
||||
} else {
|
||||
let text = 'Listing aliases\n```';
|
||||
_.each(_.keys(context.alias), key => text += `\n${key}`);
|
||||
text += '\n```'
|
||||
context.message.reply(text)
|
||||
.then(() => {
|
||||
console.info(`[${context.id}] List alias -> [${context.message.author.id}]`)
|
||||
resolve();
|
||||
}).catch(err => reject(err));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = commands => {
|
||||
commands.alias = alias;
|
||||
};
|
||||
49
game/commands/help.js
Normal file
49
game/commands/help.js
Normal file
@@ -0,0 +1,49 @@
|
||||
const _ = require('underscore');
|
||||
const helptext = `The \`!help\` command can be used to get a list of commands, or to get specific help text using \`!help <command>\`
|
||||
Also see the \`!alias\` command for extra simplifications.`
|
||||
|
||||
const ex = /^[\w\d]+$/
|
||||
function help(context) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if(context.isHelpRequest) {
|
||||
context.message.reply(helptext)
|
||||
.then(() => {
|
||||
console.info(`[${context.id}] ? help`);
|
||||
resolve();
|
||||
}).catch(err => reject(err));
|
||||
} else if(!context.args) {
|
||||
let text = 'Listing commands, use \`!help <command>\` for detailed information. Use \`!alias\` to find easy shortcut commands\n```';
|
||||
_.each(_.keys(context.commands), key => text += `\n${key}`);
|
||||
text += '\n```'
|
||||
context.message.reply(text)
|
||||
.then(() => {
|
||||
console.info(`[${context.id}] List commands -> [${context.pid}]`)
|
||||
resolve();
|
||||
}).catch(err => reject(err));
|
||||
} else {
|
||||
let match = ex.exec(context.args);
|
||||
if(match && _.has(context.commands, context.args)) {
|
||||
console.info(`[${context.id}] Passing help request to <${context.args}>`);
|
||||
context.isHelpRequest = true;
|
||||
context.commands[context.args](context);
|
||||
} else if (match && _.has(context.alias, context.args)) {
|
||||
console.info(`[${context.id}] Alias help request to <${context.command}>`);
|
||||
context.message.reply(`\`!${context.args}\`: ${context.alias[context.args].desc}`)
|
||||
.then(() => {
|
||||
console.info(`[${context.id}] Alias -> [${context.pid}]`);
|
||||
resolve();
|
||||
}).catch(err => reject(err));
|
||||
} else {
|
||||
context.message.reply(`No such command <${context.args}>`)
|
||||
.then(() => {
|
||||
console.info(`[${context.id}] No command -> [${context.pid}]`)
|
||||
resolve();
|
||||
}).catch(err => reject(err));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = commands => {
|
||||
commands.help = help;
|
||||
};
|
||||
110
game/commands/me.js
Normal file
110
game/commands/me.js
Normal file
@@ -0,0 +1,110 @@
|
||||
const _ = require('underscore');
|
||||
const helptext = `The \`!me\` command can be used to begin setting up your player character. \`!me\` shows your character, \`!me --done\` finishes.
|
||||
\`!me\` shows current information
|
||||
\`!me --done\` sets your character as ready to play (but you can still adjust it until game start) {\`!me -d \`}
|
||||
\`!me --name <...>\` set name (Max. 48 characters) {\`!me -n <...>\`}
|
||||
\`!me --age N\` set age (0 < N < 1000) {\`!me -a N\`}
|
||||
\`!me --title <...>\` set title name (Max. 48 characters, e.g. Major General, Doctor, Lady) {\`!me -t <...>\`}
|
||||
\`!me --story <...>\` give a background story (32-320 characters) {\`!me -s <...>\`}
|
||||
You can combine these for speed, examples:
|
||||
\`!me -n Johnny Smooth -a 23 -t Presentator\`
|
||||
\`!me --name Scotty Love --age 24 --title Village Idiot\`
|
||||
Mix and match long form and shorthand:
|
||||
\`!me --name Mr. Eaten --age 271 -s <...>\` (<...> omitted for brevity)
|
||||
Finalize on-the-go (be sure to include all options):
|
||||
\`!me -n Speedy Gonzales -a 15 -t Insurgent -s <...> -d\` (<...> omitted for brevity)
|
||||
`
|
||||
|
||||
let expressions = {};
|
||||
expressions.name = {};
|
||||
expressions.name.pt = /((?:--name)|(?:-n))/;
|
||||
expressions.name.ex = /(?:(?:--name)|(?:-n)\s)(.{1,48}?)\s?(?:-|$)/;
|
||||
expressions.age = {};
|
||||
expressions.age.pt = /((?:--age)|(?:-a))/;
|
||||
expressions.age.ex = /(?:(?:--age)|(?:-a)\s)(\d{1,3})\s?(?:-|$)/;
|
||||
expressions.title = {};
|
||||
expressions.title.pt = /((?:--title)|(?:-t))/;
|
||||
expressions.title.ex = /(?:(?:--title)|(?:-t)\s)(.{1,48}?)\s?(?:-|$)/;
|
||||
expressions.story = {};
|
||||
expressions.story.pt = /((?:--story)|(?:-s))/;
|
||||
expressions.story.ex = /(?:(?:--story)|(?:-s)\s)(.{32,320}?)\s?(?:-|$)/;
|
||||
const exDone = /(?:(?:--done)|(?:-d))/
|
||||
|
||||
function p(flag, context) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let flagged = expressions[flag].pt.exec(context.args);
|
||||
if(flagged) {
|
||||
let match = expressions[flag].ex.exec(context.args);
|
||||
if(match) {
|
||||
context.state.player[context.pid][flag] = match[1];
|
||||
console.info(`[${context.id}] set ${flag} for [${context.pid}]`);
|
||||
resolve(`Set \`${flag}\``);
|
||||
} else {
|
||||
console.warn(`[${context.id}] could not parse arguments for flag <${flagged[1]}>, use \`!help me\` to check requirements`);
|
||||
resolve(`Could not parse arguments for flag \`${flag}\``);
|
||||
}
|
||||
} else {
|
||||
resolve(`Flag for \`${flag}\` not present.`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function me(context) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if(!context.state.player) { context.state.player = {}; }
|
||||
if(context.isHelpRequest) {
|
||||
context.message.reply(helptext)
|
||||
.then(() => {
|
||||
console.info(`[${context.id}] ? me`);
|
||||
resolve();
|
||||
}).catch(err => reject(err));
|
||||
} else if(!context.args) {
|
||||
if(!context.state.player[context.pid]) {
|
||||
context.message.reply(`[${context.pid}] You do not have a character yet, use the \`!help me\` command to find out how to create one.`)
|
||||
.then(() => resolve())
|
||||
.catch(err => reject(err));
|
||||
} else {
|
||||
let player = context.state.player[context.pid];
|
||||
let text = '```\n';
|
||||
text += player.title ? `${player.title} ` : '[missing title] ';
|
||||
text += player.name ? `${player.name}, ` : '[missing name], ';
|
||||
text += player.age ? `${player.age} years old.\n` : '[missing age]\n';
|
||||
text += player.story ? player.story : '[missing background story]';
|
||||
text += '\n```';
|
||||
context.message.reply(text)
|
||||
.then(() => resolve())
|
||||
.catch(err => reject(err));
|
||||
}
|
||||
} else {
|
||||
if(!context.state.player[context.pid]) { context.state.player[context.pid] = {}}
|
||||
Promise.all([
|
||||
p("name", context),
|
||||
p("age", context),
|
||||
p("title", context),
|
||||
p("story", context)
|
||||
]).then(values => {
|
||||
let result = _.reduce(values, (c, v) => { return `${c}\n${v}`});
|
||||
if(exDone.test(context.args)) {
|
||||
let player = context.state.player[context.pid];
|
||||
if(player.name && player.age && player.title && player.story) {
|
||||
player.complete = true;
|
||||
console.info(`[${context.id}] completed [${context.pid}]`);
|
||||
result += `\nCompleted basic player setup for [${context.pid}]`;
|
||||
} else {
|
||||
console.info(`[${context.id}] incomplete [${context.pid}]`);
|
||||
result += `\nMissing information for [${context.pid}]. \nUse \`!me\` and \`!help me\` for more information`;
|
||||
}
|
||||
}
|
||||
context.message.reply(result)
|
||||
.then(() => {
|
||||
context.stateChanged = true;
|
||||
resolve(context);
|
||||
}).catch(err => reject(err));
|
||||
}).catch(err => reject(err));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = commands => {
|
||||
commands.me = me;
|
||||
};
|
||||
23
game/commands/ping.js
Normal file
23
game/commands/ping.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const helptext = `The \`!ping\` command can be used to check if NeverSteam v2 is running, it ignores any arguments given.`;
|
||||
|
||||
function ping(context) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if(context.isHelpRequest) {
|
||||
context.message.reply(helptext)
|
||||
.then(() => {
|
||||
console.info(`[${context.id}] ? ping`)
|
||||
resolve();
|
||||
}).catch(err => reject(err));
|
||||
} else {
|
||||
context.message.reply(`[${context.id}] ECHO`)
|
||||
.then(() => {
|
||||
console.info(`[${context.id}] PING -> ECHO [${context.pid}]`)
|
||||
resolve();
|
||||
}).catch(err => reject(err));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = commands => {
|
||||
commands.ping = ping;
|
||||
};
|
||||
38
game/commands/scene.js
Normal file
38
game/commands/scene.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const scenarios = require('../scenario/scenario.js');
|
||||
const _ = require('underscore');
|
||||
|
||||
const helptext = `The \`!scenario\` command can be used to select a scenario to play. use \`!scenario\` to list all options, and \`!scenario <name>\` to select a particular scenario.`;
|
||||
|
||||
function s(context) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if(context.isHelpRequest) {
|
||||
context.message.reply(helptext)
|
||||
.then(() => {
|
||||
console.info(`[${context.id}] ? scene`);
|
||||
resolve();
|
||||
}).catch(err => reject(err));
|
||||
} else if(context.args) {
|
||||
context.storyline = context.args;
|
||||
scenarios.init(context)
|
||||
.then(context => {
|
||||
console.info(`[${context.id}] Initiated scenario ${context.args}`);
|
||||
resolve();
|
||||
})
|
||||
.catch(err => reject(err));
|
||||
} else {
|
||||
let text = '```\n';
|
||||
_.each(scenarios.list(context), scenario => text += `${scenario}\n`);
|
||||
text += '```';
|
||||
context.message.reply(text)
|
||||
.then(() => {
|
||||
console.info(`[${context.id}] Listed scenarios`);
|
||||
resolve();
|
||||
})
|
||||
.catch(err => reject(err));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = commands => {
|
||||
commands.scenario = s;
|
||||
};
|
||||
Reference in New Issue
Block a user