Database and music fix

- swiched back to ytdl-core for youtube playback
- fixed music skip being stuck sometimes
- removed database release call on pooled client
pull/97/head
Trivernis 5 years ago
parent 467d28fb64
commit 35107dafbc

@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- bug on`AnilistApi` where the `.gql` files couldn't be found.
- Typo in changelog
- bug on `~np` message that causes the player to crash
- database handler using release on pooled client
### Changed
- name of MiscCommands module from `TemplateCommandModule` to `MiscCommandModule`
@ -22,7 +23,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- all hard coded sql statements to generic sql generation
- MusicPlayer to extend the default EventEmitter
- MessageHandler to accept instances of Response and redirect events to it
- switched to `ytdl-core-discord` for youtube audio playback
### Added
- Utility classes for generic SQL Statements

@ -322,7 +322,6 @@ class MusicCommandModule extends cmdLib.CommandModule {
})
);
/* TODO: Delete completely on release
let volume = new cmdLib.Command(
this.template.volume,
new cmdLib.Answer(async (m, k) => {
@ -336,7 +335,7 @@ class MusicCommandModule extends cmdLib.CommandModule {
return this.template.volume.response.invalid;
}
})
);*/
);
let quality = new cmdLib.Command(
this.template.quality,
@ -370,6 +369,7 @@ class MusicCommandModule extends cmdLib.CommandModule {
.registerCommand(saveMedia)
.registerCommand(deleteMedia)
.registerCommand(savedMedia)
.registerCommand(volume)
.registerCommand(quality);
}
}

@ -145,7 +145,7 @@ class Database {
* Run a sql statement with seperate values and all result rows as return.
* @param sql {String} - the sql statement with escaped values ($1, $2... for postgres, ? for sqlite)
* @param [values] {Array<String|Number>} - the seperate values
* @returns {Promise<void>}
* @returns {Promise<any>}
*/
async all(sql, values) {
this._logger.debug(`Running SQL "${sql}" with values ${values}`);
@ -166,8 +166,6 @@ class Database {
close() {
if (this._dbType === 'sqlite')
this.database.close();
else if (this._dbType === 'postgresql')
this.database.release();
}
}

@ -1,10 +1,6 @@
const music = require('../music'),
utils = require('../utils'),
config = require('../../config.json'),
dblib = require('../database'),
logging = require('../utils/logging'),
fs = require('fs-extra'),
dataDir = config.dataPath || './data';
logging = require('../utils/logging');
/**
* GuildDatabase class has abstraction for some sql statements.
@ -156,6 +152,7 @@ class GuildHandler {
*/
async applySettings() {
this.settings = await this.db.getSettings();
this.musicPlayer.setVolume(Number(this.settings.musicPlayerVolume) || 0.5);
this.musicPlayer.quality = this.settings.musicPlayerQuality || 'lowest';
}

@ -1,4 +1,4 @@
const ytdl = require("ytdl-core-discord"),
const ytdl = require("ytdl-core"),
ypi = require('youtube-playlist-info'),
yttl = require('get-youtube-title'),
config = require('../../config.json'),
@ -24,6 +24,7 @@ class MusicPlayer extends xevents.ExtendedEventEmitter {
this.playing = false;
this.current = null;
this.repeat = false;
this.volume = 0.5;
this.voiceChannel = voiceChannel;
this.exitTimeout = null;
this._logger = new logging.Logger(this);
@ -188,8 +189,8 @@ class MusicPlayer extends xevents.ExtendedEventEmitter {
}
};
try {
this.disp = this.conn.playOpusStream(await ytdl(url,
{filter: 'audioonly', quality: this.quality, liveBuffer: this.liveBuffer}));
this.disp = this.conn.playStream(await ytdl(url,
{filter: 'audioonly', quality: this.quality, liveBuffer: this.liveBuffer}, {volume: this.volume}));
this.disp.on('error', (err) => {
this._logger.error(err.message);
this._logger.debug(err.stack);
@ -232,6 +233,17 @@ class MusicPlayer extends xevents.ExtendedEventEmitter {
});
}
/**
* Sets the volume of the dispatcher to the given value
* @param percentage {Number}
*/
setVolume(percentage) {
this._logger.verbose(`Setting volume to ${percentage}`);
this.volume = percentage;
if (this.disp !== null)
this.disp.setVolume(percentage);
}
/**
* Pauses if a dispatcher exists
*/
@ -295,7 +307,9 @@ class MusicPlayer extends xevents.ExtendedEventEmitter {
skip() {
this._logger.debug("Skipping song");
if (this.disp !== null) {
this.disp.end();
let disp = this.disp;
this.disp = null;
disp.end();
} else {
this.playing = false;
if (this.queue.length > 0) {

@ -12,7 +12,7 @@
"compression": "1.7.4",
"connect-sqlite3": "0.9.11",
"cors": "2.8.5",
"discord.js": "11.4.2",
"discord.js": "^11.5.1",
"express": "4.16.4",
"express-compile-sass": "4.0.0",
"express-graphql": "0.8.0",
@ -23,17 +23,19 @@
"graphql": "14.2.1",
"js-md5": "0.7.3",
"js-sha512": "0.8.0",
"js-yaml": "latest",
"node-fetch": "2.3.0",
"node-opus": "0.3.1",
"js-yaml": "^3.13.1",
"node-fetch": "^2.6.0",
"node-gyp": "^6.0.0",
"node-opus": "^0.3.2",
"node-sass": "4.11.0",
"pg": "^7.8.2",
"pg": "^7.12.1",
"promise-waterfall": "0.1.0",
"pug": "2.0.3",
"sqlite3": "4.0.6",
"winston": "3.2.1",
"winston-daily-rotate-file": "3.8.0",
"youtube-playlist-info": "1.1.2",
"ytdl-core": "^1.0.0",
"ytdl-core-discord": "^1.0.3"
},
"devDependencies": {

Loading…
Cancel
Save