Skip to content

Commit

Permalink
fix(lfg): check if initial embed is created, leverage direct calls
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Dec 23, 2020
1 parent aa498d6 commit aeeb07d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/commands/LFG/LFG.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,15 @@ class AddLFG extends Command {
// save params based on order
const embed = new LFGEmbed(this.bot, lfg);
try {
const msg = await this.messageManager
.embedToChannel(ctx.lfg[lfg.platform] || ctx.lfg[Object.keys(ctx.lfg)[0]], embed);
const chn = message.guild.channels
.resolve(ctx.lfg[lfg.platform] || ctx.lfg[Object.keys(ctx.lfg)[0]]);

const msg = await chn.send(embed);

if (!msg) {
message.channel.send('Unknown error. Could not create LFG entry.');
return this.messageManager.statuses.FAILURE;
}
msg.delete({ timeout: dehumanize(lfg.expiry) + 10000 });
msg.react('🔰');
msg.react('❌');
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Ondemand/Wiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const WikiEmbed = require('../../embeds/WikiEmbed.js');
const warframe = new Wikia('warframe');

const { emojify } = require('../../CommonFunctions');

const noResult = `${emojify('red_tick')} No result for search, Operator. Attempt another query.`;

/**
Expand Down Expand Up @@ -49,7 +50,6 @@ class Wiki extends Command {
await message.channel.send(JSON.parse(JSON.stringify(embed)));
return this.messageManager.statuses.SUCCESS;
} catch (error) {
console.error(error);
message.channel.send(noResult);
return this.messageManager.statuses.FAILURE;
}
Expand Down
1 change: 0 additions & 1 deletion src/commands/Reddit/BaseReddit.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class BaseReddit extends Command {
async run(message) {
const { permalink, url, title } = (await fetch(this.url))[0].data.children[0].data;
const embed = new Embed();
console.log(`url: ${url} | ${title} | ${permalink}`);
embed.setTitle(title);
embed.setURL(`https://reddit.com${permalink}`);
embed.setImage(url);
Expand Down
20 changes: 19 additions & 1 deletion src/settings/MessageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,24 @@ class MessageManager {
return undefined;
}

wrap(embed, ctx) {
return this.wraps([embed], ctx);
}

wraps(embeds, ctx) {
return ctx.webhook && ctx.webhook.avatar
? {
username: ctx.webhook.name,
avatarURL: ctx.webhook.avatar,
embeds,
}
: {
username: this.settings.defaults.username,
avatarURL: this.settings.defaults.avatar,
embeds,
};
}

/**
* Send an embed, with options to delete messages after calling
* @param {Message} message original message being responded to
Expand Down Expand Up @@ -298,7 +316,7 @@ class MessageManager {
const channelWebhook = await this.settings.getChannelWebhook(ctx.channel);
if (!embed.embeds) {
// eslint-disable-next-line no-param-reassign
embed = this.webhookWrapEmbed(embed, ctx);
embed = this.wrap(embed, ctx);
}
if (channelWebhook && channelWebhook.token && channelWebhook.id) {
// eslint-disable-next-line no-param-reassign
Expand Down

0 comments on commit aeeb07d

Please sign in to comment.