Merge pull request #2 from zadi15/master

Updated + added bot responses
This commit is contained in:
KGT1 2020-09-23 11:32:01 +02:00 committed by GitHub
commit 515741f7c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 3 deletions

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2020 KGT1 Copyright (c) 2020 KGT1, zadi15
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -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)); 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) { async function searchForItemID (searchString) {
const response = await jellyfinClientManager.getJellyfinClient().getSearchHints({ const response = await jellyfinClientManager.getJellyfinClient().getSearchHints({
searchTerm: searchString, searchTerm: searchString,
@ -64,10 +65,29 @@ function summonMessage (message) {
} else if (message.channel.type === "dm") { } else if (message.channel.type === "dm") {
message.reply("no dms"); message.reply("no dms");
} else { } else {
var desc = "**Joined Voice Channel** `";
desc = desc.concat(message.member.voice.channel.name).concat("`");
summon(message.member.voice.channel); 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, argument) {
const play = new Discord.MessageEmbed()
.setColor(getRandomDiscordColor())
.setTitle("Now Playing")
.setTimestamp()
.setDescription("<:mag_right:757935694403338380> " + "Top result for: " + argument);
message.channel.send(play);
}
async function playThis (message) { async function playThis (message) {
const indexOfItemID = message.content.indexOf(CONFIG["discord-prefix"] + "play") + (CONFIG["discord-prefix"] + "play").length + 1; const indexOfItemID = message.content.indexOf(CONFIG["discord-prefix"] + "play") + (CONFIG["discord-prefix"] + "play").length + 1;
const argument = message.content.slice(indexOfItemID); const argument = message.content.slice(indexOfItemID);
@ -80,13 +100,19 @@ async function playThis (message) {
try { try {
itemID = await searchForItemID(argument); itemID = await searchForItemID(argument);
} catch (e) { } 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()); playbackmanager.stop(discordClient.user.client.voice.connections.first());
return; return;
} }
} }
discordClient.user.client.voice.connections.forEach((element) => { discordClient.user.client.voice.connections.forEach((element) => {
songPlayMessage(message, argument);
playbackmanager.startPlaying(element, itemID, isSummendByPlay); playbackmanager.startPlaying(element, itemID, isSummendByPlay);
}); });
} }
@ -106,11 +132,28 @@ function handleChannelMessage (message) {
discordClient.user.client.voice.connections.forEach((element) => { discordClient.user.client.voice.connections.forEach((element) => {
element.disconnect(); 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"))) { } else if ((message.content.startsWith(CONFIG["discord-prefix"] + "pause")) || (message.content.startsWith(CONFIG["discord-prefix"] + "resume"))) {
if (getAudioDispatcher() !== undefined) { if (getAudioDispatcher() !== undefined) {
playbackmanager.playPause(); playbackmanager.playPause();
const noPlay = new Discord.MessageEmbed()
.setColor(0xff0000)
.setTitle("<:play_pause:757940598106882049> " + "Paused/Resumed.")
.setTimestamp();
message.channel.send(noPlay);
} else { } 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")) { } else if (message.content.startsWith(CONFIG["discord-prefix"] + "play")) {
if (discordClient.user.client.voice.connections.size < 1) { if (discordClient.user.client.voice.connections.size < 1) {
@ -130,6 +173,7 @@ function handleChannelMessage (message) {
} else if (message.content.startsWith(CONFIG["discord-prefix"] + "help")) { } else if (message.content.startsWith(CONFIG["discord-prefix"] + "help")) {
const reply = new Discord.MessageEmbed() const reply = new Discord.MessageEmbed()
.setColor(getRandomDiscordColor()) .setColor(getRandomDiscordColor())
.setTitle("<:musical_note:757938541123862638> " + "Jellyfin Discord Music Bot" + " <:musical_note:757938541123862638> ")
.addFields({ .addFields({
name: `${CONFIG["discord-prefix"]}summon`, name: `${CONFIG["discord-prefix"]}summon`,
value: "Join the channel the author of the message" value: "Join the channel the author of the message"
@ -145,6 +189,9 @@ function handleChannelMessage (message) {
}, { }, {
name: `${CONFIG["discord-prefix"]}help`, name: `${CONFIG["discord-prefix"]}help`,
value: "Display this help message" 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); message.channel.send(reply);
} }