twitch-core
Version:
Twitch bot command client
71 lines (70 loc) • 3.09 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const TwitchChatCommand_1 = require("../TwitchChatCommand");
class Commands extends TwitchChatCommand_1.TwitchChatCommand {
constructor(client, options) {
super(client, Object.assign({ name: 'commands', userlevel: 'everyone', description: `This command shows help for all commands. Send ${client.options.prefix}help <command> for detailed help on a command.`, aliases: [
'help'
], examples: [
`${client.options.prefix} commands`,
`${client.options.prefix} help <command>`
], args: [
{
name: 'command'
}
] }, options));
}
run(msg, { command }) {
return __awaiter(this, void 0, void 0, function* () {
if ((command === null || command === void 0 ? void 0 : command.length) > 0) {
this.commandHelp(msg, command);
}
else {
this.commandList(msg);
}
});
}
commandList(msg) {
return __awaiter(this, void 0, void 0, function* () {
const commands = [];
const prefix = this.client.options.prefix;
for (const cmd of this.client.commands) {
if (!cmd.options.hideFromHelp) {
commands.push(prefix + cmd.options.name);
}
}
msg.reply(`Commands → ${commands.join(', ')}`);
});
}
commandHelp(msg, command) {
var _a;
const selectedCommand = this.client.commands.find(({ options }) => {
return options.name === command && !options.hideFromHelp;
});
if (selectedCommand) {
let messageText = selectedCommand.options.description;
if (((_a = selectedCommand.options.examples) === null || _a === void 0 ? void 0 : _a.length) > 0) {
messageText += ', Usage: ' + selectedCommand.options.examples.join(', ');
}
if (messageText) {
msg.reply(messageText);
}
else {
msg.reply('Help text not found');
}
}
else {
msg.reply('Command not found');
}
}
}
exports.default = Commands;