Skip to content

Commit c257fb2

Browse files
authored
Merge pull request #6 from aXises/v2
Merge V2 documentation and formatting
2 parents 0e46504 + c2dd3e4 commit c257fb2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+907
-52
lines changed

README.md

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,114 @@
11
# Fortnite Bot
2-
A bot which pings selected targets whenever fortnite is mentioned. Use at your own risk.
2+
3+
![CodeFactor](https://www.codefactor.io/repository/github/axises/fortnitebot/badge) [![codecov](https://codecov.io/gh/aXises/fortniteBot/branch/master/graph/badge.svg)](https://codecov.io/gh/aXises/fortniteBot)
4+
[![Maintainability](https://api.codeclimate.com/v1/badges/51cbd263ff1f0afff332/maintainability)](https://codeclimate.com/github/aXises/fortniteBot/maintainability)
5+
[![Test Coverage](https://api.codeclimate.com/v1/badges/51cbd263ff1f0afff332/test_coverage)](https://codeclimate.com/github/aXises/fortniteBot/test_coverage)
6+
7+
A bot which pings selected targets whenever fortnite is mentioned. Use at your own risk. Despite its name, the main focus of the bot is to provide a flexible command system so that fun commands can be easily added to provide entertaining interactions between users and the bot.
8+
9+
## Requirements
10+
- Node 6 or higher
11+
- TypeScript 2
12+
- tslint is recommended for style consistency
13+
14+
## Build
15+
Clone the repository `git clone https://github.com/aXises/fortniteBot`
16+
17+
Install required packages `npm install`
18+
19+
Install TypeScript `npm install -g typescript`
20+
21+
Nodemon is recommended `npm install -g nodemon`
22+
23+
Compile TypeScript `tsc`
24+
25+
Configure API keys in fortniteBot.ts or with .env file
26+
27+
Running the application `node fortniteBot.js` or `nodemon fortniteBot.js`
28+
29+
## Creating commands
30+
It is recommended to place these in a seperate file.
31+
```
32+
// MyCustomCommands.ts
33+
// Examples to demonstrate adding different types of commands.
34+
import * as Discord from "discord.js";
35+
import { FortniteBotAction } from "../action/FortniteBotAction";
36+
import { ExecutableCommand } from "../command/ExecutableCommand";
37+
import { AutoTriggerCommand } from "../command/AutoTriggerCommand";
38+
import { FortniteBotTrigger } from "../action/FortniteBotTrigger";
39+
40+
// Example Executable Command.
41+
42+
// Example action. Takes 1 argument and sends it back to the channel.
43+
const testCommandAction = new FortniteBotAction(1, (state, args) => {
44+
const m: Discord.Message = state.getHandle();
45+
if (args.length !== 1) {
46+
return false; // Command failed.
47+
}
48+
m.channel.send(args[0]);
49+
return true; // Command was successfully executed.
50+
});
51+
52+
// To execute the command, call '!f testcommand'. Anyone with access level 0 can execute this command.
53+
const testCommand = new ExecutableCommand("testcommand", 0, testCommandAction);
54+
55+
// Example Auto Trigger Command
56+
57+
// Example Triggers.
58+
const trigger1 = new FortniteBotTrigger((state) => {
59+
return Math.random() > 0.5; // Action will be executed if true. (50%)
60+
});
61+
62+
const trigger2 = new FortniteBotTrigger((state) => {
63+
const m: Discord.Message = state.getHandle();
64+
return m.content === "egg"; // Action will be executed whenever the message is "egg".
65+
});
66+
67+
// Example Action for auto trigger.
68+
const testAutoAction = new FortniteBotAction(1, (state) => {
69+
const m: Discord.Message = state.getHandle();
70+
m.channel.send("This action was triggered");
71+
return true;
72+
});
73+
74+
// Set up the command with different triggers.
75+
const autoCommand1 = new AutoTriggerCommand(0, testAutoAction, trigger1);
76+
const autoCommand2 = new AutoTriggerCommand(0, testAutoAction, trigger2);
77+
78+
// Export all the commands.
79+
export const myCustomCommands = [testCommand, autoCommand1, autoCommand2];
80+
81+
// Import in to the command manager with CommandManager.addBulkCommand() or CommandManager.addCommand().
82+
// See FortniteBotEventCore.ts for example.
83+
```
84+
385

486
## Commands
587
```
6-
!fortnite - Asks your targets to play fortnite.
7-
!fortnite tts - Asks your targets to play fortnite but more nicely.
8-
!fortnite target {@target1} {@target2} ... {@targetn} - Set new targets/friends.
9-
!fortnite auto {amount} {delay(ms)} - Ask your friends many times
10-
!fortnite delete - Deletes all messages sent by the bot.
88+
Standard Commands
89+
!f - Asks your targets to play fortnite.
90+
!f ping - Check for response.
91+
!f help - Displays help message.
92+
!f target @target - Adds target to the targetlist.
93+
!f targetlist - Shows the current targets.
94+
!f removeself - Removes yourself from the targetlist.
95+
!f auto amount delay(s) - Automatically ping the targets a set amount of times with an delay.
96+
97+
User Commands
98+
!f register - Registers yourself.
99+
!f profile - Check your profile.
100+
!f daily - Grab daily rewards.
101+
102+
Shop Commands
103+
!f shoplist - Displays all available shops.
104+
!f viewshop shopname - View a shop.
105+
!f buy index/itemname from shopname - Buy an item from a shop.
106+
107+
...More coming soon.
11108
```
109+
12110
## Contributing
13-
~~Don't.~~
111+
All contribtions are welcome. Adhering to tslint style is recommeded.
14112

15113
## Disclaimer
16114
I do not play nor have any affiliation with Fortnite. This application is a simple tool to ~~spam~~ ask your friends/server members.

fortniteBot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ dotenvConfig();
88
const keys = {
99
discordToken: process.env.discordToken,
1010
chatBotUserId: process.env.chatBotUserId,
11-
chatBotAPIKey: process.env.chatBotAPIKey
11+
chatBotApiKey: process.env.chatBotApiKey
1212
};
1313

1414
const initConfig = new FortniteBotInitConfig(keys.discordToken,
15-
keys.chatBotUserId, keys.chatBotAPIKey);
15+
keys.chatBotUserId, keys.chatBotApiKey);
1616

1717
export const fortniteBotCore = new FortniteBotCore(initConfig);
1818

src/action/FortniteBotAction.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
11
import { FortniteBotState } from "../state/FortniteBotState";
22

33
export class FortniteBotAction {
4+
/**
5+
* Number of arguments this action requires.
6+
*/
47
public argLength: number;
8+
9+
/**
10+
* An action to invoke.
11+
*/
512
public action: (stateHandle: FortniteBotState, args: string[]) => boolean;
13+
14+
/**
15+
* @classdesc Base class for a standard action executed by the bot.
16+
* @param argLength - Number of arguments the action requires.
17+
* @param action - An action to invoke.
18+
*/
619
public constructor(argLength: number,
720
action: (stateHandle: FortniteBotState,
821
args: string[]) => boolean) {
922
this.argLength = argLength;
1023
this.action = action;
1124
}
25+
26+
/**
27+
* Executes the action with a set of arguments.
28+
* @param state - A Handle for the action to bind to.
29+
* @param args - Arguments to execute the action with.
30+
* @returns true if the command was successfully executed.
31+
*/
1232
public execute(state: FortniteBotState, args: string[]): boolean {
1333
return this.action(state, args);
1434
}

src/action/FortniteBotTrigger.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,19 @@ import { FortniteBotAction } from "./FortniteBotAction";
22
import { FortniteBotState } from "../state/FortniteBotState";
33

44
export class FortniteBotTrigger extends FortniteBotAction {
5+
/**
6+
* @classdesc Base trigger class, invokes an FortniteBotAction if conditions are met.
7+
* @param trigger - A trigger to invoke, returns true if conditions are met.
8+
*/
59
public constructor(trigger: (state: FortniteBotState) => boolean) {
610
super(0, trigger);
711
}
12+
13+
/**
14+
* Attempt to execute the trigger.
15+
* @param state A Handle for the trigger to bind to.
16+
* @returns true if the command was successfully executed.
17+
*/
818
public execute(state: FortniteBotState): boolean {
919
return super.execute(state, null);
1020
}

src/action/RequestResponseAction.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { FortniteBotState } from "../state/FortniteBotState";
22
import { FortniteBotAction } from "./FortniteBotAction";
33

44
export class RequestResponseAction extends FortniteBotAction {
5+
/**
6+
* @classdesc An action which requires a user response.
7+
* @param argLength - Number of arguments the action requires.
8+
* @param action - An action to invoke.
9+
*/
510
public constructor(argLength: number,
611
action: (stateHandle: FortniteBotState,
712
args: string[]) => boolean) {

src/command/AutoTriggerCommand.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,28 @@ import { FortniteBotAction } from "action/FortniteBotAction";
44
import { FortniteBotTrigger } from "action/FortniteBotTrigger";
55
import { fortniteBotCore as activeCore } from "../../fortniteBot";
66

7-
/**
8-
* Commands which are auto triggered.
9-
*/
10-
117
export class AutoTriggerCommand extends Command implements ICommand {
8+
/**
9+
* The condition required to execute the action.
10+
*/
1211
public trigger: FortniteBotTrigger;
12+
13+
/**
14+
* @classdesc Commands which are triggered without user directly calling it.
15+
* @param accessLevel - The required access level to execute this command.
16+
* @param action - The action to execute.
17+
* @param trigger - The condition required to execute the action.
18+
*/
1319
public constructor(accessLevel: number,
1420
action: FortniteBotAction, trigger: FortniteBotTrigger) {
1521
super(null, accessLevel, action);
1622
this.trigger = trigger;
1723
}
24+
25+
/**
26+
* Attempt to execute the trigger.
27+
* @returns true if conditions of the trigger has been met.
28+
*/
1829
public tryTrigger(): boolean {
1930
return this.trigger.execute(activeCore.getCoreState());
2031
}

src/command/Command.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,52 @@ import { fortniteBotCore } from "../../fortniteBot";
88
import { fortniteBotCore as activeCore } from "../../fortniteBot";
99

1010
export class Command implements ICommand {
11+
/**
12+
* The string required to execute this command.
13+
*/
1114
public commandString?: string;
15+
16+
/**
17+
* The required access level to execute this command.
18+
*/
1219
public readonly accessLevel: number;
20+
21+
/**
22+
* An action to execute.
23+
*/
1324
public action: FortniteBotAction;
25+
26+
/**
27+
* Arguments to execute the action with.
28+
*/
1429
public args: string[];
30+
31+
/**
32+
* @classdesc Base command class for the bot.
33+
* @param commandString - The string required to execute this command.
34+
* @param accessLevel - The required access level to execute this command.
35+
* @param action - The action to execute.
36+
*/
1537
public constructor(commandString: string, accessLevel: number,
1638
action: FortniteBotAction) {
1739
this.action = action;
1840
this.accessLevel = accessLevel;
1941
this.commandString = commandString;
2042
}
43+
44+
/**
45+
* Changes the arguments of the command.
46+
* @param args - New arguments for the command.
47+
*/
2148
public setArgs(args: string[]): void {
2249
this.args = args;
2350
}
24-
public executeAction(user: User): void {
2551

52+
/**
53+
* Execute the action provided by this command.
54+
* @param user - The user attempting to execute this command.
55+
*/
56+
public executeAction(user: User): void {
2657
if (user.accessLevel < this.accessLevel) {
2758
const m = activeCore.getCoreState().getHandle() as Discord.Message;
2859
m.reply(

0 commit comments

Comments
 (0)