Changes to structure and fixes

- added folders for every lib
- moved lib files to folders and renamed them to `index.js`
- moved commands outside of lib
- moved graphql schema to web
- removed lib graphql folder
- added graphql folder to AniListApi folder
- fixed bug on ~skip and ~stop
- fixed bug on ExtendedRichEmbed
- fixed bug on RichCharacterInfo
feature/api-rewrite
Trivernis 6 years ago
parent 2a2386e545
commit 540ab231db

@ -5,8 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Fixed
- bug where the bot counts itself when calculating needed votes to skip/stop music
- bug on the `ExtendedRichEmbed` where `addField` and `setDescription` throws an error when the value is null or undefined
- bug on `AnilistApiCommands` where the `RichCharacterInfo` uses a nonexistent function of the `ExtendedRichEmbed`
### Changed
- name of MiscCommands module from `TemplateCommandModule` to `MiscoCommandModule`
- moved everything in `lib` to subfolders with the same name as the files and renamed the files to `index.js`
- moved commands outside of `lib`
## [0.11.0-beta] - 2019-03-03
### Changed

@ -1,12 +1,12 @@
const Discord = require("discord.js"),
fs = require('fs-extra'),
logging = require('./lib/logging'),
logging = require('./lib/utils/logging'),
msgLib = require('./lib/MessageLib'),
guilding = require('./lib/guilding'),
utils = require('./lib/utils'),
config = require('./config.json'),
args = require('args-parser')(process.argv),
sqliteAsync = require('./lib/sqliteAsync'),
sqliteAsync = require('./lib/utils/sqliteAsync'),
authToken = args.token || config.api.botToken,
prefix = args.prefix || config.prefix || '~',
gamepresence = args.game || config.presence;
@ -69,24 +69,24 @@ class Bot {
if (config.webinterface && config.webinterface.enabled)
await this.initializeWebserver();
this.logger.verbose('Registering commands');
await this.messageHandler.registerCommandModule(require('./lib/commands/AnilistApiCommands').module, {});
await this.messageHandler.registerCommandModule(require('./lib/commands/UtilityCommands').module, {
await this.messageHandler.registerCommandModule(require('./commands/AnilistApiCommands').module, {});
await this.messageHandler.registerCommandModule(require('./commands/UtilityCommands').module, {
bot: this,
config: config
});
await this.messageHandler.registerCommandModule(require('./lib/commands/InfoCommands').module, {
await this.messageHandler.registerCommandModule(require('./commands/InfoCommands').module, {
client: this.client,
messageHandler: this.messageHandler
});
await this.messageHandler.registerCommandModule(require('./lib/commands/MusicCommands').module, {
await this.messageHandler.registerCommandModule(require('./commands/MusicCommands').module, {
getGuildHandler: async (g) => await this.getGuildHandler(g)
});
await this.messageHandler.registerCommandModule(require('./lib/commands/ServerUtilityCommands').module, {
await this.messageHandler.registerCommandModule(require('./commands/ServerUtilityCommands').module, {
getGuildHandler: async (g) => await this.getGuildHandler(g),
messageHandler: this.messageHandler,
config: config
});
await this.messageHandler.registerCommandModule(require('./lib/commands/MiscCommands').module, {});
await this.messageHandler.registerCommandModule(require('./commands/MiscCommands').module, {});
this.registerEvents();
}

@ -1,5 +1,5 @@
/* template index.js. Doesn't implement actual commands */
const cmdLib = require('../../CommandLib'); // required for command objects
const cmdLib = require('../../lib/CommandLib'); // required for command objects
/**
* A description what the command module includes and why. Doesn't need to list commands but explains

@ -1,5 +1,5 @@
const cmdLib = require('../../CommandLib'),
anilistApi = require('../../api/AnilistApi');
const cmdLib = require('../../lib/CommandLib'),
anilistApi = require('../../lib/api/AniListApi');
/**
* The AniList commands are all commands that interact with the anilist api.
@ -144,7 +144,7 @@ class RichCharacterInfo extends cmdLib.ExtendedRichEmbed {
.replace(/~!.*?!~/g, '')
.replace(/\n\n\n/g, ''));
if (characterInfo.media && characterInfo.media.edges)
this.addNonemptyField(
this.addField(
'Media Appeareance',
characterInfo.media.edges.map(x => {
let media = x.node;

@ -1,6 +1,6 @@
const cmdLib = require('../../CommandLib'),
const cmdLib = require('../../lib/CommandLib'),
fsx = require('fs-extra'),
utils = require('../../utils');
utils = require('../../lib/utils');
/**
* Info commands provide information about the bot. These informations are

@ -1,5 +1,5 @@
/* template index.js. Doesn't implement actual commands */
const cmdLib = require('../../CommandLib');
const cmdLib = require('../../lib/CommandLib');
/**
* Several commands that are that special that they can't be included in any other module.

@ -1,6 +1,6 @@
const cmdLib = require('../../CommandLib'),
utils = require('../../utils'),
config = require('../../../config');
const cmdLib = require('../../lib/CommandLib'),
utils = require('../../lib/utils'),
config = require('../../config');
function checkPermission(msg, rolePerm) {
if (!rolePerm || ['all', 'any', 'everyone'].includes(rolePerm))
@ -117,7 +117,7 @@ class MusicCommandModule extends cmdLib.CommandModule {
let vc = gh.musicPlayer.voiceChannel || m.member.voiceChannel;
if (gh.musicPlayer.connected && vc) {
let votes = gh.updateCommandVote(stop.name, m.author.tag);
let neededVotes = Math.ceil(vc.members.size/2);
let neededVotes = Math.ceil((vc.members.size - 1) / 2);
if (neededVotes <= votes.count || checkPermission(m, 'dj')) {
this._logger.debug(`Vote passed. ${votes.count} out of ${neededVotes} for stop or permission granted`);
@ -167,7 +167,7 @@ class MusicCommandModule extends cmdLib.CommandModule {
let vc = gh.musicPlayer.voiceChannel || m.member.voiceChannel;
if (gh.musicPlayer.playing && vc) {
let votes = gh.updateCommandVote(skip.name, m.author.tag);
let neededVotes = Math.ceil(vc.members.size/2);
let neededVotes = Math.ceil((vc.members.size - 1) / 2);
if (neededVotes <= votes.count || checkPermission(m, 'dj')) {
this._logger.debug(`Vote passed. ${votes.count} out of ${neededVotes} for skip or permission granted`);

@ -1,4 +1,4 @@
const cmdLib = require('../../CommandLib');
const cmdLib = require('../../lib/CommandLib');
/**
* This command module includes utility commands for the server.

@ -1,4 +1,4 @@
const cmdLib = require('../../CommandLib');
const cmdLib = require('../../lib/CommandLib');
/**
* Utility commands are all commands that allow the user to control the behaviour of the

@ -1,9 +1,9 @@
const Discord = require('discord.js'),
yaml = require('js-yaml'),
fsx = require('fs-extra'),
logging = require('./logging'),
config = require('../config.json'),
utils = require('./utils');
logging = require('../utils/logging'),
config = require('../../config.json'),
utils = require('../utils');
const scopes = {
'Global': 0,
@ -239,13 +239,16 @@ class ExtendedRichEmbed extends Discord.RichEmbed {
* @param value
*/
setDescription(value) {
let croppedValue = value;
if (value.substring)
croppedValue = value.substring(0, 1024);
if (croppedValue.length < value.length)
croppedValue = croppedValue.replace(/\n.*$/g, '');
if (croppedValue && croppedValue.replace(/\n/g, '').length > 0)
super.setDescription(croppedValue);
if (value) {
let croppedValue = value;
if (value.substring)
croppedValue = value.substring(0, 1024);
if (croppedValue.length < value.length && croppedValue.replace)
croppedValue = croppedValue.replace(/\n.*$/g, '');
if (croppedValue && croppedValue.replace
&& croppedValue.replace(/\n/g, '').length > 0)
super.setDescription(croppedValue);
}
return this;
}
@ -255,15 +258,16 @@ class ExtendedRichEmbed extends Discord.RichEmbed {
* @param value
*/
addField(name, value) {
let croppedValue = value;
if (value.substring)
croppedValue = value.substring(0, 1024);
if (croppedValue.length < value.length)
if (name && value) {
let croppedValue = value;
if (value.substring)
croppedValue = value.substring(0, 1024);
if (croppedValue && croppedValue.length < value.length && croppedValue.replace)
croppedValue = croppedValue.replace(/\n.*$/g, '');
if (name && croppedValue
&& croppedValue.replace(/\n/g, '').length > 0 && name.replace(/\n/g, '').length > 0)
super.addField(name, croppedValue);
if (croppedValue && croppedValue.replace
&& croppedValue.replace(/\n/g, '').length > 0 && name.replace(/\n/g, '').length > 0)
super.addField(name, croppedValue);
}
return this;
}
}

@ -1,7 +1,7 @@
const cmdLib = require('./CommandLib'),
config = require('../config.json'),
const cmdLib = require('../CommandLib'),
config = require('../../config.json'),
Discord = require('discord.js'),
logging = require('./logging'),
logging = require('../utils/logging'),
promiseWaterfall = require('promise-waterfall');
/* eslint no-useless-escape: 0 */

@ -1,9 +1,9 @@
const ytdl = require("ytdl-core"),
ypi = require('youtube-playlist-info'),
yttl = require('get-youtube-title'),
config = require('../config.json'),
utils = require('./utils.js'),
logging = require('./logging'),
config = require('../../config.json'),
utils = require('../utils/index.js'),
logging = require('../utils/logging'),
ytapiKey = config.api.youTubeApiKey;
/**

@ -0,0 +1,26 @@
class EventRouter {
constructor() {
}
/**
* Dispatches
* @param event
*/
dispatchEvent(event) {
}
/**
* Registeres discord client events to the EventRouter
* @param client
*/
registerClientEvents(client) {
}
}
class EventGroup

@ -4,21 +4,21 @@ const express = require('express'),
compression = require('compression'),
md5 = require('js-md5'),
sha512 = require('js-sha512'),
logging = require('./logging'),
logging = require('../utils/logging'),
fs = require('fs'),
session = require('express-session'),
SQLiteStore = require('connect-sqlite3')(session),
bodyParser = require('body-parser'),
compileSass = require('express-compile-sass'),
config = require('../config.json'),
utils = require('../lib/utils');
config = require('../../config.json'),
utils = require('../utils');
exports.WebServer = class {
constructor(port) {
this.app = express();
this.server = null;
this.port = port;
this.schema = buildSchema(fs.readFileSync('./lib/api/graphql/schema.gql', 'utf-8'));
this.schema = buildSchema(fs.readFileSync('./web/api/graphql/schema.gql', 'utf-8'));
this.root = {};
this._logger = new logging.Logger(this);
}

@ -1,8 +1,8 @@
const music = require('./MusicLib'),
utils = require('./utils'),
config = require('../config.json'),
sqliteAsync = require('./sqliteAsync'),
logging = require('./logging'),
sqliteAsync = require('./utils/sqliteAsync'),
logging = require('./utils/logging'),
fs = require('fs-extra'),
dataDir = config.dataPath || './data';

@ -13,7 +13,7 @@ mockobjects.mockLogger = {
};
describe('lib/utils', function() {
const utils = require('../lib/utils.js');
const utils = require('../lib/utils/index.js');
describe('#getSplitDuration', function() {
it('returns an object from milliseconds', function() {
@ -28,7 +28,7 @@ describe('lib/utils', function() {
it('returns the correct extension for a filename', function(done) {
assert(utils.getExtension('test.txt') === '.txt');
assert(utils.getExtension('test.tar.gz') === '.gz');
assert(utils.getExtension('../lib/utils.js') === '.js');
assert(utils.getExtension('../lib/index.js') === '.js');
assert(utils.getExtension('.gitignore') === '.gitignore');
done();
});

Loading…
Cancel
Save