forked from rowisahub/PodcastBotWIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PodC.js
150 lines (112 loc) · 3.95 KB
/
PodC.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
const Discord = require('discord.js');
const { Readable, PassThrough } = require('stream');
const Stream = require('stream');
const mergeStream = require('merge-stream');
// var VideoStreamMerger = require('video-stream-merger');
const fs = require('fs');
const client = new Discord.Client();
client.once('ready', async() => {
console.log(`Logged in as ${client.user.tag}`);
});
const prefix = '.'
// client.on('voiceStateUpdate', async(oldState, newState) =>{
// })
const SILENCE_FRAME = Buffer.from([0xF8, 0xFF, 0xFE]);
class Silence extends Readable {
_read() {
this.push(SILENCE_FRAME);
this.destroy();
}
}
var SEND;
var RESV;
client.on('message', async(message,member) => {
// console.log(SEND.receiver.packets)
let args = message.content.slice(prefix.length).trim().split(' ');
let cmd = args.shift().toLowerCase();
if (message.author.bot) return;
if(cmd==='on'){
const member = message.member;
if (!member) {
return;
}
if (!member.voice.channel) {
await message.reply(`you're not in a voice channel`);
return;
}
const SNchannel = await client.channels.cache.get("805868781033095218");
if (!SNchannel) return console.error("The channel does not exist!");
await SNchannel.join().then(connection => {
console.log("Successfully connected to VC!");
SEND = connection;
}).catch(e => {
console.error(e);
});
RESV = await message.member.voice.channel.join();
RESV.play(new Silence(), { type: 'opus' });
RESV.voice.setSelfDeaf(false);
// const mergedStreams = concatStreams([stream1, stream2, stream3]);
// Temp
// var stream2 = new Stream();
// // Temp
// var stream1 = new Stream();
// var merged = mergeStream(stream1, stream2);
// var streams = [stream1];
// let joined = streams.reduce((pt, s, i, a) => {
// s.pipe(pt, {end: false})
// s.once('end', () => a.every(s => s.ended) && pt.emit('end'))
// return pt
// }, new PassThrough())
// merger.addStream(screenStream)
// var asd = []
RESV.on('speaking', async (user, speaking) => {
// console.log(speaking.bitfield)
// console.log(`User ${user.username} is speaking!`)
if(user.id===client.user.id) return
// var curS = RESV.receiver.createStream(user, { mode: 'opus' });
// // merger.addStream(curS);
// // audioStream = RESV.receiver.createStream(user, { mode: 'opus' });
// const reS = SEND.play(curS, { type: 'opus' })
// reS.on('error', console.error);
if(speaking.bitfield===1){
console.log(`User ${user.username} is speaking!`)
var curS = RESV.receiver.createStream(user, { mode: 'opus' });
// curS.id = user.id;
// asd.push(curS)
// merger.addStream(curS);
// audioStream = RESV.receiver.createStream(user, { mode: 'opus' });
const reS = SEND.play(curS, { type: 'opus' })
reS.on('error', console.error);
// console.log(asd)
}else if(speaking.bitfield===0){
console.log(`User ${user.username} stopped speaking`)
// for(var i = 0; i < asd.length; i++){
// if(asd[i].id===user.id){
// asd.splice(i, 1)
// }
// }
// console.log(asd)
}
})
// const reS = SEND.play(merger.result, { type: 'opus' });
// reS.on('error', console.error);
// const audio = connection.receiver.createStream(message.member.id, { mode: 'opus' });
// audio.pipe(fs.createWriteStream('user_audio'));
}else if(cmd==='off'){
const member = message.member;
if (!member) {
return;
}
if (!member.voice.channel) {
await message.reply(`you're not in a voice channel`);
return;
}
if(!RESV) return message.channel.send('No resive found');
if(!SEND) return message.channel.send('No send found');
RESV.disconnect();
SEND.disconnect();
console.log("Successfully disconnected from VC!");
}
// val.voice_Channel.leave()
})
client.login("");