Skip to content

Commit

Permalink
Add example command file
Browse files Browse the repository at this point in the history
  • Loading branch information
fatton139 committed Jul 28, 2018
1 parent e6a74fa commit c2dd3e4
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/command/MyCustomCommands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// MyCustomCommands.ts
// Examples to demonstrate adding different types of commands.
import * as Discord from "discord.js";
import { FortniteBotAction } from "../action/FortniteBotAction";
import { ExecutableCommand } from "../command/ExecutableCommand";
import { AutoTriggerCommand } from "../command/AutoTriggerCommand";
import { FortniteBotTrigger } from "../action/FortniteBotTrigger";

// Example Executable Command.

// Example action. Takes 1 argument and sends it back to the channel.
const testCommandAction = new FortniteBotAction(1, (state, args) => {
const m: Discord.Message = state.getHandle();
if (args.length !== 1) {
return false; // Command failed.
}
m.channel.send(args[0]);
return true; // Command was successfully executed.
});

// To execute the command, call '!f testcommand'. Anyone with access level 0 can execute this command.
const testCommand = new ExecutableCommand("testcommand", 0, testCommandAction);

// Example Auto Trigger Command

// Example Triggers.
const trigger1 = new FortniteBotTrigger((state) => {
return Math.random() > 0.5; // Action will be executed if true. (50%)
});

const trigger2 = new FortniteBotTrigger((state) => {
const m: Discord.Message = state.getHandle();
return m.content === "egg"; // Action will be executed whenever the message is "egg".
});

// Example Action for auto trigger.
const testAutoAction = new FortniteBotAction(1, (state) => {
const m: Discord.Message = state.getHandle();
m.channel.send("This action was triggered");
return true;
});

// Set up the command with different triggers.
const autoCommand1 = new AutoTriggerCommand(0, testAutoAction, trigger1);
const autoCommand2 = new AutoTriggerCommand(0, testAutoAction, trigger2);

// Export all the commands.
export const myCustomCommands = [testCommand, autoCommand1, autoCommand2];

// Import in to the command manager with CommandManager.addBulkCommand() or CommandManager.addCommand().
// See FortniteBotEventCore.ts for example.

0 comments on commit c2dd3e4

Please sign in to comment.