Add yell, say and die command
parent
6c84aefd96
commit
70cb7d4745
@ -0,0 +1,5 @@
|
|||||||
|
export enum CommandCategory {
|
||||||
|
UTILITY = "Utility",
|
||||||
|
MUSIC = "Music",
|
||||||
|
MISC = "Misc",
|
||||||
|
}
|
@ -1,6 +1,13 @@
|
|||||||
import {CommandCollection} from "../../lib/CommandCollection";
|
import {CommandCollection} from "../../lib/CommandCollection";
|
||||||
import {Ping} from "./utility/Ping";
|
import {Ping} from "./utility/Ping";
|
||||||
|
import {Say} from "./utility/Say";
|
||||||
|
import { Help } from "./utility/Help";
|
||||||
|
import {Yell} from "./utility/Yell";
|
||||||
|
import { Die } from "./utility/Die";
|
||||||
|
|
||||||
export const globalCommands = new CommandCollection([
|
export const globalCommands: CommandCollection<any> = new CommandCollection([
|
||||||
Ping,
|
Ping,
|
||||||
|
Say,
|
||||||
|
Yell,
|
||||||
|
Die,
|
||||||
]);
|
]);
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
import {Command} from "../../../lib/Command";
|
||||||
|
import {CommandPermission} from "../../../lib/CommandPermission";
|
||||||
|
import {Message} from "discord.js";
|
||||||
|
import {CommandCategory} from "../../CommandCategory";
|
||||||
|
import { Help } from "./Help";
|
||||||
|
|
||||||
|
export class Die extends Command {
|
||||||
|
public static commandName = "die";
|
||||||
|
public static category = CommandCategory.UTILITY;
|
||||||
|
public static permission = CommandPermission.OWNER;
|
||||||
|
public static description = "Kills the bot.";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replies with the current ping.
|
||||||
|
* @param msg
|
||||||
|
*/
|
||||||
|
public async invoke(msg: Message): Promise<void> {
|
||||||
|
await msg.channel.send("AAAAAARRRGGHHH...");
|
||||||
|
await msg.client.destroy();
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,99 @@
|
|||||||
|
import {Command} from "../../../lib/Command";
|
||||||
|
import {Message, RichEmbed} from "discord.js";
|
||||||
|
import {CommandCollection} from "../../../lib/CommandCollection";
|
||||||
|
import {globalCommands} from "../index";
|
||||||
|
import {guildCommands} from "../../guild";
|
||||||
|
import {privateCommands} from "../../private";
|
||||||
|
import {CommandCategory} from "../../CommandCategory";
|
||||||
|
import {ExtendedMessage} from "../../../lib/ExtendedMessage";
|
||||||
|
import {CommandPermission} from "../../../lib/CommandPermission";
|
||||||
|
|
||||||
|
export class Help extends Command {
|
||||||
|
public static commandName = "help";
|
||||||
|
public static description = "Shows a help for commands.";
|
||||||
|
public static usage = "help [<command>]";
|
||||||
|
public static category = CommandCategory.UTILITY;
|
||||||
|
public allCommands: CommandCollection<any> = new CommandCollection<any>(
|
||||||
|
[...globalCommands, ...guildCommands, ...privateCommands]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows a help embed.
|
||||||
|
* If an argument is provided the specific help for that command is shown.
|
||||||
|
* @param msg
|
||||||
|
* @param exMsg
|
||||||
|
*/
|
||||||
|
public invoke(msg: Message, exMsg: ExtendedMessage): void {
|
||||||
|
const args = exMsg.args;
|
||||||
|
const helpEmbed = new RichEmbed();
|
||||||
|
|
||||||
|
helpEmbed.setTitle("Help");
|
||||||
|
if (args.length === 0) {
|
||||||
|
msg.channel.send("", this.getOverviewHelpEmbed(exMsg));
|
||||||
|
} else {
|
||||||
|
const commandHelp = this.getCommandHelpEmbed(exMsg);
|
||||||
|
if (commandHelp) {
|
||||||
|
msg.channel.send("", commandHelp);
|
||||||
|
} else {
|
||||||
|
msg.channel.send(`The command **${args[0]}** could not be found.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a help embed for the provided command.
|
||||||
|
* @param exMsg
|
||||||
|
*/
|
||||||
|
private getCommandHelpEmbed(exMsg: ExtendedMessage): RichEmbed {
|
||||||
|
const CommandClass = this.allCommands.findByName(exMsg.args[0]);
|
||||||
|
|
||||||
|
if (CommandClass) {
|
||||||
|
const helpEmbed = new RichEmbed();
|
||||||
|
helpEmbed.setTitle(`Help for **${CommandClass.commandName}**`);
|
||||||
|
helpEmbed.addField("Description", CommandClass.description || "*No description entity found.*");
|
||||||
|
helpEmbed.addField("Usage",
|
||||||
|
`\`${exMsg.prefix}${CommandClass.usage || CommandClass.commandName}\``, true);
|
||||||
|
let permissionNeeded: string;
|
||||||
|
switch (CommandClass.permission as CommandPermission) {
|
||||||
|
case CommandPermission.OWNER:
|
||||||
|
permissionNeeded = "Owner";
|
||||||
|
break;
|
||||||
|
case CommandPermission.ADMIN:
|
||||||
|
permissionNeeded = "Admin";
|
||||||
|
break;
|
||||||
|
case CommandPermission.DJ:
|
||||||
|
permissionNeeded = "DJ";
|
||||||
|
break;
|
||||||
|
case CommandPermission.REGULAR:
|
||||||
|
default:
|
||||||
|
permissionNeeded = "None";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
helpEmbed.addField("Permission Level", permissionNeeded, true);
|
||||||
|
return helpEmbed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a rich embed containing an overview of all the available commands.
|
||||||
|
* @param exMsg
|
||||||
|
*/
|
||||||
|
private getOverviewHelpEmbed(exMsg: ExtendedMessage): RichEmbed {
|
||||||
|
const helpEmbed = new RichEmbed();
|
||||||
|
const commandsByCategory: any = {};
|
||||||
|
helpEmbed.setDescription(
|
||||||
|
`Use \`${exMsg.prefix}\`help [command] for more info on a command.`);
|
||||||
|
for (const CommandClass of this.allCommands) {
|
||||||
|
const category: string = CommandClass.category;
|
||||||
|
if (!commandsByCategory[Help.category]) {
|
||||||
|
commandsByCategory[category] = "";
|
||||||
|
}
|
||||||
|
commandsByCategory[category] += `\`${CommandClass.commandName}\`\t`;
|
||||||
|
}
|
||||||
|
for (const category in commandsByCategory) {
|
||||||
|
if (commandsByCategory.hasOwnProperty(category)) {
|
||||||
|
helpEmbed.addField(category, commandsByCategory[category]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return helpEmbed;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
import {Command} from "../../../lib/Command";
|
||||||
|
import {CommandPermission} from "../../../lib/CommandPermission";
|
||||||
|
import {Message} from "discord.js";
|
||||||
|
import {CommandCategory} from "../../CommandCategory";
|
||||||
|
import { Help } from "./Help";
|
||||||
|
|
||||||
|
export class Say extends Command {
|
||||||
|
public static commandName = "say";
|
||||||
|
public static category = CommandCategory.UTILITY;
|
||||||
|
public static permission = CommandPermission.REGULAR;
|
||||||
|
public static description = "Replies with what you said.";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replies with the current ping.
|
||||||
|
* @param msg
|
||||||
|
*/
|
||||||
|
public invoke(msg: Message): void {
|
||||||
|
const msgContents = Say.getArgs(msg.content);
|
||||||
|
msgContents.shift();
|
||||||
|
const replyContent = msgContents.join(" ");
|
||||||
|
|
||||||
|
if (replyContent.replace(/\s/g, "").length > 0) {
|
||||||
|
msg.channel.send(replyContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
import {Command} from "../../../lib/Command";
|
||||||
|
import {CommandPermission} from "../../../lib/CommandPermission";
|
||||||
|
import {Message} from "discord.js";
|
||||||
|
import {CommandCategory} from "../../CommandCategory";
|
||||||
|
import { Help } from "./Help";
|
||||||
|
|
||||||
|
export class Yell extends Command {
|
||||||
|
public static commandName = "yell";
|
||||||
|
public static category = CommandCategory.UTILITY;
|
||||||
|
public static permission = CommandPermission.REGULAR;
|
||||||
|
public static description = "Yells what you said.";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replies with the current ping.
|
||||||
|
* @param msg
|
||||||
|
*/
|
||||||
|
public invoke(msg: Message): void {
|
||||||
|
const msgContents = Yell.getArgs(msg.content);
|
||||||
|
msgContents.shift();
|
||||||
|
const replyContent = msgContents.join(" ");
|
||||||
|
|
||||||
|
if (replyContent.replace(/\s/g, "").length > 0) {
|
||||||
|
msg.channel.send(replyContent.toUpperCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
import {Message} from "discord.js";
|
||||||
|
|
||||||
|
const messageRegex: RegExp = /^(.)(\w+)\s*(.*)$/;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class for parsing messages in an easier to handle format.
|
||||||
|
*/
|
||||||
|
export class ExtendedMessage {
|
||||||
|
|
||||||
|
public readonly originalMessage: Message;
|
||||||
|
public readonly content: string;
|
||||||
|
public readonly prefix: string;
|
||||||
|
public readonly commandName: string;
|
||||||
|
public readonly argString: string;
|
||||||
|
public readonly args: string[];
|
||||||
|
|
||||||
|
constructor(message: Message) {
|
||||||
|
this.originalMessage = message;
|
||||||
|
this.content = message.content;
|
||||||
|
const matches = this.content.match(messageRegex);
|
||||||
|
this.prefix = matches[1];
|
||||||
|
this.commandName = matches[2];
|
||||||
|
this.argString = matches[3];
|
||||||
|
this.args = matches[3].split(/\s+/).filter((s) => s.length > 0);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue