Skip to content

feat: detritus support #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 13 commits into
base: dev
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# configs file
examples/eris/src/configs/tokenConfig.json
examples/djs/src/configs/tokenConfig.json
examples/detritus/src/configs/tokenConfig.json
examples/tokenConfig.json

# json db
src/Database/JSON/Database/*.json
examples/eris/src/Database/*.json
examples/djs/src/Database/*.json
examples/detritus/src/Database/*.json

# Logs
logs
Expand Down
30 changes: 30 additions & 0 deletions examples/detritus/scripts/start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const pm2 = require('pm2');

// Start process
console.log('>> Starting AxonCore');
pm2.connect( (err) => {
if (err) {
console.error(err);
process.exit(2);
}
pm2.start( {
script: 'index.js',
args: ['--color'],
name: 'AxonCore.detritus',
exec_mode: 'fork',
max_memory_restart: '1G',
cwd: 'examples/src',
error: '../logs/error.err',
output: '../../logs/output.log',
pid: '../../logs/pid.pid',
node_args: '-r esm',
autorestart: true,
wait_ready: true,
}, (e) => {
pm2.disconnect();
if (e) {
throw e;
}
} );
} );
//
56 changes: 56 additions & 0 deletions examples/detritus/src/Bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { ShardClient } from 'detritus-client';

import { AxonOptions } from 'axoncore';

import Client from './Client';

import botConfig from './configs/customConfig.json';
import tokenConfig from '../../tokenConfig.json';
import lang from './configs/lang.json';

import MyUtils from './MyUtils';

const axonOptions = new AxonOptions( {
prefixes: botConfig.prefixes,
settings: botConfig.settings,
lang,
logo: null,

info: botConfig.info,
staff: botConfig.staff,
template: botConfig.template,
custom: {
param: 1,
},
},
tokenConfig.webhooks,
{
utils: MyUtils, // use your own Utils
logger: null, // custom Logger
DBProvider: null, // custom DB Service
DBLocation: `${__dirname}/Database/`,

axonConfig: null,
guildConfig: null,
} );

/**
* new AxonClient(token, erisOptions, AxonOptions, modules)
*
* new Client(token, erisOptions, AxonOptions) => Modules imported in Client
*/
const client = new ShardClient(
tokenConfig.bot.token,
{
gateway: {
loadAllMembers: true,
},
},
);

const Bot = new Client(
client,
axonOptions,
);

export default Bot;
61 changes: 61 additions & 0 deletions examples/detritus/src/Client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { AxonClient } from 'axoncore';

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

/**
* Example - Client constructor
*
* @author KhaaZ
*
* @class Client
* @extends AxonCore.AxonClient
*/
class Client extends AxonClient {
constructor(client, axonOptions) {
super(client, axonOptions, modules);

this.param = 1; // personal stuff
this._param = 2; // personal hidden stuff
}

onInit() {
this.staff.contributors = [];
}

onStart() {
return Promise.resolve(true);
}

onReady() {
return Promise.resolve(true);
}

initStatus() {
// called after ready event
// overrides default editStatus
// used to setup custom status
this.botClient.gateway.setPresence( {
game: {
name: `AxonCore | ${this.settings.prefixes[0]}help`,
type: 0,
},
status: '',
} );
}

// disabled
// eslint-disable-next-line no-unused-vars
$sendFullHelp(msg, guildConfig) {
// override sendFullHelp method
return this.axonUtils.sendMessage(msg.channel, 'Full Help override');
}

// disabled
// eslint-disable-next-line no-unused-vars
$sendHelp(command, env) {
// override sendHelp method
return this.axonUtils.sendMessage(env.msg.channel, `Help override for ${command.label}`);
}
}

export default Client;
Empty file.
32 changes: 32 additions & 0 deletions examples/detritus/src/MyUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Utils } from 'axoncore';

