Update bot to new discord API and add simple chatgpt module

This commit is contained in:
2023-03-21 13:35:28 +01:00
parent 136173f4de
commit b6008e0ad3
11 changed files with 6383 additions and 4183 deletions

View File

@@ -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();
}
}