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. - bug on`AnilistApi` where the `.gql` files couldn't be found.
- Typo in changelog - Typo in changelog
- bug on `~np` message that causes the player to crash - bug on `~np` message that causes the player to crash
- database handler using release on pooled client
### Changed ### Changed
- name of MiscCommands module from `TemplateCommandModule` to `MiscCommandModule` - 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 - all hard coded sql statements to generic sql generation
- MusicPlayer to extend the default EventEmitter - MusicPlayer to extend the default EventEmitter
- MessageHandler to accept instances of Response and redirect events to it - MessageHandler to accept instances of Response and redirect events to it
- switched to `ytdl-core-discord` for youtube audio playback
### Added ### Added
- Utility classes for generic SQL Statements - 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( let volume = new cmdLib.Command(
this.template.volume, this.template.volume,
new cmdLib.Answer(async (m, k) => { new cmdLib.Answer(async (m, k) => {
@ -336,7 +335,7 @@ class MusicCommandModule extends cmdLib.CommandModule {
return this.template.volume.response.invalid; return this.template.volume.response.invalid;
} }
}) })
);*/ );
let quality = new cmdLib.Command( let quality = new cmdLib.Command(
this.template.quality, this.template.quality,
@ -370,6 +369,7 @@ class MusicCommandModule extends cmdLib.CommandModule {
.registerCommand(saveMedia) .registerCommand(saveMedia)
.registerCommand(deleteMedia) .registerCommand(deleteMedia)
.registerCommand(savedMedia) .registerCommand(savedMedia)
.registerCommand(volume)
.registerCommand(quality); .registerCommand(quality);
} }
} }

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

@ -1,10 +1,6 @@
const music = require('../music'), const music = require('../music'),
utils = require('../utils'),
config = require('../../config.json'),
dblib = require('../database'), dblib = require('../database'),
logging = require('../utils/logging'), logging = require('../utils/logging');
fs = require('fs-extra'),
dataDir = config.dataPath || './data';
/** /**
* GuildDatabase class has abstraction for some sql statements. * GuildDatabase class has abstraction for some sql statements.
@ -156,6 +152,7 @@ class GuildHandler {
*/ */
async applySettings() { async applySettings() {
this.settings = await this.db.getSettings(); this.settings = await this.db.getSettings();
this.musicPlayer.setVolume(Number(this.settings.musicPlayerVolume) || 0.5);
this.musicPlayer.quality = this.settings.musicPlayerQuality || 'lowest'; 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'), ypi = require('youtube-playlist-info'),
yttl = require('get-youtube-title'), yttl = require('get-youtube-title'),
config = require('../../config.json'), config = require('../../config.json'),
@ -24,6 +24,7 @@ class MusicPlayer extends xevents.ExtendedEventEmitter {
this.playing = false; this.playing = false;
this.current = null; this.current = null;
this.repeat = false; this.repeat = false;
this.volume = 0.5;
this.voiceChannel = voiceChannel; this.voiceChannel = voiceChannel;
this.exitTimeout = null; this.exitTimeout = null;
this._logger = new logging.Logger(this); this._logger = new logging.Logger(this);
@ -188,8 +189,8 @@ class MusicPlayer extends xevents.ExtendedEventEmitter {
} }
}; };
try { try {
this.disp = this.conn.playOpusStream(await ytdl(url, this.disp = this.conn.playStream(await ytdl(url,
{filter: 'audioonly', quality: this.quality, liveBuffer: this.liveBuffer})); {filter: 'audioonly', quality: this.quality, liveBuffer: this.liveBuffer}, {volume: this.volume}));
this.disp.on('error', (err) => { this.disp.on('error', (err) => {
this._logger.error(err.message); this._logger.error(err.message);
this._logger.debug(err.stack); 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 * Pauses if a dispatcher exists
*/ */
@ -295,7 +307,9 @@ class MusicPlayer extends xevents.ExtendedEventEmitter {
skip() { skip() {
this._logger.debug("Skipping song"); this._logger.debug("Skipping song");
if (this.disp !== null) { if (this.disp !== null) {
this.disp.end(); let disp = this.disp;
this.disp = null;
disp.end();
} else { } else {
this.playing = false; this.playing = false;
if (this.queue.length > 0) { if (this.queue.length > 0) {

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

Loading…
Cancel
Save