Added Debug to assist with yt latency troubleshooting

This commit is contained in:
Robert 2023-08-30 19:10:57 -07:00
parent 55500fc439
commit 988707ed9c
2 changed files with 50 additions and 28 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
.env .env
config.json .data/*

76
bot.js
View File

@ -12,10 +12,13 @@ const client = new Client( { intents: [GatewayIntentBits.Guilds, GatewayIntentBi
// Define Sigtrap Callback for clean shutdowns // Define Sigtrap Callback for clean shutdowns
function signalExit(signal) { function signalExit(signal) {
console.log(`\tCaught ${signal}`); console.log(`\tCaught ${signal}`);
// Kills voice connections, and logs the client out // Signal via discord that we are closing
client.destroy(); client.channels.fetch("860393205401255936")
// Exit with return code 0 .then(papi => papi.send('bye bye papi') )
process.exit(0); // then disconnect
.then( client.destroy()
// and when that is done finally exit
.then( process.exit(0) ) );
} }
// Subscribe to a few signal events // Subscribe to a few signal events
process.on('SIGINT', signalExit); // For Ctrl-C when running in a TTY process.on('SIGINT', signalExit); // For Ctrl-C when running in a TTY
@ -24,8 +27,13 @@ process.on('SIGTERM', signalExit); // for systemd's stoppping of services
// Define Discord Callbacks // Define Discord Callbacks
client.on( Events.ClientReady, c => { client.on( Events.ClientReady, c => {
console.log(`Logged in Successfully as ${c.user.tag}`); console.log(`Logged in Successfully as ${c.user.tag}`);
// Signal via discord that we are alive
client.channels.fetch("860393205401255936")
.then( papi => papi.send('hello papi') );
}); });
client.on( Events.MessageCreate, async message => { client.on( Events.MessageCreate, async message => {
// Variables that may be useful
var d = new Date(); // Today's date and timestamp
// *** FIlter Section *** // *** FIlter Section ***
// In the event of a DM... // In the event of a DM...
if (message.guild == null) { if (message.guild == null) {
@ -60,8 +68,6 @@ client.on( Events.MessageCreate, async message => {
} }
// *** Process Section *** // *** Process Section ***
// Variables that may be useful
const d = new Date(); // Today's date and timestamp
// 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}`);
@ -123,10 +129,10 @@ client.on( Events.MessageCreate, async message => {
console.log(`ytmatch yields ${ytmatch[0]}`); console.log(`ytmatch yields ${ytmatch[0]}`);
// Message matches the youtube video regex, see if it comes with a timestamp // Message matches the youtube video regex, see if it comes with a timestamp
const timematch = message.content.match(/(?<=t=)(\d{1,4})s?(?=$)/); const timematch = message.content.match(/(?<=t=)(\d{1,4})s?(?=$)/);
if (timematch) { if (timematch) {
console.log(`timematch yields $timematch[1]`); console.log(`timematch yields $timematch[1]`);
timestamp = timematch[1]; timestamp = timematch[1];
} }
// Reconstruct a URL for the supplied video // Reconstruct a URL for the supplied video
yturl = `https://youtu.be/${ytmatch[0]}`; yturl = `https://youtu.be/${ytmatch[0]}`;
} else { } else {
@ -142,34 +148,37 @@ client.on( Events.MessageCreate, async message => {
} }
console.log(`yturl: ${yturl}`); console.log(`yturl: ${yturl}`);
// Create a stream reference to the provided URL // Create a stream reference to the provided URL
const stream = await play.stream(yturl, { seek: timestamp }); const stream = await play.stream(yturl, {
seek: timestamp
});
// Now that we have a stream reference we can join the channel and play // Now that we have a stream reference we can join the channel and play
const connection = Voice.joinVoiceChannel({ const connection = Voice.joinVoiceChannel({
channelId: message.member.voice.channel.id, channelId: message.member.voice.channel.id,
guildId: message.guild.id, guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator, adapterCreator: message.guild.voiceAdapterCreator,
}); });
// Open the stream as a voice resource // Open the stream as a voice resource
const resource = Voice.createAudioResource(stream.stream, { inputType: stream.type }); const resource = Voice.createAudioResource(stream.stream, { inputType: stream.type });
// Create a player to play the resource // Create a player to play the resource
const player = Voice.createAudioPlayer(); const player = Voice.createAudioPlayer();
// Play the resource through the player (i hate discord v16) // Play the resource through the player (i hate discord v16)
player.play(resource); player.play(resource);
// Connect the player to the voice connection (internal screaming intensifies) // Connect the player to the voice connection (internal screaming intensifies)
connection.subscribe(player); connection.subscribe(player);
// Setup Callbacks for when the player completes // Setup Callbacks for when the player completes
return; return;
} }
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.0 \'Table Salt\'\n'; var response = 'ZeSkypeBot v7.2.1 \'Table Salt\'\n';
response += 'Original by moosecrap#5953 for Skype, Remade by Weegee#6402 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.0 Attempts to fix seemingly random searches, now should support age-restricted videos\n'; response += 'v7.2.0 Attempts to fix seemingly random searches, now should support age-restricted videos\n';
response += 'v7.1.0 Added support for searching in !play\n' response += 'v7.1.0 Added support for searching in !play\n'
response += 'v7.0.0 Update to Discord.js 14\n'; response += 'v7.0.0 Update to Discord.js 14\n';
response += 'v6.1.0 Update to Discord.js 13, replaced ytdl-core-discord with play-dl\n'; response += 'v6.1.0 Update to Discord.js 13, replaced ytdl-core-discord with play-dl\n';
response += 'v6.0.6 Changes to !play regex in pursuit of playing at timestamps\n'; response += 'v6.0.6 Changes to !play regex in pursuit of playing at timestamps\n';
response += 'v6.0.5 Added feedback for cases where ytdl crashes\n'; response += 'v6.0.5 Added feedback for cases where ytdl crashes\n';
response += 'v6.0.3 Changed !play regex per user feedback and counterexamples\n'; response += 'v6.0.3 Changed !play regex per user feedback and counterexamples\n';
response += 'v6.0.2 Removed response to voiceless sound commands, for being too spammy\n'; response += 'v6.0.2 Removed response to voiceless sound commands, for being too spammy\n';
@ -184,7 +193,7 @@ client.on( Events.MessageCreate, async message => {
message.channel.send(response); message.channel.send(response);
return; return;
} }
// Generic message responses // Generic message responses
if (message.content.match(/https:\/\/ootbingo\.github\.io/)) { if (message.content.match(/https:\/\/ootbingo\.github\.io/)) {
var response = 'ooh its bingo time, i call '; var response = 'ooh its bingo time, i call ';
@ -194,6 +203,19 @@ client.on( Events.MessageCreate, async message => {
message.channel.send(response); message.channel.send(response);
return; return;
} }
if (message.content === "!echo" ) {
var response = 'Debug Timers:\n```';
response += `Discord Timestamp: ${message.createdAt.toISOString()}\n`;
response += `Local event start: ${d.toISOString()}\n`;
d = new Date();
response += `Local event now: ${d.toISOString()}\n`;
response += `Online Since: ${client.readyAt.toISOString()}\n`;
response += '```';
message.channel.send(response);
return;
}
}); });
// Now our client is prepared, we can log in. // Now our client is prepared, we can log in.
client.login(token); client.login(token);