- Finalized ID conversion on Trusted Users and Authorized Guilds

- Removed console timestamp now that offical bot is running in systemd and logs to syslog (which does its own timestamp)
- Removed fs include for lack of use
- Refactored per-user special behavior to follow same code block formats

- Updated Intents requirements due to Discord API changes: https://support-dev.discord.com/hc/en-us/articles/4404772028055
This commit is contained in:
Robert 2021-12-11 21:02:55 -08:00
parent 31767fbfae
commit 11edee02fb

54
bot.js
View File

@ -1,13 +1,8 @@
// Include Discordjs library
// http://github.com/discordjs/
const { Client, VoiceChannel, Intents } = require('discord.js');
// Include console-stamp, so that calls to console.log automatically have our preferred timestamp on them
require('console-stamp')(console, 'yyyy/mm/dd HH:MM:ss.l');
// Include FileStream, for reading files
const fs = require('fs');
// Include ytdl, so we can play youtube videos over voice
const ytdl = require('ytdl-core-discord');
// Include our local auth key, so that we don't leak keys
const auth = require('./auth.json');
@ -16,16 +11,19 @@ const auth = require('./auth.json');
// Initialize a new Discord Client, and tell Discord what updates we are interested in recieving
// https://discord.com/developers/docs/topics/gateway#list-of-intents
const client = new Client({ intents: [Intents.FLAGS.GUILD_MESSAGES] });
const client = new Client({ intents: [Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS] });
// Define Sigtrap Callback, so that when the program is Ctrl-C'd it shuts down cleanly
process.on('SIGINT', () => {
console.log("\tCaught Interrupt Signal");
// Define Sigtrap Callback for clean shutdowns
function signalExit(signal) {
console.log("\tCaught ${signal}");
// Kills voice connections, and logs the client out
client.destroy();
// Exit with return code 0
process.exit(0);
});
}
// Subscribe to a few signal events
process.on('SIGINT', signalExit); // For Ctrl-C when running in a TTY
process.on('SIGTERM', signalExit); // for systemd's stoppping of services
// Define Several Discord Related Callbacks
@ -39,36 +37,41 @@ client.on('ready', () => { console.log(`Logged in as ${client.user.tag}!`); });
// https://discord.js.org/#/docs/main/v12/class/Message
client.on('message', async message => {
// Filter Section
// Ignore DMs (TODO: Recieve Sound Files from Trusted parties?)
// In the event of a DM...
if (message.guild == null) {
switch (message.author.id) {
case "262406433201586177": // Weegee
case "137358406821347328": // moosecrap
case "144317130026778624": // Piroglith
case "137293315883139072": // tks_ftw
case "137358406821347328": // moosecrap
case "172538370440953867": // Brightland
case "183009699300507648": // spamminn
case "209154502412992514": // NariNaju
case "198278682677084160": // DrunkZombie
case "137349560610586624": // craze
case "305491553198145539": // Sam
case "174356437550497792": // NoobWantsHacks
case "308412988329558017": // Revanite
// TODO: Recieve sound files from trusted parties?
return;
default:
console.log(`Ignoring DM from ${message.author.tag} ${message.author.id}: ${message.content}`);
console.log(`Ignoring DM from ${message.author.tag}: ${message.content}`);
return;
}
}
// Hard-coded Goldar Squad check (TODO: Change to guild.id after determining the IDs)
switch (message.guild.name) {
case "Goldar Squad":
case "ZeSkypeBot Incubator":
// Filter Authorized Guilds
switch (message.guild.id) {
case "860344888301846538": // ZeSkypeBot Incubator
case "305204527152365581": // Goldar Squad
break;
default:
console.log(`Message from Unauthorized Guild ${message.guild.name}!`);
return;
}
// Process Section
// Check for the shutup message
if (message.content === "~") {
console.log(`!stop issued by ${message.author.tag} ${message.author.id}`);
console.log(`!stop issued by ${message.author.tag}`);
if (!message.member.voice.channel) {
message.channel.send('you can\'t stop the party if you\'re not here');
} else {
@ -81,8 +84,12 @@ client.on('message', async message => {
// we had to add '/' because moose tried to 'play' ../../../../etc/shadow
// Construct the expected sound path
const soundPath = `./sounds/${message.content}.ogg`;
if (message.author.id === "172538370440953867" && message.content === "butthash" ) {
if (message.author.id === "172538370440953867") {
switch(message.content) {
case "butthash":
message.react('859687015247511561');
default:
}
}
if (message.author.id === "144317130026778624") {
switch(message.content) {
@ -96,7 +103,7 @@ client.on('message', async message => {
try {
// Test if there is a file at the expected path
if (fs.existsSync(soundPath) && message.member.voice.channel) {
console.log(`Sound ${message.content} issued by ${message.author.tag} ${message.author.id}`);
console.log(`Sound '${message.content}' issued by ${message.author.tag} ${message.author.id}`);
// Join the Voice Channel of the author
const connection = await message.member.voice.channel.join();
// TODO: Switch to fs-based file read?
@ -116,7 +123,7 @@ client.on('message', async message => {
// Otherwise process commands
if (message.content === "!help" ) {
console.log(`!help issued by ${message.author.tag} ${message.author.id}`);
var response = 'ZeSkypeBot v6.0.3 \'black pepper\'\n';
var response = 'ZeSkypeBot v6.0.4 \'black pepper\'\n';
response += 'Original by moosecrap#5953 for Skype, Remade by Weegee#6402 for Discord\n';
response += 'Changelog:\n';
response += 'v6.0.3 Changed !play regex per user feedback and counterexamples\n';
@ -159,7 +166,6 @@ client.on('message', async message => {
message.channel.send(response);
return;
}
});
// Now our client is prepared, we can log in. Callbacks defined previously
client.login(auth.token);