Skip to content

Commit

Permalink
Add emojis to notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdevey committed Nov 3, 2021
1 parent 025711f commit 9206e37
Showing 1 changed file with 53 additions and 19 deletions.
72 changes: 53 additions & 19 deletions src/stateUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,64 @@ export function stateUpdate(discord, before, updated) {
if(member.user.bot == true) return;

// Decide on what the message should
// say based on if they joined or left.
var message;
// say based on if they joined or left
// or something else.

if(before.channel == undefined && updated.channel != undefined) {

// User joined a VC
message = `${member.displayName} just joined ${updated.channel.name}`
console.log(`${member.user.tag} JOINED ${updated.channel.name}`);
} else if(before.channel != undefined && updated.channel == undefined) {
return send(discord, `${member.displayName} just joined ${updated.channel.name}`, `🎧`, member, updateChannel);

}

if(before.channel != undefined && updated.channel == undefined) {

// User left a VC
message = `${member.displayName} just left ${before.channel.name}`
console.log(`${member.user.tag} LEFT ${before.channel.name}`);
} else if(before.channel != undefined && updated.channel != undefined && before.channel != updated.channel) {
return send(discord, `${member.user.tag} LEFT ${before.channel.name}`, `🚪`, member, updateChannel);

}

if(before.channel != undefined && updated.channel != undefined && before.channel != updated.channel) {

// User switched VCs
message = `${member.displayName} just switched to ${updated.channel.name}`
console.log(`${member.user.tag} SWITCHED TO ${updated.channel.name}`);
} else return;

// Build the embed.
const embed = new discord.MessageEmbed()
.setColor('#0067f4')
.setTitle(message)
.setAuthor(member.displayName, member.user.displayAvatarURL())
.setTimestamp();

// Send the embed in the special
// channel.
updateChannel.send({ embeds: [embed] });
return send(discord, `${member.displayName} just switched to ${updated.channel.name}`, `🔄️`, member, updateChannel);

}

if(updated.streaming) {

// User is streaming
console.log(`${member.user.tag} IS LIVE IN ${updated.channel.name}`);
return send(discord, `${member.displayName} is live in ${updated.channel.name}`, `🔴`, member, updateChannel);

}

}

/**
* Send the embed
*
* @param discord Discord.js instance
* @param message The message
* @param emoji The emoji
* @param member The member
* @param updateChannel The channel to send updates too
*/

function send(discord, message: String, emoji: String, member, updateChannel) {

// Build the embed.
const embed = new discord.MessageEmbed()
.setColor('#0067f4')
.setTitle(message)
.setAuthor(member.displayName, member.user.displayAvatarURL())
.setFooter(emoji)
.setTimestamp();

// Send the embed in the special
// channel.
updateChannel.send({ embeds: [embed] });
}

0 comments on commit 9206e37

Please sign in to comment.