Skip to content

Commit

Permalink
Add embeds
Browse files Browse the repository at this point in the history
  • Loading branch information
Leyren committed Jan 12, 2020
1 parent 822ab0b commit c10f4ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Binary file added assets/bdo-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 17 additions & 6 deletions guildquests.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const Discord = require("discord.js");
const moment = require("moment");
const interval = 5000

Expand Down Expand Up @@ -32,7 +33,7 @@ module.exports = (client) => {
if (match){
const [name, idx] = [match[1], match[2]];
const resolved = serverNames.filter(s => s.toUpperCase().startsWith(name.toUpperCase()));
return resolved.map((v, d) => v+idx);
return resolved.map((v, d) => v + idx);
}
};

Expand All @@ -49,12 +50,21 @@ module.exports = (client) => {
const currentGQs = (guild) => {
const gqs = client.gq.lists.get(guild) || [];
let msg = ``;
gqs.forEach((v, idx) => msg += `<${idx + 1}> [${v.server}] ${v.desc} --- Time left: ${moment.duration(v.end.diff(curr)).format('HH:mm:ss')}.\n`);
gqs.forEach((v, idx) => msg += `<${idx + 1}> [**${v.server}**] ${v.desc} --- Time left: ${moment.duration(v.end.diff(curr)).format('HH:mm:ss')}.\n`);
return msg;
};

let embed = new Discord.RichEmbed()
.setColor('#0099ff')
.setTitle('Current Missions')
.setDescription('///')
.attachFiles(['./assets/bdo-icon.png'])
.setThumbnail('attachment://bdo-icon.png')
.setTimestamp();

setInterval(async () => {
curr = moment();

for (var [guild, quests] of client.gq.lists.entries()) {
let [valid, expired] = [[], []];
quests.forEach((v, _) => (curr > v.end ? expired : valid).push(v));
Expand All @@ -63,16 +73,17 @@ module.exports = (client) => {

if (quests.length > 0){
client.gq.lists.set(guild, quests);
const content = currentGQs(guild);
embed.setDescription(currentGQs(guild));
if (!client.gq.msgs.has(guild)){
const msg = await guild.channels.find(v => v.type == `text`).send(content);
const msg = await guild.channels.find(v => v.type == `text`).send(embed);
client.gq.msgs.set(guild, msg);
}else{
client.gq.msgs.get(guild).edit(content);
client.gq.msgs.get(guild).edit(embed);
}
}else{
client.gq.lists.delete(guild);
if (client.gq.msgs.has(guild)) client.gq.msgs.get(guild).edit("Current guild quests: None.");
embed.setDescription('///')
if (client.gq.msgs.has(guild)) client.gq.msgs.get(guild).edit(embed);
}
}
}, interval);
Expand Down

0 comments on commit c10f4ae

Please sign in to comment.