class MyUtils extends Utils {
constructor(...args) {
super(...args);
this.invite = /^(discord.gg\/|discordapp.com\/invite\/)([a-z0-9]+)$/gi;
}

/**
* Convert a hex code into a rgb code
*
* @param {Number/String} float - The base10 number to convert OR the base10 number as a String
* @returns {String} rgb color code (xxx, xxx, xxx)
*/
hexTOrgb(hex) {
let num = hex.replace('#', '');
num = parseInt(num, 16);
return [num >> 16, num >> 8 & 255, num & 255]; // eslint-disable-line
}

/**
* Convert a rgb code into a hex code
*
* @param {Number/String} float - the rgb color code
* @returns {String} Hex color code (6 char) (without #)
*/
rgbTOhex(red, green, blue) {
return ((blue | green << 8 | red << 16) | 1 << 24).toString(16).slice(1); // eslint-disable-line
}
}

export default MyUtils;
65 changes: 65 additions & 0 deletions examples/detritus/src/configs/customConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"info": {
"name": "Axon",
"description": "AxonCore - Bot client, core module (eris lib)",
"version": "1.0.0",
"library": "detritus"
},

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

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

"prefixes": {
"general": "a!",
"owner": "!!",
"admin": "a."
},

"staff": {
"owners": [
{
"name": "KhaaZ#0001",
"id": "179908288337412096"
}
],
"admins": [
{
"name": "KhaaZ#0001",
"id": "179908288337412096"
}
]
},

"template": {
"embeds": {
"help": "ffffff",
"global": 4315874,
"error": 15844367
},

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

"settings": {
"lang": "english",
"debugMode": true,
"library": 2,
"logger": 1,
"db": 1,
"guildConfigCache": 1000
}
}
16 changes: 16 additions & 0 deletions examples/detritus/src/configs/lang.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"english": {
"ERR_BOT_PERM": "I don't have sufficient permissions to do that! I need: {{permissions}}",
"ERR_CALLER_PERM": "You don't have sufficient permissions to do that! You need: {{permissions}}",
"ERR_DESTINATION_PERM": "This user is a mod/admin, I can't do that!",
"ERR_COOLDOWN": "Please, slow down! Remaining time: **{{cooldown}}** sec...",
"ERR_GENERAL": "An unexpected error occured! Contact the bot developers."
},
"french": {
"ERR_BOT_PERM": "Je n'ai pas les permissions pour faire cela ! J'ai besoin de: {{permissions}}",
"ERR_CALLER_PERM": "Vous n'avez pas les permissions pour faire cela ! Vous avez besoin de: {{permissions}}",
"ERR_DESTINATION_PERM": "Cet utilisateur est un mod/admin, je ne peux pas faire ca !",
"ERR_COOLDOWN": "S'il vous plait, ralentissez ! Temps restant: **{{cooldown}}** sec...",
"ERR_GENERAL": "An unexpected error occured! Contact the bot developers."
}
}
24 changes: 24 additions & 0 deletions examples/detritus/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Bot from './Bot';
import customConf from './configs/customConfig.json';

if (customConf.db === 1) {
try {
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/AxonCoreDB', {
useCreateIndex: true,
autoReconnect: true,
} )
.then( () => {
Bot.logger.notice('Connected to AxonCore DataBase.');
} )
.catch(err => {
Bot.logger.fatal(`Could NOT connect to AxonCore DataBase.\n${err.stack}`);
} );
} catch (e) {
Bot.logger.fatal(`Could NOT connect to AxonCore DataBase.\n${e.stack}`);
}
}

Bot.start();

Bot.logger.notice('=== ONLINE ===');
50 changes: 50 additions & 0 deletions examples/detritus/src/modules/Core/commands/Ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Command, CommandOptions, CommandResponse } from 'axoncore';

import Pong from './Ping_Pong';

class Ping extends Command {
constructor(module) {
super(module);

this.label = 'ping';
this.aliases = [
'ping',
'pang',
'pung',
];

this.hasSubcmd = true;

this.info = {
owners: ['KhaaZ'],
name: 'ping',
description: 'Ping the bot.',
usage: 'ping',
examples: ['ping'],
};

this.options = new CommandOptions(this, {
argsMin: 0,
guildOnly: false,
} );
}

init() {
return [Pong];
}

async execute( { msg } ) {
const start = Date.now();
const mess = await this.sendMessage(msg.channel, 'Pong! ');
if (!mess) {
return new CommandResponse( { success: false } );
}

const diff = (Date.now() - start);
this.editMessage(mess, `Pong! \`${diff}ms\``);

return new CommandResponse( { success: true } );
}
}

export default Ping;
Loading