This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
util.js
43 lines (39 loc) · 1.52 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Currently just a dump of everything that doesn't belong to other files
// TODO need to move to appropriate sections or files.
const ytdl = require('ytdl-core');
const {initial_audio_src} = require('../config/config.json');
function createCommand(name, description, func)
{
return {name: name, description: description, execute: func};
}
function fixVoiceReceive(connection)
{
// Play something to send a opcode 5 payload (apparently a requirement that was not documented)
// https://github.com/discord/discord-api-docs/issues/808
const dispatcher = connection.play(ytdl(initial_audio_src,
{filter: "audioonly", range: {start: 0, end: 2500}}));
dispatcher.on("error", (err) => console.log(err));
dispatcher.on("start", () => console.log(`Guild ${connection.channel.guild.id}: Starting initial audio for payload request`));
dispatcher.on("finish", () =>
{
console.log(`Guild ${connection.channel.guild.id}: Finished the initial audio`);
dispatcher.destroy();
});
return dispatcher;
}
function createVoiceConnectionData(connection,
VoiceRecognition,
user,
textChannel)
{
return {
connection: connection,
textChannel: textChannel,
voiceRecognition: VoiceRecognition,
listeningTo: user,
dispatcher: undefined,
queue: [],
playing: undefined
};
}
module.exports = {createCommand, fixVoiceReceive, createVoiceConnectionData};