File size: 2,667 Bytes
597ee18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const config = require('./config/default.json');
const Discord = require("discord.js");
const client = new Discord.Client();
var fs = require('fs');

var version = '2.1';
var files = fs.readdirSync('./sound');
var defaultVoiceChannel = config.defaultVoiceChannel;
var allowDefaultVoice = true;
client.login(config.token); 

client.on("message", msg => 
{
	if (msg.content.startsWith("!"))
	{
		var command = msg.content.toLowerCase();
		if (files.includes(command.substring(1) + '.mp3'))
		{
			playSound(`sound/` + command.substring(1) + `.mp3`, msg);
		}
		else
		{
			switch (command)
			{
				case ("!helpbot"):
					listCommands(msg);
					break;
				case ("!listaudio"):
					msg.channel.sendMessage('Available files: ' + files.toString());
					break;
				default:
					//msg.channel.sendMessage('Not a command...  Try !HelpBot');
			}
		}
	}
});

client.on('ready', () => 
{
	console.log('Rileys Sound v' + version + ' Bot is Running!');
});

function playSound(file, msg) 
{
	var voiceChannel = msg.member.voiceChannel;
	if (voiceChannel == undefined)
	{
		if (allowDefaultVoice == false)
		{
			msg.channel.sendMessage("Join a voice channel!");
			return;
		}
		else
			voiceChannel = client.channels.get(defaultVoiceChannel)		
	}
	
	voiceChannel.join().then((connection) => 
	{
		const dispatcher = connection.playFile(file);
		dispatcher.on('end', () => 
		{
			connection.disconnect();
		});
	}).catch((error) => 
	{
		console.log('Error occured!');
		console.log(error);
	});
}

function listCommands(msg) {
	const message = [
	'```',
	'Riley\'s Sound Bot v' + version,
	' ',
	'- Commands -',
	'!HelpBot      --- Show this message',
	'!ListAudio      --- List all available audio files.',
	' ',
	'- Generic Audio -',
	'!Allahu Akbar   --- Play "ALLAHU AKBAR!" sound',
	'!TerroristsWin  --- Play CS GO "Terrorists Win" sound',
	' ',
	'- Nick Audio Expansion Pack With Bonus Kody Sound File -',
	'!Genius         --- Play "Genius!" sound.  Audio courtesy of Nick',
	'!ProveIt        --- Play "Prove It!" sound.  Audio courtesy of Nick',
	'!UmmmNo         --- Play "Ummmm no?!?!?" sound.  Audio courtesy of Nick',
	'!NotToday       --- Play "Not today!" sound.  Audio courtesy of Nick',
	'!Now            --- Play "Now!" sound.  Audio courtesy of Nick',
	'!Illegal        --- Play "He\'s an illegal" sound.  Audio courtesy of Nick',
	'!WhoRYou        --- Play "Who are you?" sound.  Audio courtesy of Nick',
	' ',
	'- President Trump Audio Expansion Pack -',
	'!Wrong			--- Play Donald Trump saying "Wrong".',
	'```'
	];
	msg.channel.sendMessage(message);
}