Skip to content
This repository has been archived by the owner on Aug 27, 2018. It is now read-only.

Commit

Permalink
Cutting Indev to Master for NPM 0.10.0 release (#76)
Browse files Browse the repository at this point in the history
* Added padding to help command

* Removed one line function

* Added padding to help command

* Custom Permission Roles Support

* Adds member usage type.

* parseUsage fix and member usage type

* Allows multi word values to be used

* Fix random missing periods, spelling, etc.

* bot owner commands only...

* Fix for Core 'conf' command

* Adds Boolean Usage type and reverts old boolean fix

* Reverted again and made value checking better.
Will now correctly change depending on the type of the key.
Set can now set a boolean key as 'false'

* Quick fix for disable.js not disabling commands in
disabledCommands array

* Fix for default config being 'out of sync' on updates

* Better 'Fix', which allow you to use setKey, and not
have your default options overwritten, but still add
missing keys if you don't have them

* Updated forEach per Ao's recommendation

* Download.js VM "Cannot Find Module" Fix

* Readded Cybers selfbot option && fix for it

* If command is now selfbot only and bot is not a selfbot,
The bot will now uninstall the modules it previously installed.

* Selfbot commands now correctly load or not if selfbot

* Bumping Komada Core to use D.JS Indev

* Eslint/Beautify everything~

* Updated ESLint to allow Template Literals

* Fix Resolves/Rejects to stop executing further code

* Delete .jsbeautifyrc

* Update .eslintrc.json

* Update package.json

* Update package.json

* Various Changes.

* Update .eslintrc.json

* Fixed

* Conf.js Fix && Eslint

* The Great Conf Fix

* Update confs.js

* Eslinting Patch

* ESlint them all

* Fucked up?

* Semver Patch

* Fixes

* Bumped

* Monitors addition (#71)

* Monitors Loading && Monitors Running

* Message Event ignores bot messages and runs monitors

* Profanity- 1st Monitor Example

* Ignores Bots, Outputs Error Stacks into console

* Semver minor bump

Monitors

* removal of max-len from linter

* oops. I mean semver patch

* Better Support for Arrays/Ints/Booleans/Strings

* Update package.json

* Monitors/Inhibitors Uncaught Exception fix

* Verison Bumps

* Fixes Galore

* Aye Fixed Komada not listening to itself

* Reload all the things! (#75)

* Fixes last eslint issues and codeblock undefined issue

* New Reload.js Command.

* Reload Function! Reload all the pieces now!

* Fixes for Function/Command reload.js

* Semver Minor. Preparing for NPM release

* Create CHANGELOG.MD

* Rename CHANGELOG.MD to CHANGELOG.md

* Changelog Released.
  • Loading branch information
CyberiumShadow authored Nov 21, 2016
1 parent 1627e6d commit 8469fb9
Show file tree
Hide file tree
Showing 52 changed files with 1,895 additions and 1,364 deletions.
23 changes: 18 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": { "sourceType": "module" },
"extends": "airbnb-base",
"rules": {
"no-console": "off",
"indent": ["error", 2, { "SwitchCase": 1 } ],
"indent": ["error", 2, { "SwitchCase": 1 }],
"linebreak-style": "off",
"quotes": [ "warn", "double" ],
"semi": [ "warn", "always" ]
"quotes": ["warn", "double"],
"semi": ["warn", "always"],
"no-param-reassign": "off",
"no-shadow": "warn",
"no-plusplus": "off",
"radix": ["error", "as-needed"],
"max-len": "warn",
"import/no-extraneous-dependencies": "off",
"import/no-unresolved": "off",
"no-prototype-builtins": "warn",
"no-restricted-syntax": "warn",
"guard-for-in": "warn",
"consistent-return": ["warn", { "treatUndefinedAsUnspecified": true }],
"no-use-before-define": ["warn", { "functions": true, "classes": true }],
"no-eval": "warn",
"max-len": "off"
}
}
30 changes: 0 additions & 30 deletions .jsbeautifyrc

This file was deleted.

52 changes: 52 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Change Log
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [0.10.0] - 2016-11-21
### Added
- Reloading for Functions, Events, Inhibitors, Monitors from [UnseenFaith]
- Monitors from [UnseenFaith]
- ESLint Rules added from [CyberiumShadow] and [hkwu]
- Discord.JS Indev Support from [CyberiumShadow]
- Custom Permissions Roles from [UnseenFaith]

### Changed
- New Reload.js Command. from [UnseenFaith]
- Komada no longer listens to bots. from [CyberiumShadow]
- Better support for Arrays/Ints/Booleans/Strings in confs from [UnseenFaith]
- Changing commands to bot owner only. from [eslachance]
- Allowing multiword values to be used in confs from [CyberiumShadow]
- Padding from [vzwGrey]

### Fixed
- Fixes for Function/Command reload.js from [UnseenFaith]
- Fixes last eslint issues and codeblock undefined issue from [UnseenFaith]
- Monitors/Inhibitors Uncaught Exception fix from [UnseenFaith]
- The Great Conf Fix from [UnseenFaith]
- Fixed Promise Resolve/Rejects to prevent further code execution from [bdistin]
- Download.js VM "Cannot Find Module" Fix from [UnseenFaith]
- Various Confs fixes from [UnseenFaith]
- Usage Addition/ParseUsage fix from [UnseenFaith]

### Contribution Count (Latest Update)
- [UnseenFaith]: 12 contributions
- [CyberiumShadow]: 4 contributions
- [bdistin]: 1 contribution
- [hkwu]: 1 contribution
- [eslachance]: 1 contribution
- [vzwGrey]: 1 contribution


[Unreleased]: https://github.com/eslachance/komada/compare/v0.10.0...HEAD
[0.10.0]: https://github.com/eslachance/komada/compare/1627e6deb1d8c352d83e52ccd590f2330f5f8bb2...v0.10.0

[vzwGrey]: https://github.com/vzwGrey
[eslachance]: https://github.com/eslachance
[hkwu]: https://github.com/hkwu
[bdistin]: https://github.com/bdistin
[UnseenFaith]: https://github.com/UnseenFaith
[CyberiumShadow]: https://github.com/CyberiumShadow
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ npm install
node app.js
```

> Requires Node 6 or higher (because discord.js requires that), also requires Discord.js v10 (currently #indev), installed automatically with `npm install`.
> Requires Node 6 or higher (because Discord.js requires that), also requires Discord.js v10, installed automatically with `npm install`.
## Quick & Dirty Reference Guide
> For creating your own pieces
Essentially, the way Komada works is that we have *core* pieces (functions, events, commands, etc) loaded automatically.
But you can add your own pieces easily by adding files to your *local* folders (which are created on first load)
Essentially, the way Komada works is that we have *core* pieces (functions, events, commands, etc.) loaded automatically.
But you can add your own pieces easily by adding files to your *local* folders (which are created on first load).

These pieces are:
- **Commands** which add in-chat functionality to your bot
These pieces are:
- **commands** which add in-chat functionality to your bot.
- **functions** which can be used by other pieces or anywhere in the bot.
- **dataHandlers** which are database connectors (in progress at the moment)
- **dataHandlers** which are database connectors (in progress at the moment).

### Creating a new command

Expand All @@ -64,12 +64,12 @@ the categories offered in the help command. For instance adding `./commands/Misc
will create a command named `test` in the `Misc` category. Subcategories can
also be created by adding a second folder level.

> If a command is present both in the *core* folders and your client folders,
> If a command is present both in the *core* folders and your client folders,
your command will override the core one. This can let you modify the core
behaviour. Note also that you cannot have more than one command with the same name.

```js
exports.run = (client, msg. [...args]) => {
exports.run = (client, msg, [...args]) => {
// Place Code Here
};

Expand All @@ -94,13 +94,13 @@ exports.help = {
run. The name of the arguments in the array (and their count) is determined
by the `usage` property and its given arguments.

**Non-obvious options**:
**Non-obvious options**:
- **enabled**: Set to false to completely disable this command, it cannot be forecefully enabled.
- **aliases**: Array of aliases for the command, which will *also* trigger it.
- **permLevel**: Permission level, controlled via `./functions/permissionLevel.js`
- **permLevel**: Permission level, controlled via `./functions/permissionLevel.js`.
- **botPerms**: An array of permission strings (such as `"MANAGE_MESSAGES"`) required for the command to run.
- **requiredFuncs**: An array of function names required for this command to execute (dependency)
- **usage**: The usage string as determined by the Argument Usage (see below)
- **requiredFuncs**: An array of function names required for this command to execute (dependency).
- **usage**: The usage string as determined by the Argument Usage (see below).

#### Command Arguments

Expand All @@ -110,22 +110,22 @@ by the `usage` property and its given arguments.
`<Name:Type{min,max}>`

- **Name** Mostly used for debugging message, unless the type is Litteral in which it compares the argument to the name.
- **Type** The type of variable you are expecting
- **Type** The type of variable you are expecting.
- **Min, Max** Minimum or Maximum for a giving variable (works on strings in terms of length, and on all types of numbers in terms of value) You are allowed to define any combination of min and max. Omit for none, `{min}` for min, `{,max}` for max.
- **Special Repeat Tag** `[...]` will repeat the last usage optionally until you run out of arguments. Useful for doing something like `<SearchTerm:str> [...]` which will allow you to take as many search terms as you want, per your Usage Deliminator.
- **Special Repeat Tag** `[...]` will repeat the last usage optionally until you run out of arguments. Useful for doing something like `<SearchTerm:str> [...]` which will allow you to take as many search terms as you want, per your Usage Delimiter.

**Usage Types**

- `literal` : Literally equal to the Name. This is the default type if none is defined.
- `str`, `string` : Strings
- `int`, `integer` : Integers
- `num`, `number`, `Float` : Floating point numbers
- `url` : a url
- `msg`, `message` : A message object returned from the message id (now using fetchMessage as of d3d498c99d5eca98b5cbcefb9838fa7d96f17c93)
- `channel` : A channel object returned from the channel id or channel tag
- `guild` : A guild object returned from the guild id
- `user`, `mention` : A user object returned from the user id or mention
- `str`, `string` : Strings.
- `int`, `integer` : Integers.
- `num`, `number`, `Float` : Floating point numbers.
- `url` : A URL.
- `msg`, `message` : A message object returned from the message ID (now using fetchMessage as of d3d498c99d5eca98b5cbcefb9838fa7d96f17c93).
- `channel` : A channel object returned from the channel ID or channel tag.
- `guild` : A guild object returned from the guild ID.
- `user`, `mention` : A user object returned from the user ID or mention.

### Creating an event

Events are placed in `./events/` and their filename must be `eventName.js`.
Expand All @@ -140,8 +140,8 @@ exports.run = (client, [...args]) => {
};
```

Where `[...args]` is arguments you would *normally* get from those events.
For example, while the `ready` event would only have `(client)`, the
Where `[...args]` are arguments you would *normally* get from those events.
For example, while the `ready` event would only have `(client)`, the
`guildMemberAdd` event would be `(guild, member)`.

### Creating a function
Expand All @@ -164,4 +164,4 @@ module.exports = (str) => {
```

The arguments are arbitrary - just like a regular function. It may, or may not,
return anything. Basically any functions. You know what I mean.
return anything. Basically any functions. You know what I mean.
55 changes: 30 additions & 25 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
const Discord = require("discord.js");
const chalk = require("chalk");
const loadFunctions = require("./functions/loadFunctions.js");

const clk = new chalk.constructor({ enabled: true });

exports.start = (config) => {

const client = new Discord.Client(config.clientOptions);

client.config = config;

// Extend client
client.config["init"] = [];
client.config.init = [];
client.funcs = {};
client.helpStructure = new Map();
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
client.commandInhibitors = new Discord.Collection();
client.commandMonitors = new Discord.Collection();
client.dataProviders = new Discord.Collection();

client.coreBaseDir = __dirname + "/";
client.clientBaseDir = process.cwd() + "/";
client.coreBaseDir = `${__dirname}/`;
client.clientBaseDir = `${process.cwd()}/`;

// Load core functions, then everything else
require("./functions/loadFunctions.js")(client).then(() => {
loadFunctions(client).then(() => {
client.funcs.loadDataProviders(client);
client.funcs.loadCommands(client);
client.funcs.loadCommandInhibitors(client);
client.funcs.loadCommandMonitors(client);
client.funcs.loadEvents(client);
});

Expand All @@ -34,48 +37,50 @@ exports.start = (config) => {
});

client.once("confsRead", () => {
client.commands.forEach(command => {
if(command.init) {
client.commands.forEach((command) => {
if (command.init) {
command.init(client);
}
});
});

client.on("message", msg => {
let conf = client.funcs.confs.get(msg.guild);
client.on("message", (msg) => {
if (msg.author.bot && msg.author.id !== client.user.id) return;
const conf = client.funcs.confs.get(msg.guild);
msg.guildConf = conf;
client.funcs.runCommandMonitors(client, msg).catch(reason => msg.channel.sendMessage(reason).catch(console.error));
if (!msg.content.startsWith(conf.prefix) && !client.config.prefixMention.test(msg.content)) return;
let prefixLength = conf.prefix.length;
if(client.config.prefixMention.test(msg.content)) prefixLength = client.config.prefixMention.exec(msg.content)[0].length +1;
let command = msg.content.slice(prefixLength).split(" ")[0].toLowerCase();
let suffix = msg.content.slice(prefixLength).split(" ").slice(1).join(" ");
if (client.config.prefixMention.test(msg.content)) prefixLength = client.config.prefixMention.exec(msg.content)[0].length + 1;
const command = msg.content.slice(prefixLength).split(" ")[0].toLowerCase();
const suffix = msg.content.slice(prefixLength).split(" ").slice(1).join(" ");
let commandLog;
switch (msg.channel.type) {
case "text":
commandLog = `${clk.black.bgYellow(`${msg.author.username}<@${msg.author.id}>`)} : ${clk.bold(command)}('${suffix ? suffix : ""}') => ${clk.bgGreen(`${msg.guild.name}[${msg.guild.id}]`)}`;
break;
case "dm":
commandLog = `${clk.black.bgYellow(`${msg.author.username}<@${msg.author.id}>`)} : ${clk.bold(command)}('${suffix ? suffix : ""}') => ${clk.bgMagenta("[Direct Messages]")}`;
commandLog = `${clk.black.bgYellow(`${msg.author.username}<@${msg.author.id}>`)} : ${clk.bold(command)}('${suffix}') => ${clk.bgMagenta("[Direct Messages]")}`;
break;
case "group": //works for selfbots only
commandLog = `${clk.black.bgYellow(`${msg.author.username}<@${msg.author.id}>`)} : ${clk.bold(command)}('${suffix ? suffix : ""}') => ${clk.bgCyan(`${msg.channel.owner.username}[${msg.channel.owner.id}] in [GroupDM]`)}`;
case "group": // works for selfbots only
commandLog = `${clk.black.bgYellow(`${msg.author.username}<@${msg.author.id}>`)} : ${clk.bold(command)}('${suffix}') => ${clk.bgCyan(`${msg.channel.owner.username}[${msg.channel.owner.id}] in [GroupDM]`)}`;
break;
default: // text channels
commandLog = `${clk.black.bgYellow(`${msg.author.username}<@${msg.author.id}>`)} : ${clk.bold(command)}('${suffix}') => ${clk.bgGreen(`${msg.guild.name}[${msg.guild.id}]`)}`;
}
let cmd;
if (client.commands.has(command)) {
cmd = client.commands.get(command);
} else if (client.aliases.has(command)) {
cmd = client.commands.get(client.aliases.get(command));
}
if(!cmd) return;
if (!cmd) return;
client.funcs.runCommandInhibitors(client, msg, cmd)
.then(params => {
.then((params) => {
client.funcs.log(commandLog);
cmd.run(client, msg, params);
})
.catch(reason => {
if(reason) {
msg.channel.sendMessage(reason).catch(console.error);
.catch((reason) => {
if (reason) {
if (reason.stack) client.funcs.log(reason.stack, "error");
msg.channel.sendCode("", reason).catch(console.error);
}
});
});
Expand All @@ -84,6 +89,6 @@ exports.start = (config) => {
return client;
};

process.on("unhandledRejection", err => {
console.error("Uncaught Promise Error: \n" + err.stack);
process.on("unhandledRejection", (err) => {
console.error(`Uncaught Promise Error: \n${err.stack}`);
});
Loading

0 comments on commit 8469fb9

Please sign in to comment.