diff --git a/.data/.gitkeep b/.data/.gitkeep new file mode 100755 index 0000000..e69de29 diff --git a/.dockerignore b/.dockerignore index fd5a86d..1ebe970 100755 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,6 @@ Sounds Markov - +.git +.gitignore +Dockerfile +.dockerignore diff --git a/bot.js b/bot.js index f26fb53..5ab2779 100755 --- a/bot.js +++ b/bot.js @@ -1,19 +1,17 @@ -// ZeSkypeBot 7.0.0_a - // *** Libraries to import *** const { Client, Events, GatewayIntentBits } = require('discord.js'); const Voice = require('@discordjs/voice'); const { createReadStream, existsSync } = require('fs'); const play = require('play-dl'); // Local config files to import -const { token } = require('./config.json'); +const { token } = require('./.data/config.json'); // Declare a new Discord Client Instance const client = new Client( { intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildVoiceStates] } ); // Define Sigtrap Callback for clean shutdowns function signalExit(signal) { - console.log("\tCaught ${signal}"); + console.log(`\tCaught ${signal}`); // Kills voice connections, and logs the client out client.destroy(); // Exit with return code 0 @@ -108,24 +106,66 @@ client.on( Events.MessageCreate, async message => { const resource = Voice.createAudioResource(createReadStream(soundPath)); const player = Voice.createAudioPlayer(); // Play the resource through the player to the connection (i hate discord v16) - player.on('Playing', () => { - console.log(`Playing ${soundpath}`); - }); player.play(resource); + // Connect the player to the voice connection (internal screaming intensifies) connection.subscribe(player); - // Setup Callbacks for when the player completes - player.on('Idle', () => { - console.log(`Finished ${soundpath}`); - }); return; } } - // Otherwise process commands + // Check for youtube play command + if (message.content.startsWith('!play') && message.member.voice.channel) { + console.log(`!play issued by ${message.author.tag} ${message.author.id}`); + // Determine if we have a URL or a search term + const ytmatch = message.content.match(/(?<=(https?:\/\/)(www\.)?youtu((be\.com\/watch\?v=)|(\.be\/)))[\w-]{11,12}/); + var yturl = null; + var timestamp = '0' + if (ytmatch) { + console.log(`ytmatch yields ${ytmatch[0]}`); + // Message matches the youtube video regex, see if it comes with a timestamp + const timematch = message.content.match(/(?<=t=)(\d{1,4})s?(?=$)/); + if (timematch) { + console.log(`timematch yields $timematch[1]`); + timestamp = timematch[1]; + } + // Reconstruct a URL for the supplied video + yturl = `https://youtu.be/${ytmatch[0]}`; + } else { + // Message may be a search term + let args = message.content.split('play ')[1]; + console.log(`ytsearch args: "${args}"`); + // Search youtube with the term + let yt_info = await play.search(args, { limit: 1 }); + // and get the first result as a URL + yturl = yt_info[0].url; + // Link it to the chat + message.channel.send(`Found video ${yturl} hope its what you were looking for`); + } + console.log(`yturl: ${yturl}`); + // Create a stream reference to the provided URL + const stream = await play.stream(yturl, { seek: timestamp }); + // Now that we have a stream reference we can join the channel and play + const connection = Voice.joinVoiceChannel({ + channelId: message.member.voice.channel.id, + guildId: message.guild.id, + adapterCreator: message.guild.voiceAdapterCreator, + }); + // Open the stream as a voice resource + const resource = Voice.createAudioResource(stream.stream, { inputType: stream.type }); + // Create a player to play the resource + const player = Voice.createAudioPlayer(); + // Play the resource through the player (i hate discord v16) + player.play(resource); + // Connect the player to the voice connection (internal screaming intensifies) + connection.subscribe(player); + // Setup Callbacks for when the player completes + return; + } if (message.content === "!help" ) { console.log(`!help issued by ${message.author.tag} ${message.author.id}`); - var response = 'ZeSkypeBot v7.1.0 \'Table Salt\'\n'; + var response = 'ZeSkypeBot v7.2.0 \'Table Salt\'\n'; response += 'Original by moosecrap#5953 for Skype, Remade by Weegee#6402 for Discord\n'; response += 'Changelog:\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.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'; @@ -144,53 +184,6 @@ client.on( Events.MessageCreate, async message => { message.channel.send(response); return; } - // Check for youtube play command - if (message.content.startsWith('!play') && message.member.voice.channel) { - // Determine if we have a URL or a search term - const ytmatch = message.content.match(/(?<=(https?:\/\/)(www\.)?youtu((be\.com\/watch\?v=)|(\.be\/)))[\w-]{11}/); - var yturl = null; - var timestamp = '0' - if (ytmatch) { - // Message matches the youtube video regex, see if it comes with a timestamp - const timematch = message.content.match(/(?<=t=)(\d{1,4})s?(?=$)/); - if (timematch) { - timestamp = timematch[1]; - } - // Reconstruct a URL for the supplied video - yturl = `https://youtu.be/${ytmatch[0]}`; - } else { - // Message may be a search term - let args = message.content.split('play')[1]; - // Search youtube with the term - let yt_info = await play.search(args, { limit: 1 }); - // and get the first result as a URL - yturl = yt_info[0].url; - } - // Create a stream reference to the provided URL - const stream = await play.stream(yturl, { seek: timestamp }); - // Now that we have a stream reference we can join the channel and play - const connection = Voice.joinVoiceChannel({ - channelId: message.member.voice.channel.id, - guildId: message.guild.id, - adapterCreator: message.guild.voiceAdapterCreator, - }); - // Open the stream as a voice resource - const resource = Voice.createAudioResource(stream.stream, { inputType: stream.type }); - // Create a player to play the resource - const player = Voice.createAudioPlayer(); - // Play the resource through the player (i hate discord v16) - player.on('Playing', () => { - console.log(`Playing ${yturl}`); - }); - player.play(resource); - // Connect the player to the voice connection (internal screaming intensifies) - connection.subscribe(player); - // Setup Callbacks for when the player completes - player.on('Idle', () => { - console.log(`Finished ${yturl}`); - }); - return; - } // Generic message responses if (message.content.match(/https:\/\/ootbingo\.github\.io/)) { diff --git a/package.json b/package.json index c1cab58..74fac41 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zeskypebot", - "version": "7.0.0_a", + "version": "7.2.0", "description": "Goldar Squad's Skype Bot, ported for Discord\"", "main": "bot.js", "scripts": {