Update bot to new discord API and add simple chatgpt module
This commit is contained in:
@@ -1,28 +1,32 @@
|
||||
module.exports = class AudioQueue {
|
||||
constructor(connection) {
|
||||
this.connection = connection;
|
||||
this.queue = [];
|
||||
this.current = undefined;
|
||||
}
|
||||
playNext() {
|
||||
if (this.queue.length == 0) {
|
||||
this.current = undefined;
|
||||
return;
|
||||
}
|
||||
this.current = this.connection.play(this.queue[0]);
|
||||
this.current.on('speaking', (val) => {if (val == 0) this.handleStop(this.current)});
|
||||
}
|
||||
handleStop(current) {
|
||||
this.queue.shift();
|
||||
this.playNext();
|
||||
}
|
||||
add(element) {
|
||||
this.queue.push(element);
|
||||
if (this.queue.length == 1) this.playNext();
|
||||
}
|
||||
flush() {
|
||||
this.current.setVolume(0);
|
||||
this.queue=[];
|
||||
this.playNext();
|
||||
}
|
||||
const Voice = require("@discordjs/voice");
|
||||
|
||||
module.exports = class AudioQueue {
|
||||
constructor(connection, api) {
|
||||
this.connection = connection;
|
||||
this.api = api;
|
||||
this.queue = [];
|
||||
this.current = undefined;
|
||||
}
|
||||
playNext() {
|
||||
if (this.queue.length == 0) {
|
||||
this.current = undefined;
|
||||
return;
|
||||
}
|
||||
this.current = this.api.play(this.queue[0]);
|
||||
this.api.player.on(Voice.AudioPlayerStatus.Idle, this.handleStop.bind(this));
|
||||
}
|
||||
handleStop(current) {
|
||||
console.log(`Handling stop`);
|
||||
this.queue.shift();
|
||||
this.playNext();
|
||||
}
|
||||
add(element) {
|
||||
this.queue.push(element);
|
||||
if (this.queue.length == 1) this.playNext();
|
||||
}
|
||||
flush() {
|
||||
this.current.setVolume(0);
|
||||
this.queue=[];
|
||||
this.playNext();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user