Skip to content

Commit

Permalink
global refactoring, AxonCore base
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaaz committed Jul 21, 2018
1 parent ff178cb commit 0e24bf3
Show file tree
Hide file tree
Showing 24 changed files with 650 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# conf
src/configs/tokenConf.json

# Logs
logs
*.log
Expand Down
Empty file removed docs/.gitkeep
Empty file.
25 changes: 16 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
{
"name": "splashtoonbot",
"name": "webspell",
"version": "0.1.0",
"description": "Splashtoon bot - handle rss feed and misc",
"description": "webSpell bot - handle rss feed and misc",
"author": "KhaaZ#0001",
"license": "ISC",
"dependencies": {
"bluebird": "^3.5.1",
"eris": "^0.8.6",
"axoncore": "git+https://github.com/Khaazz/AxonCore.git",
"chalk": "^2.4.1",
"eris": "git+https://github.com/Khaazz/eris.git#axoncore",
"esm": "^3.0.72",
"eventemitter3": "^3.1.0",
"moment": "^2.22.2",
"mongoose": "^5.2.3",
"pm2": "^3.0.0"
"pm2": "^3.0.0",
"winston": "^3.0.0"
},
"devDependencies": {
"cloc": "^2.3.3",
"eslint": "^5.1.0",
"yarn": "^1.7.0"
},
"main": "index.js",
"scripts": {
"lint": "lint .",
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
"start": "node -r esm src/index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Khaazz/splashtoonBot.git"
"url": "git+https://github.com/Khaazz/webSPELL.git"
},
"bugs": {
"url": "https://github.com/Khaazz/splashtoonBot/issues"
"url": "https://github.com/Khaazz/webSPELL/issues"
},
"homepage": "https://github.com/Khaazz/splashtoonBot#readme",
"homepage": "https://github.com/Khaazz/webSPELL#readme",
"keywords": [
"bot",
"discord",
Expand Down
10 changes: 5 additions & 5 deletions scripts/startStable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const pm2 = require('pm2');
//

// Start process
console.log('>> Starting SplashtonBot');
console.log('>> Starting webSpell');
pm2.connect(function(err) {
if (err) {
console.error(err);
Expand All @@ -12,13 +12,13 @@ pm2.connect(function(err) {
pm2.start({
script: 'stableMain.js',
args: [ '--color' ],
name: 'SplashtonBot',
name: 'webSpell',
exec_mode : 'fork',
max_memory_restart : '1G',
cwd: 'src/main',
error: '../../logs/Stable/error.err',
output: '../../logs/Stable/output.log',
pid: '../../logs/Stable/pid.pid',
error: './logs/error.err',
output: './logs/output.log',
pid: './logs/pid.pid',
node_args: '-r esm',
autorestart: true,
wait_ready: true,
Expand Down
22 changes: 22 additions & 0 deletions src/Bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

import WebSpell from './WebSpell';

import config from './configs/customConf.json';
import tokenConf from './configs/tokenConf.json';

const Bot = new WebSpell(
tokenConf.bot.token,
{
autoreconnect: true,
defaultImageFormat: 'png',
defaultImageSize: 512,
disableEveryone: true,
getAllUsers: true,
messageLimit: 100,
restMode: true
},
config
);

export default Bot;
46 changes: 46 additions & 0 deletions src/WebSpell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

import AxonClient from 'axoncore';

import * as modules from './modules/index';

/**
* Example - Client constructor
*
* @author KhaaZ
*
* @class Client
* @extends {AxonCore.AxonClient}
*/
class WebSpell extends AxonClient {
constructor(token, options, config) {
super(token, options, config, modules);

}

initStaff() {
this.staff.manager = [];
}

/** CURRENTLY DISABLED */
$init() {
return new Promise((resolve, reject) => {
try {
resolve(true);
} catch (err) {
reject(err);
}
});
}

/** CURRENTLY DISABLED */
$initStatus() {
this.editStatus(null, {
name: `webSPELL | ${this.params.prefix[0]}help`,
type: 0
});
}

}

export default WebSpell;
28 changes: 28 additions & 0 deletions src/configs/customConf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"general": {
"name": "webSPELL",
"description": "webSPELL - RSS news and others (webSPELL network)"
},

"prefix": {
"general": "//",
"owner": "!!",
"admin": "e."
},

"ids": {
"owners": ["179908288337412096"],
"admins": ["179908288337412096", "205439821236142082"]
},

"configPath": {
"general": "/home/khaaz/GIT/webSPELL/src/configs/generalConf.json",
"template": "/home/khaaz/GIT/webSPELL/src/configs/templateConf.json",
"tokens": "/home/khaaz/GIT/webSPELL/src/configs/tokenConf.json"
},

"debugMode": false,

"customLogger": true,
"customDB": true
}
32 changes: 32 additions & 0 deletions src/configs/generalConf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "Axon",
"description": "AxonCore - Bot client, core module (eris lib)",
"avatar": "url",

"version": "1.0",
"lib": "eris",
"client": "Axon",

"links": {
"website": "",
"invite": "",
"invitePermission": "",
"server": "",

"github": "https://github.com/khaazz/AxonCore",
"trello": "",
"sentry": ""
},


"owners": {
"khaaz": {
"name": "KhaaZ#0001",
"id": "179908288337412096"
},
"example": {
"name": "example#1234",
"id": "123456789"
}
}
}
27 changes: 27 additions & 0 deletions src/configs/templateConf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"embed": {
"colors": {
"help": "",
"global": 4315874,
"error": 15844367
}
},

"emote": {
"error": "<:error:426906693624922113>",
"success": "<:success:426906630463160330>",
"loading": "<a:loading:397911964988342282>",
"update": "<:update:373546418952077323>",
"info": ":information_source:"
},

"message": {
"error": {
"permBot": "I don't have sufficient permissions to do that!",
"permSource": "You don't have sufficient permissions to do that!",
"permDest": "This user is a mod/admin, I can't do that!",
"cooldown": "Please, slow down!",
"general": "An unexpected error occured! Contact Bot developers."
}
}
}
42 changes: 42 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import Bot from './Bot';

// packages
import mongoose from 'mongoose';

try {
mongoose.connect('mongodb://localhost/webSpellDB');
Bot.Logger.notice('Connected to webSpell DataBase.');
} catch (e) {
Bot.Logger.emerg('Could NOT connect to webSpell DataBase.\n' + e.stack);
}

// User ned to Deal with error listener by himself
// where to log etc
// Error Listeners
process.on('uncaughtException', (err) => {
Bot.Logger.emerg(err.stack);

Bot.emit('error', err);

process.exit(1);
});

process.on('unhandledRejection', (err) => {
Bot.Logger.error(err.stack);

Bot.emit('error', err);

});

Bot.on('error', (err) => {
Bot.Logger.error(err.stack);
});

Bot.on('warn', (msg) => {
Bot.Logger.warn(msg);
});

// Connection
Bot.connect();

Bot.Logger.notice('=== ONLINE ===');
Empty file removed src/main/.gitkeep
Empty file.
Empty file removed src/modules/.gitkeep
Empty file.
46 changes: 46 additions & 0 deletions src/modules/Core/commands/Ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

import { Command } from 'axoncore';

import Pong from './Ping_Pong';

class Ping extends Command {

constructor(module) {
super(module);

this.label = 'ping';
this.aliases = ['ping'];

this.hasSubcmd = true;
this.subcmds = [Pong];

this.infos = {
owner: ['KhaaZ'],
cmdName: 'ping',
description: 'Ping the bot.',
examples: ['ping'],
arguments: []
};

this.options.argsMin = 0;
this.options.cooldown = 3000;
this.options.guildOnly = false;
}

async execute({ msg }) {
const start = Date.now();

const mess = await this.sendMessage(msg.channel, 'Pong! ');

if (!mess) {
return;
}

const diff = (Date.now() - start);

return this.editMessage(mess, `Pong! \`${diff}ms\``);
}
}

export default Ping;
43 changes: 43 additions & 0 deletions src/modules/Core/commands/Ping_Pong.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

import { Command } from 'axoncore';

class Pong extends Command {

constructor(module) {
super(module);

this.label = 'pong';
this.aliases = ['pong'];

this.isSubcmd = true;
this.hasSubcmd = false;

this.infos = {
owner: ['KhaaZ'],
cmdName: 'ping pong',
description: 'Pong the bot.',
examples: ['ping pong'],
arguments: []
};

this.options.argsMin = 0;
this.options.cooldown = 3000;
this.options.guildOnly = false;
}

async execute({ msg }) {
const start = Date.now();

const mess = await this.sendMessage(msg.channel, 'BADABOUM!');
if (!mess) {
return;
}

const diff = (Date.now() - start);

return this.editMessage(mess, `BADABOUM! \`${diff}ms\``);
}
}

export default Pong;
1 change: 1 addition & 0 deletions src/modules/Core/commands/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Ping } from './Ping';
File renamed without changes.
Loading

0 comments on commit 0e24bf3

Please sign in to comment.