Rearranged code blocks to support future logic

This commit is contained in:
Robert 2023-09-23 17:13:40 -07:00
parent 3e7603412e
commit a40017f53e

127
bot.js Normal file → Executable file
View File

@ -31,7 +31,11 @@ client.on( Events.ClientReady, c => {
client.on( Events.MessageCreate, async message => { client.on( Events.MessageCreate, async message => {
// Variables that may be useful // Variables that may be useful
var d = new Date(); // Today's date and timestamp var d = new Date(); // Today's date and timestamp
// *** FIlter Section *** // *** FIlter Section ***
// Prevent any triggering if the message is our own
if( message.author.id === "860345552742907935" ) return;
// In the event of a DM... // In the event of a DM...
if (message.guild == null) { if (message.guild == null) {
switch (message.author.id) { switch (message.author.id) {
@ -65,6 +69,7 @@ client.on( Events.MessageCreate, async message => {
} }
// *** Process Section *** // *** Process Section ***
// Check for the shutup message // Check for the shutup message
if (message.content === "~") { if (message.content === "~") {
console.log(`!stop issued by ${message.author.tag}`); console.log(`!stop issued by ${message.author.tag}`);
@ -76,56 +81,6 @@ client.on( Events.MessageCreate, async message => {
} }
return; return;
} }
// Try to find a sound file that matches the message
if (!message.content.match(/[ \/;]/)) {
// we had to add '/' because moose tried to 'play' ../../../../etc/shadow
// Construct the expected sound path
const soundPath = '';
if( d.getMonth() == 3 && d.getDate() == 1 ) {
// TODO: april fools!
// Scan the directory as an array
// select randomly from the array
// play that sound instead
}
else soundPath = `./Sounds/${message.content}.ogg`;
if (message.author.id === "172538370440953867") {
switch(message.content) {
case "butthash":
message.react('859687015247511561');
default:
}
}
if (message.author.id === "144317130026778624") {
switch(message.content) {
case "daytona":
case "e":
if ([0,5,6].includes(d.getDay()) && Math.random() < 0.8) return;
default:
}
}
// Test if there is a file at the expected path
if (message.member.voice.channel && existsSync(soundPath)) {
console.log(`Sound '${message.content}' issued by ${message.author.tag} ${message.author.id}`);
// Join the Voice Channel of the author
const connection = Voice.joinVoiceChannel({
channelId: message.member.voice.channelId,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator,
});
// Create an audio player for the desired sound
const resource = Voice.createAudioResource(createReadStream(soundPath));
const player = Voice.createAudioPlayer();
// Play the resource through the player to the connection (i hate discord v16)
player.play(resource);
// Connect the player to the voice connection (internal screaming intensifies)
connection.subscribe(player);
return;
}
}
else {
// Somebody tried to escape characters or semicolon
message.channel.send('NO FUCK YOU');
}
// Check for youtube play command // Check for youtube play command
if (message.content.startsWith('!play') && message.member.voice.channel) { if (message.content.startsWith('!play') && message.member.voice.channel) {
console.log(`!play issued by ${message.author.tag} ${message.author.id}`); console.log(`!play issued by ${message.author.tag} ${message.author.id}`);
@ -178,7 +133,7 @@ client.on( Events.MessageCreate, async message => {
} }
if (message.content === "!help" ) { if (message.content === "!help" ) {
console.log(`!help issued by ${message.author.tag} ${message.author.id}`); console.log(`!help issued by ${message.author.tag} ${message.author.id}`);
var response = 'ZeSkypeBot v7.2.2 \'Angelica root\'\n'; var response = 'ZeSkypeBot v7.2.3 \'Angelica root\'\n';
response += 'Original by @moosecrap for Skype, Remade by @fredstonemason for Discord\n'; response += 'Original by @moosecrap for Skype, Remade by @fredstonemason for Discord\n';
response += 'Changelog:\n'; response += 'Changelog:\n';
response += 'v7.2.1 Added !echo to try and deduce why theres lag in commands\n'; response += 'v7.2.1 Added !echo to try and deduce why theres lag in commands\n';
@ -201,17 +156,6 @@ client.on( Events.MessageCreate, async message => {
message.channel.send(response); message.channel.send(response);
return; return;
} }
// Generic message responses
if (message.content.match(/https:\/\/ootbingo\.github\.io/)) {
var response = 'ooh its bingo time, i call ';
if (Math.floor(Math.random()*2)) { response += 'over'; }
else { response += 'under'; }
response += ' on gateskip';
message.channel.send(response);
return;
}
if (message.content === "!echo" ) { if (message.content === "!echo" ) {
var response = 'Debug Timers:\n```'; var response = 'Debug Timers:\n```';
response += `Discord Timestamp: ${message.createdAt.toISOString()}\n`; response += `Discord Timestamp: ${message.createdAt.toISOString()}\n`;
@ -223,7 +167,64 @@ client.on( Events.MessageCreate, async message => {
message.channel.send(response); message.channel.send(response);
return; return;
} }
// Generic message responses
if (message.content.match(/https:\/\/ootbingo\.github\.io/)) {
var response = 'ooh its bingo time, i call ';
if (Math.floor(Math.random()*2)) { response += 'over'; }
else { response += 'under'; }
response += ' on gateskip';
message.channel.send(response);
return;
}
// Try to find a sound file that matches the message
if (!message.content.match(/[ \/;]/)) {
// we had to add '/' because moose tried to 'play' ../../../../etc/shadow
// Construct the expected sound path
const soundPath = '';
if( d.getMonth() == 3 && d.getDate() == 1 ) {
// TODO: april fools!
// Scan the directory as an array
// select randomly from the array
// play that sound instead
}
else soundPath = `./Sounds/${message.content}.ogg`;
if (message.author.id === "172538370440953867") {
switch(message.content) {
case "butthash":
message.react('859687015247511561');
default:
}
}
if (message.author.id === "144317130026778624") {
switch(message.content) {
case "daytona":
case "e":
if ([0,5,6].includes(d.getDay()) && Math.random() < 0.8) return;
default:
}
}
// Test if there is a file at the expected path
if (message.member.voice.channel && existsSync(soundPath)) {
console.log(`Sound '${message.content}' issued by ${message.author.tag} ${message.author.id}`);
// Join the Voice Channel of the author
const connection = Voice.joinVoiceChannel({
channelId: message.member.voice.channelId,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator,
});
// Create an audio player for the desired sound
const resource = Voice.createAudioResource(createReadStream(soundPath));
const player = Voice.createAudioPlayer();
// Play the resource through the player to the connection (i hate discord v16)
player.play(resource);
// Connect the player to the voice connection (internal screaming intensifies)
connection.subscribe(player);
return;
}
} else {
//message.channel.send('NO FUCK YOU');
console.log(`user ${message.author.tag} used some bad characters: ${message.content}`);
}
}); });
// Now our client is prepared, we can log in. // Now our client is prepared, we can log in.
client.login(token); client.login(token);