-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
82 lines (71 loc) · 1.87 KB
/
index.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
const fs = require('fs')
const Discord = require('discord.js')
const config = require('./config.json')
const client = new Discord.Client()
const chokidar = require('chokidar')
const watcher = chokidar.watch('./audios', {
ignored: /^\./,
ignoreInitial: true,
persistent: true,
awaitWriteFinish: true
})
function check() {
const fileListed = []
fs.readdirSync('./audios').forEach((file) => {
if (
file.includes('.mp3') ||
file.includes('.m4a') ||
file.includes('.ogg')
) {
fileListed[file.split('.')[0]] = file
}
})
return fileListed
}
let fileList = check()
watcher.on('add', function (path) {
fileList = check()
console.log('fileList has been updated with ' + path)
})
client.on('ready', () => {
console.log(`Logged in as ${client.user.username}!`)
})
client.on('message', async (msg) => {
if (msg.author === client.user) {
return
}
if (msg.content === 'help') {
let msgOut = 'Comandi disponibili: \n'
for (const key in fileList) {
msgOut += key + '\n'
}
msg.channel.send(msgOut)
}
if (msg.content === 'testtutto') {
let msgOut = 'Comandi disponibili: \n'
for (const key in fileList) {
msgOut += key + ' '
}
msg.channel.send(msgOut)
}
const split = msg.content.split(' ')
for (let index = 0; index < split.length; index++) {
const item = split[index]
await new Promise(async (resolve) => {
if (fileList[item] !== undefined) {
const connection = await msg.member.voice.channel.join()
const dispatcher = connection.play(
require('path').join(__dirname, '/audios/' + fileList[item])
)
dispatcher.on('finish', async () => {
dispatcher.destroy()
if (index === split.length - 1) {
connection.disconnect()
}
resolve()
})
}
})
}
})
client.login(config.TOKEN)