From 94f765af0d4c8d71c51211b205e2194bcb4be540 Mon Sep 17 00:00:00 2001 From: zadi15 <44522755+zadi15@users.noreply.github.com> Date: Tue, 22 Sep 2020 15:37:45 +0300 Subject: [PATCH 1/5] Update messages sent to users --- LICENSE.md | 2 +- src/messagehandler.js | 55 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 969cf7f..040108e 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 KGT1 +Copyright (c) 2020 KGT1, zadi15 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/messagehandler.js b/src/messagehandler.js index 00fd310..dda9d79 100644 --- a/src/messagehandler.js +++ b/src/messagehandler.js @@ -41,6 +41,7 @@ function getRandomDiscordColor () { return ("#" + ("00" + (randomNumber(rS, rE)).toString(16)).substr(-2) + ("00" + (randomNumber(gS, gE)).toString(16)).substr(-2) + ("00" + (randomNumber(bS, bE)).toString(16)).substr(-2)); } +// Song Search, return the song itemID async function searchForItemID (searchString) { const response = await jellyfinClientManager.getJellyfinClient().getSearchHints({ searchTerm: searchString, @@ -59,15 +60,38 @@ function summon (voiceChannel) { } function summonMessage (message) { + getRandomDiscordColor(); if (!message.member.voice.channel) { message.reply("please join a voice channel to summon me!"); } else if (message.channel.type === "dm") { message.reply("no dms"); } else { + var desc = "**Joined Voice Channel** `"; + desc = desc.concat(message.member.voice.channel.name).concat("`"); + summon(message.member.voice.channel); + + const vcJoin = new Discord.MessageEmbed() + .setColor(getRandomDiscordColor()) + .setTitle('Joined Channel') + .setTimestamp() + .setDescription("<:loudspeaker:757929476993581117> " + desc); + message.channel.send(vcJoin); } } +function songPlayMessage (message, itemID, argument){ + getRandomDiscordColor(); + //const imageUrl = getImageUrl(itemID); + const play = new Discord.MessageEmbed() + .setColor(getRandomDiscordColor()) + .setTitle('Now Playing') + //.setImage(imageUrl) + .setTimestamp() + .setDescription("<:mag_right:757935694403338380> " + 'Top result for: ' + argument); + message.channel.send(play); +} + async function playThis (message) { const indexOfItemID = message.content.indexOf(CONFIG["discord-prefix"] + "play") + (CONFIG["discord-prefix"] + "play").length + 1; const argument = message.content.slice(indexOfItemID); @@ -80,13 +104,19 @@ async function playThis (message) { try { itemID = await searchForItemID(argument); } catch (e) { - message.reply(e.message); + const noSong = new Discord.MessageEmbed() + .setColor(0xff0000) + .setTitle('Error!') + .setTimestamp() + .setDescription("<:x:757935515445231651> " + e); + message.channel.send(noSong); playbackmanager.stop(discordClient.user.client.voice.connections.first()); return; } } discordClient.user.client.voice.connections.forEach((element) => { + songPlayMessage(message, itemID, argument); playbackmanager.startPlaying(element, itemID, isSummendByPlay); }); } @@ -106,11 +136,28 @@ function handleChannelMessage (message) { discordClient.user.client.voice.connections.forEach((element) => { element.disconnect(); }); + var desc = "**Left Voice Channel** `"; + desc = desc.concat(message.member.voice.channel.name).concat("`"); + const vcJoin = new Discord.MessageEmbed() + .setColor(getRandomDiscordColor()) + .setTitle('Left Channel') + .setTimestamp() + .setDescription("<:wave:757938481585586226> " + desc); + message.channel.send(vcJoin); } else if ((message.content.startsWith(CONFIG["discord-prefix"] + "pause")) || (message.content.startsWith(CONFIG["discord-prefix"] + "resume"))) { if (getAudioDispatcher() !== undefined) { playbackmanager.playPause(); + const noPlay = new Discord.MessageEmbed() + .setColor(0xff0000) + .setTitle("<:play_pause:757940598106882049> " +'Paused/Resumed.') + .setTimestamp() + message.channel.send(noPlay); } else { - message.reply("there is nothing playing!"); + const noPlay = new Discord.MessageEmbed() + .setColor(0xff0000) + .setTitle("<:x:757935515445231651> " +'There is nothing Playing right now!') + .setTimestamp() + message.channel.send(noPlay); } } else if (message.content.startsWith(CONFIG["discord-prefix"] + "play")) { if (discordClient.user.client.voice.connections.size < 1) { @@ -130,6 +177,7 @@ function handleChannelMessage (message) { } else if (message.content.startsWith(CONFIG["discord-prefix"] + "help")) { const reply = new Discord.MessageEmbed() .setColor(getRandomDiscordColor()) + .setTitle("<:musical_note:757938541123862638> " + 'Jellyfin Discord Music Bot' + " <:musical_note:757938541123862638> ") .addFields({ name: `${CONFIG["discord-prefix"]}summon`, value: "Join the channel the author of the message" @@ -145,6 +193,9 @@ function handleChannelMessage (message) { }, { name: `${CONFIG["discord-prefix"]}help`, value: "Display this help message" + }, { + name: `GitHub`, + value: "Find the code for this bot at: https://github.com/KGT1/jellyfin-discord-music-bot" }); message.channel.send(reply); } From 1b7f4b786da247b37528c8006113843f328de96c Mon Sep 17 00:00:00 2001 From: zadi15 Date: Wed, 23 Sep 2020 09:52:35 +0300 Subject: [PATCH 2/5] Update src/messagehandler.js Co-authored-by: KGT1 --- src/messagehandler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/messagehandler.js b/src/messagehandler.js index dda9d79..8aeea52 100644 --- a/src/messagehandler.js +++ b/src/messagehandler.js @@ -116,7 +116,7 @@ async function playThis (message) { } discordClient.user.client.voice.connections.forEach((element) => { - songPlayMessage(message, itemID, argument); + songPlayMessage(message, argument); playbackmanager.startPlaying(element, itemID, isSummendByPlay); }); } From ed20432c02294ea5c0832a58946dfaa0f585e591 Mon Sep 17 00:00:00 2001 From: zadi15 Date: Wed, 23 Sep 2020 09:52:51 +0300 Subject: [PATCH 3/5] Update src/messagehandler.js Co-authored-by: KGT1 --- src/messagehandler.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/messagehandler.js b/src/messagehandler.js index 8aeea52..ac9ca4b 100644 --- a/src/messagehandler.js +++ b/src/messagehandler.js @@ -80,9 +80,7 @@ function summonMessage (message) { } } -function songPlayMessage (message, itemID, argument){ - getRandomDiscordColor(); - //const imageUrl = getImageUrl(itemID); +function songPlayMessage (message, argument){ const play = new Discord.MessageEmbed() .setColor(getRandomDiscordColor()) .setTitle('Now Playing') From 6c0ef87c35b629d47c1cb2b4da754f0274c9453e Mon Sep 17 00:00:00 2001 From: zadi15 Date: Wed, 23 Sep 2020 09:54:58 +0300 Subject: [PATCH 4/5] Removed unnecessary function --- src/messagehandler.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/messagehandler.js b/src/messagehandler.js index ac9ca4b..be0eb2d 100644 --- a/src/messagehandler.js +++ b/src/messagehandler.js @@ -60,7 +60,6 @@ function summon (voiceChannel) { } function summonMessage (message) { - getRandomDiscordColor(); if (!message.member.voice.channel) { message.reply("please join a voice channel to summon me!"); } else if (message.channel.type === "dm") { From 540c70e30440c6d5d8a04e46b33b242bd85400d5 Mon Sep 17 00:00:00 2001 From: zadi15 <44522755+zadi15@users.noreply.github.com> Date: Wed, 23 Sep 2020 12:02:32 +0300 Subject: [PATCH 5/5] Fixed linter issues --- src/messagehandler.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/messagehandler.js b/src/messagehandler.js index be0eb2d..18ae5e6 100644 --- a/src/messagehandler.js +++ b/src/messagehandler.js @@ -72,20 +72,19 @@ function summonMessage (message) { const vcJoin = new Discord.MessageEmbed() .setColor(getRandomDiscordColor()) - .setTitle('Joined Channel') + .setTitle("Joined Channel") .setTimestamp() .setDescription("<:loudspeaker:757929476993581117> " + desc); message.channel.send(vcJoin); } } -function songPlayMessage (message, argument){ +function songPlayMessage (message, argument) { const play = new Discord.MessageEmbed() .setColor(getRandomDiscordColor()) - .setTitle('Now Playing') - //.setImage(imageUrl) + .setTitle("Now Playing") .setTimestamp() - .setDescription("<:mag_right:757935694403338380> " + 'Top result for: ' + argument); + .setDescription("<:mag_right:757935694403338380> " + "Top result for: " + argument); message.channel.send(play); } @@ -103,7 +102,7 @@ async function playThis (message) { } catch (e) { const noSong = new Discord.MessageEmbed() .setColor(0xff0000) - .setTitle('Error!') + .setTitle("Error!") .setTimestamp() .setDescription("<:x:757935515445231651> " + e); message.channel.send(noSong); @@ -137,7 +136,7 @@ function handleChannelMessage (message) { desc = desc.concat(message.member.voice.channel.name).concat("`"); const vcJoin = new Discord.MessageEmbed() .setColor(getRandomDiscordColor()) - .setTitle('Left Channel') + .setTitle("Left Channel") .setTimestamp() .setDescription("<:wave:757938481585586226> " + desc); message.channel.send(vcJoin); @@ -146,14 +145,14 @@ function handleChannelMessage (message) { playbackmanager.playPause(); const noPlay = new Discord.MessageEmbed() .setColor(0xff0000) - .setTitle("<:play_pause:757940598106882049> " +'Paused/Resumed.') - .setTimestamp() + .setTitle("<:play_pause:757940598106882049> " + "Paused/Resumed.") + .setTimestamp(); message.channel.send(noPlay); } else { const noPlay = new Discord.MessageEmbed() .setColor(0xff0000) - .setTitle("<:x:757935515445231651> " +'There is nothing Playing right now!') - .setTimestamp() + .setTitle("<:x:757935515445231651> " + "There is nothing Playing right now!") + .setTimestamp(); message.channel.send(noPlay); } } else if (message.content.startsWith(CONFIG["discord-prefix"] + "play")) { @@ -174,7 +173,7 @@ function handleChannelMessage (message) { } else if (message.content.startsWith(CONFIG["discord-prefix"] + "help")) { const reply = new Discord.MessageEmbed() .setColor(getRandomDiscordColor()) - .setTitle("<:musical_note:757938541123862638> " + 'Jellyfin Discord Music Bot' + " <:musical_note:757938541123862638> ") + .setTitle("<:musical_note:757938541123862638> " + "Jellyfin Discord Music Bot" + " <:musical_note:757938541123862638> ") .addFields({ name: `${CONFIG["discord-prefix"]}summon`, value: "Join the channel the author of the message"