Merge pull request #97 from Trivernis/develop

Resync of dependency-updates
pull/98/head
Trivernis 5 years ago committed by GitHub
commit be2cffe257
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -240,35 +240,6 @@ class Bot {
gh.musicPlayer.checkListeners(); gh.musicPlayer.checkListeners();
} }
}); });
this.client.on('message', async (msg) => {
try {
let sql = this.maindb.sql;
let server = null;
let channel = null;
let user = msg.author.tag;
let message = msg.content;
if (msg.guild) {
server = msg.guild.name;
channel = msg.channel.name;
await this.maindb.run(sql.insert('messages', {
server: sql.parameter(1),
channel: sql.parameter(2),
username: sql.parameter(3),
message: sql.parameter(4)
}), [server, channel, user, message]);
} else {
await this.maindb.run(sql.insert('messages', {
channel: sql.parameter(1),
username: sql.parameter(2),
message: sql.parameter(3)
}), ['PRIVATE', user, message]);
}
} catch (err) {
this.logger.warn(err.message);
this.logger.debug(err.stack);
}
});
} }
/** /**

@ -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);
@ -178,6 +179,7 @@ class MusicPlayer extends xevents.ExtendedEventEmitter {
this.queue.push(this.current); this.queue.push(this.current);
let toggleNext = () => { let toggleNext = () => {
if (this.queue.length > 0) { if (this.queue.length > 0) {
this.disp = null;
this.current = this.queue.shift(); this.current = this.queue.shift();
this.emit('next', this.current); this.emit('next', this.current);
this.playYouTube(this.current.url).catch((err) => this._logger.warn(err.message)); this.playYouTube(this.current.url).catch((err) => this._logger.warn(err.message));
@ -188,8 +190,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 +234,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 +308,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,6 +12,8 @@
"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.5.1",
"express": "4.16.4",
"discord.js": "11.5.1", "discord.js": "11.5.1",
"express": "4.17.1", "express": "4.17.1",
"express-compile-sass": "4.0.0", "express-compile-sass": "4.0.0",
@ -34,7 +36,7 @@
"winston": "3.2.1", "winston": "3.2.1",
"winston-daily-rotate-file": "4.2.1", "winston-daily-rotate-file": "4.2.1",
"youtube-playlist-info": "1.1.2", "youtube-playlist-info": "1.1.2",
"ytdl-core-discord": "1.0.3" "ytdl-core": "^1.0.0",
}, },
"devDependencies": { "devDependencies": {
"assert": "2.0.0", "assert": "2.0.0",

Loading…
Cancel
Save