Skip to content

Commit

Permalink
Merge pull request #3 from Khaazz/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
bsian03 authored Jan 19, 2020
2 parents fc7b792 + 5f95896 commit 88531a6
Show file tree
Hide file tree
Showing 14 changed files with 284 additions and 53 deletions.
21 changes: 20 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
{
"extends": "@axonteam"
"extends": "@axonteam",
"overrides": [
{
"files": ["*.ts"],
"extends": [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"rules": {
"no-useless-constructor": 0,
"no-magic-numbers": 0,
"max-classes-per-file": 0,
"lines-between-class-members": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-use-before-define": [ 2, { "classes": false} ]
}
}
]

}
41 changes: 41 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Contributing

**The issue tracker is only for bug reports and enhancement suggestions. If you have a question, please ask it in the [Discord server](https://discord.gg/QZ6B5US) instead of opening an issue – you will get redirected there anyway.**

If you wish to contribute to AxonCore codebase or documentation, feel free to fork the repository and submit a
pull request.

## Tools

We use ESLint to enforce a consistent coding style.
We also use yarn as dependency manager. A `package-lock.json` should never be commited.

## Setup

To get ready to work on the codebase, please do the following:

1. Fork & clone the repository, and make sure you're on the **dev** branch
2. Run `yarn` to install dependencies
3. Add your features, bug fix, documentatin change etc...!
4. Make sure your code pass the tests: run `yarn test` and make sure it does not errors out
5. [Submit a pull request](https://github.com/Khaazz/AxonCore/compare)

## Semantic commit messages

A better commit structure help navigate through commit history and build patch-note by easily identifying the level of change of said commit.
Here the commit types used in this project:

- fix(file): fix, **PATCH**
- refactor(file): improvement, implementation change without API change, **PATCH**
- perf(file): performance improvement (same as refactor) **PATCH**, **MINOR**
- feat(file): change, addition (new feature), minor API change, **MINOR**
- BREAKING(file): big API change **MAJOR**
- docs(file): documentation only change
- chore: CI and internal / dev tool changes
- typings: typings improvement or change **PATCH / MINOR**
- style: code formatting only change

Adding `(file)` is optional and is used to specify the file changed.

*Example*:
feat(Command): Add Command.useless that does nothing.
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# BUG REPORT

Issue description.

**Additional information:**

- Node.js version:
- AxonCore version:
- Library used: (eris, discordjs, detritus...)
- Library version:
- DB engine used: (json, mongoose, sequelise...)
16 changes: 16 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Change this Pull Request introduce

PR description.

**Status:**

- [ ] Typings have been updated or don't need to be.
- [ ] This PR have been tested and is ready to be merged

**Semantic versioning classification:**

- [ ] This PR introduces Breaking Changes.
- [ ] This PR adds new features, improve the code and implies minimal changes.
- [ ] This PR fixes a bug and references the relevant issue or documentation.
- [ ] This PR improve performance or refactor code without API changes.
- [ ] This PR **only** includes non-code changes (documentation, CI, tools...).
3 changes: 0 additions & 3 deletions .github/workflows/docgen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@master

- name: Install Node v12
uses: actions/setup-node@master
with:
node-version: 12

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Generate and commit documentation
uses: axonteam/action-docgen@master
23 changes: 20 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,27 @@ name: Test
on: [push, pull_request]

jobs:
lint:

lint-js:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: yarn install and lint
run: |
yarn install
yarn lint:js
env:
CI: true

lint-ts:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
Expand All @@ -20,6 +37,6 @@ jobs:
- name: yarn install and lint
run: |
yarn install
yarn test:push
yarn lint:ts
env:
CI: true
1 change: 1 addition & 0 deletions axoncore.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

// vsCode eslint support
"eslint.enable": true,
"eslint.validate": ["javascript", "typescript"],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
Expand Down
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,24 @@
"@axonteam/eslint-config": "^2.2.0",
"@types/mongoose": "^5.5.32",
"@types/node": "^12.12.14",
"@typescript-eslint/eslint-plugin": "^2.16.0",
"@typescript-eslint/parser": "^2.16.0",
"chalk": "^2.4.2",
"discord.js": "discordjs/discord.js",
"eris": "abalabahaha/eris#dev",
"eslint": "^6.6.0",
"eslint": "^6.8.0",
"mongoose": "^5.7.7",
"superagent": "^5.1.0",
"typescript": "^3.6.4",
"yarn": "^1.19.1"
"superagent": "^5.2.1",
"typescript": "^3.7.5",
"yarn": "^1.21.1"
},
"main": "./index.js",
"types": "./index.d.ts",
"scripts": {
"lint": "eslint src examples *.js",
"lint": "yarn run lint:js && yarn run lint:ts",
"lint:js": "eslint src examples *.js",
"lint:ts": "eslint index.d.ts",
"test": "yarn run lint",
"test:push": "eslint src examples *.js",
"test:publish": "eslint src *.js",
"docgen": "node ./scripts/gendoc.js && cp README.md ./docs/README.md",
Expand Down
62 changes: 54 additions & 8 deletions src/AxonClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,30 @@ class AxonClient extends EventEmitter {
}

// **** EXECUTOR **** //
/**
* Fired when a command is successfully ran
* @event AxonClient#commandExecution
* @prop {Boolean} status - Whereas the command was successfully executed or not
* @prop {String} commandFullLabel - The command fullLabel
* @prop {Object} data
* @prop {Message} data.msg - The message that triggered the command
* @prop {Command} data.command - The Command that was executed
* @prop {GuildConfig} data.guildConfig - The GuildConfig
* @prop {CommandContext} data.context - The execution context
* @memberof AxonClient
*/

/**
* Fired when a command fails
* @event AxonClient#commandError
* @prop {String} commandFullLabel - The command fullLabel
* @prop {Object} data
* @prop {Message} data.msg - The message that triggered the command
* @prop {Command} data.command - The Command that was executed
* @prop {GuildConfig} data.guildConfig - The GuildConfig
* @prop {AxonCommandError} data.error - The error
* @memberof AxonClient
*/

_execCommand(msg, args, command, guildConfig, { isAdmin, isOwner } ) {
if (this.settings.debugMode) {
Expand All @@ -509,14 +533,12 @@ class AxonClient extends EventEmitter {
msg, args, guildConfig, isAdmin, isOwner,
} )
.then( (context) => {
context.executed
? this.emit('commandSuccess', { msg, guildConfig, context } )
: this.emit('commandFailure', { msg, guildConfig, context } );
this.emit('commandExecution', context.executed, command.fullLabel, { msg, command, guildConfig, context } );

this.settings.debugMode && console.timeEnd('- Net');
} )
.catch(err => {
this.emit('commandError', { msg, guildConfig, err } );
this.emit('commandError', command.fullLabel, { msg, command, guildConfig, error: err } );
this.settings.debugMode && console.timeEnd('- Net');

this.log('ERROR', err);
Expand All @@ -543,11 +565,11 @@ class AxonClient extends EventEmitter {
msg, args, guildConfig, isAdmin, isOwner,
} )
.then( (context) => {
this.emit('commandSuccess', { msg, guildConfig, context } );
this.emit('commandExecution', true, command.label, { msg, command, guildConfig, context } );
this.settings.debugMode && console.timeEnd('- Net');
} )
.catch(err => {
this.emit('commandError', { msg, guildConfig, err } );
this.emit('commandError', command.label, { msg, command, guildConfig, err } );
this.settings.debugMode && console.timeEnd('- Net');

this.log('ERROR', err);
Expand All @@ -558,16 +580,40 @@ class AxonClient extends EventEmitter {
}
}

/**
* Fired when a command fails
* @event AxonClient#eventExecution
* @prop {Boolean} status - Whereas the listener was successfully executed or not
* @prop {String} eventName - The discord event name
* @prop {String} listenerName - The listener label
* @prop {Object} data - Additional information
* @prop {Listener} data.listener - The Listener that was executed
* @prop {GuildConfig} data.guildConfig - The GuildConfig object
* @memberof AxonClient
*/

/**
* Fired when a command fails
* @event AxonClient#eventError
* @prop {String} eventName - The discord event name
* @prop {String} listenerName - The Listener label
* @prop {Object} data - Additional information
* @prop {Listener} data.listener - The Listener that was executed
* @prop {GuildConfig} data.guildConfig - The GuildConfig object
* @prop {Error} data.error - The error
* @memberof AxonClient
*/

_execListener(listener, guildConfig, ...args) {
listener._execute(guildConfig, ...args)
.then( () => {
if (this.settings.debugMode) {
this.log('VERBOSE', `[EVENT](${listener.eventName}) - ${listener.label}`);
}
this.emit('eventSuccess', { event: listener.eventName, listener, guildConfig } );
this.emit('eventExecution', true, listener.eventName, listener.label, { listener, guildConfig } );
} )
.catch(err => {
this.emit('eventError', { event: listener.eventName, listener, guildConfig, err } );
this.emit('eventError', listener.eventName, listener.label, { listener, guildConfig, error: err } );

this.log('ERROR', `[EVENT](${listener.eventName}) - ${listener.label}\n${err}`);
} );
Expand Down
9 changes: 3 additions & 6 deletions src/Structures/Command/Command.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,10 @@ class Command extends Base {
* @memberof Command
*/
get fullLabel() {
let cmd = this; // eslint-disable-line
const fullLabel = [this.label];
while (cmd.parentCommand) {
fullLabel.push(cmd.parentCommand.label);
cmd = cmd.parentCommand;
if (!this.parentCommand) {
return this.label;
}
return fullLabel.reverse().join(' ');
return `${this.parentCommand.fullLabel} ${this.label}`;
}

// **** MAIN **** //
Expand Down
2 changes: 1 addition & 1 deletion src/Structures/Command/CommandContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { COMMAND_EXECUTION_TYPES, COMMAND_EXECUTION_STATE } from '../../Utility/
* @class CommandContext
*
* @prop {String} raw - Raw input
* @prop {String} commandLabel - The command name
* @prop {String} commandLabel - The command full label
* @prop {String} moduleLabel - The module name
* STATUS
* @prop {Boolean} [executed=true] - Whether the command was actually executed or not
Expand Down
16 changes: 16 additions & 0 deletions src/Structures/Event/Listener.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Base from '../Base';
import GuildConfig from '../DataStructure/GuildConfig'; // eslint-disable-line

import NotImplementedException from '../../Errors/NotImplementedException';

/**
* Default Listener class
* Extends Listener to create an event
Expand Down Expand Up @@ -81,6 +83,20 @@ class Listener extends Base {
async _execute(guildConfig, ...args) {
return this.execute(...args, guildConfig); // No execute function
}

/**
* Main execute function, need to be overriden in child.
*
* @param {Array} args - Array of the events arguments (as separate parameters)
* @param {GuildConfig?} guildConfig - The guildConfig or undefined if not a guild event
* @returns {Promise}
*
* @memberof Listener
*/
// eslint-disable-next-line no-unused-vars
async execute(args, guildConfig) {
throw new NotImplementedException();
}
}

export default Listener;
34 changes: 17 additions & 17 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"compilerOptions": {
"target": "es6",
"module": "ES6",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"lib": ["es6"]
},
"files": ["index.d.ts"]
}
"compilerOptions": {
"target": "es6",
"module": "ES6",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"lib": ["es6"]
},
"files": ["index.d.ts"]
}
Loading

0 comments on commit 88531a6

Please sign in to comment.