Skip to content

Commit

Permalink
fix: misc existential fixes, support compactable
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Nov 8, 2021
1 parent 0ed2bff commit 99d0852
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 4,979 deletions.
4,946 changes: 19 additions & 4,927 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions src/CommonFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,7 @@ const createPagedInteractionCollector = async (interaction, pages, ctx) => {
}
const pagedPages = pages.map((newPage, index) => {
const pageInd = `Page ${index + 1}/${pages.length}`;
if (!newPage.description) newPage.setDescription('_ _');
if (newPage.footer) {
if (newPage instanceof MessageEmbed) {
if (newPage.footer.text.indexOf('Page') === -1) {
Expand All @@ -1253,15 +1254,16 @@ const createPagedInteractionCollector = async (interaction, pages, ctx) => {
}
return new MessageEmbed(newPage);
});
const embeds = [pagedPages[page - 1]];
const message = interaction.deferred || interaction.replied
? await interaction.editReply({
ephemeral: ctx.ephemerate,
embeds: [pagedPages[page - 1]],
embeds,
components: navComponents,
})
: await interaction.reply({
ephemeral: ctx.ephemerate,
embeds: [pagedPages[page - 1]],
embeds,
components: navComponents,
});

Expand Down Expand Up @@ -1329,6 +1331,10 @@ const createPagedInteractionCollector = async (interaction, pages, ctx) => {
return message;
};

const createDynamicInteractionCollector = async (interaction, pages, ctx) => (pages?.length < 26
? createSelectionCollector(interaction, pages, ctx)
: createPagedInteractionCollector(interaction, pages, ctx));

const confirmationComponents = [
new MessageActionRow({
components: [
Expand Down Expand Up @@ -1441,4 +1447,5 @@ module.exports = {
createPagedInteractionCollector,
createConfirmationCollector,
createSelectionCollector,
createDynamicInteractionCollector,
};
2 changes: 1 addition & 1 deletion src/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const contexts = {
TwitchApi: 'magenta',
TM: 'yellow',
};
const ignore = ['CHANNEL_NOT_CACHED', 'Invalid refresh token', 'Failed to load', 'https://discrd.com/api/webhooks/'];
const ignore = ['Invalid refresh token', 'Failed to load', 'https://discord.com/api/webhooks/', 'Could not find the channel', 'DiscordAPIError'];

/**
* A collection of methods for logging
Expand Down
2 changes: 1 addition & 1 deletion src/commands/LFG/LFG.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class AddLFG extends Command {
await message.reply('Unknown error. Could not create LFG entry.');
return this.constructor.statuses.FAILURE;
}
let deleteTimeout = this.bot.client.setTimeout(msg.delete, dehumanize(lfg.expiry) + 10000);
let deleteTimeout = setTimeout(msg.delete, dehumanize(lfg.expiry) + 10000);
msg.react('🔰');
await msg.react('❌');

Expand Down
3 changes: 0 additions & 3 deletions src/commands/Ondemand/Whatsin.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
'use strict';

const fetch = require('../../resources/Fetcher');

const Command = require('../../models/Command');
const WhatsinEmbed = require('../../embeds/WhatsinEmbed');

const inProgressEmbed = { title: 'Processing search...', color: 0xF1C40F };
const noResultsEmbed = { title: 'No results for that query. Please refine your search.', color: 0xff6961 };
const relicBase = 'https://drops.warframestat.us/data/relics';

function toTitleCase(str) {
return str.replace(/\w\S*/g, txt => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase());
Expand Down
3 changes: 2 additions & 1 deletion src/commands/Roles/JoinRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ class JoinRole extends Command {
embed.fields[0].name = `${prefix}${this.call} <role or role id>`;
const roles = await this.settings.getRolesForGuild(message.guild);
embed.fields[1].value = roles.length ? roles.map(role => role.guildRole.name).join('; ') : 'No possible roles';
await message.reply({ embeds: [embed] });
if (!message.channel) return null;
return message.reply({ embeds: [embed] });
}
}

Expand Down
10 changes: 2 additions & 8 deletions src/commands/Silly/Echo.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@ class Echo extends Command {
this.regex = new RegExp(`^${this.call}\\s?(.+)?`, 'i');
}

/**
* Run the command
* @param {Message} message Message with a command to handle, reply to,
* or perform an action based on parameters.
* @param {Object} ctx command call context
* @returns {string} success status
*/
async run(message, ctx) {
if (message.deleteable) {
await message.delete();
}
await message.channel.send({ content: message.cleanContent.replace(this.call, '').replace(ctx.prefix, '').trim() });
const content = message.cleanContent.replace(this.call, '').replace(ctx.prefix, '').trim();
if (content.length) await message.channel.send({ content });
return this.constructor.statuses.SUCCESS;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Worldstate/Arbitration.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Arbitration extends Command {
await message.reply({ content: ctx.i18n`No Arbitration Mission Active` });
}

await message.reply({ embeds: [new ArbitrationEmbed(this.bot, arbi, platform, ctx.i18n)] });
await message.reply({ embeds: [new ArbitrationEmbed(null, arbi, platform, ctx.i18n)] });

return this.constructor.statuses.SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/Worldstate/Fissures.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Fissures extends Command {
};

fissures.forEach((fissure) => {
eras[fissure.tier.toLowerCase()].push(fissure);
eras?.[fissure.tier.toLowerCase()]?.push(fissure);
});

Object.keys(eras).forEach((eraKey) => {
Expand Down
18 changes: 3 additions & 15 deletions src/embeds/ArbitrationEmbed.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
'use strict';

const BaseEmbed = require('./BaseEmbed.js');
const { assetBase } = require('../CommonFunctions');

const arbiThumb = `${assetBase}/img/arbitrations.png`;

/**
* Generates alert embeds
*/
class ArbitrationEmbed extends BaseEmbed {
/**
* @param {Genesis} bot - An instance of Genesis
* @param {ExternalMission} arbitration - The alerts to be included in the embed
* @param {string} platform - platform
* @param {I18n} i18n - string template function for internationalization
*/
module.exports = class ArbitrationEmbed extends require('./BaseEmbed.js') {
constructor(bot, arbitration, platform, i18n) {
super();
this.thumbnail.url = arbiThumb;
this.color = 0x742725;
this.title = i18n`[${platform.toUpperCase()}] Worldstate - Arbitration`;
this.addField(arbitration.node, arbitration.type);
this.addField(arbitration.node || '???', arbitration.type || '???');

this.footer.text = i18n`Expires`;
this.timestamp = arbitration.expiry;
}
}

module.exports = ArbitrationEmbed;
};
2 changes: 1 addition & 1 deletion src/embeds/EnemyEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class EnemyEmbed extends BaseEmbed {
inline: true,
}];

enemy.resistances.forEach((resistance) => {
enemy?.resistances?.forEach((resistance) => {
const field = {
name: `Resistances for ${resistance.type}${resistance.amount}`,
value: '',
Expand Down
6 changes: 3 additions & 3 deletions src/embeds/UserInfoEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class UserInfoEmbed extends BaseEmbed {
value: member.id === message.guild.ownerID ? affirm : negate,
inline: true,
},
{
member?.presence?.status ? {
name: 'Status',
value: member.presence.status,
inline: true,
},
} : null,
{
name: 'Current State:',
value: `**Deafened:** ${member.deaf ? affirm : negate}\n`
Expand All @@ -69,7 +69,7 @@ class UserInfoEmbed extends BaseEmbed {
value: member.roles.cache.size ? member.roles.cache.map(role => role).join(', ') : 'User has no roles.',
inline: false,
},
]);
].filter(a => a));

this.footer.text = `${this.footer.text} - Joined`;
this.timestamp = member.joinedAt;
Expand Down
1 change: 1 addition & 0 deletions src/eventHandlers/InteractionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ module.exports = class InteractionHandler extends require('../models/BaseEventHa
ctx.handler = this;
ctx.logger = this.logger;
if (interaction.guild) ctx.settings.addExecution(interaction.guild, commandId(interaction));
if (!interaction) return null;
// eslint-disable-next-line no-nested-ternary,consistent-return
return match
? match?.commandHandler?.(interaction, ctx)
Expand Down
21 changes: 13 additions & 8 deletions src/interactions/tracking/Tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,16 @@ module.exports = class Settings extends require('../../models/Interaction') {
? trackableItems.items
: trackableEvents[currentDetermination];
const groupOptions = list?.length
? list.map(li => ({
label: toTitleCase(li.split('.').join(' ')),
value: li,
default: current.items.includes(li) || current.events.includes(li),
}))
? list.map((li, index) => {
if (index < 25) {
return {
label: toTitleCase(li.split('.').join(' ')),
value: li,
default: current.items.includes(li) || current.events.includes(li),
};
}
return null;
}).filter(a => a)
: [{ label: 'N/A', value: 'na', default: false }];
return ([
// paginator
Expand Down Expand Up @@ -460,17 +465,17 @@ module.exports = class Settings extends require('../../models/Interaction') {
}
if (webhook.url) {
try {
await interaction.reply(`${emojify('green_tick')} Webhook setup complete.`);
await interaction.followUp(`${emojify('green_tick')} Webhook setup complete.`);
await webhook.send(':diamond_shape_with_a_dot_inside: Webhook initialized');
if (!webhook.avatar.startsWith('http')) webhook.avatar = ctx.settings.defaults.avatar;
} catch (e) {
ctx.logger.error(e);
await interaction.reply(`${emojify('red_tick')} Cannot set up webhooks: failed to send.`);
await interaction.followUp(`${emojify('red_tick')} Cannot set up webhooks: failed to send.`);
}
} else {
ctx.logger.debug(`webhook for ${channel.id} already set up...`);
}
ctx.settings.setChannelWebhook(channel, webhook);
await ctx.settings.setChannelWebhook(channel, webhook);
} else {
await interaction.followUp(`${emojify('red_tick')} Cannot set up webhooks: missing permissions.`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/interactions/warframe/LFG.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module.exports = class LFG extends require('../../models/Interaction') {

const embed = new LFGEmbed(null, lfg);
const chn = interaction.guild.channels
.resolve((ctx.lfg[lfg.platform] || ctx.lfg[Object.keys(ctx.lfg)[0]]).id);
.resolve((ctx.lfg?.[lfg.platform] || ctx.lfg?.[Object.keys(ctx.lfg)?.[0]]).id);

const buttons = [
new MessageActionRow({
Expand Down
38 changes: 32 additions & 6 deletions src/interactions/warframe/Worldstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { Constants: { ApplicationCommandOptionTypes: Types }, MessageEmbed } = require('discord.js');

const {
games, createGroupedArray,
games, createGroupedArray, createDynamicInteractionCollector,
} = require('../../CommonFunctions.js');

const platformChoices = require('../../resources/platformMap');
Expand Down Expand Up @@ -199,7 +199,7 @@ module.exports = class WorldState extends require('../../models/Interaction') {
type: Types.SUB_COMMAND,
name: 'steelpath',
description: 'Get Current Steel Path Offerings',
options: compactable,
options: platformable,
}, {
type: Types.SUB_COMMAND,
name: 'sortie',
Expand All @@ -213,8 +213,8 @@ module.exports = class WorldState extends require('../../models/Interaction') {
const language = ctx.language || 'en';
const subcommand = interaction.options.getSubcommand();
const { options } = interaction;
const platform = options?.get?.('platform')?.value || ctx.platform || 'pc';
// const compact = options?.get?.('compact')?.value || false;
const platform = options?.getString?.('platform')?.value || ctx.platform || 'pc';
const compact = options?.getBoolean?.('compact');
const ephemeral = ctx.ephemerate;

let category = options?.get?.('category')?.value || 'all';
Expand All @@ -233,9 +233,35 @@ module.exports = class WorldState extends require('../../models/Interaction') {
let pages;
let embed;
switch (field) {
case 'alerts':
case 'fissures':
if (!compact) {
pages = [];
const eras = {
lith: [],
meso: [],
neo: [],
axi: [],
requiem: [],
};

data.forEach((fissure) => {
eras?.[fissure.tier.toLowerCase()]?.push(fissure);
});

Object.keys(eras).forEach((eraKey) => {
// eslint-disable-next-line new-cap
pages.push(new embeds.fissures(null, eras[eraKey],
platform, ctx.i18n, eras[eraKey][0].tier));
});
return createDynamicInteractionCollector(interaction, pages, ctx);
}
case 'alerts':
case 'invasions':
if (!compact) {
return createDynamicInteractionCollector(interaction,
// eslint-disable-next-line new-cap
data.map(a => new embeds[field](null, [a], platform, ctx.i18n)), ctx);
}
case 'arbitration':
case 'earthCycle':
case 'cetusCycle':
Expand Down Expand Up @@ -275,7 +301,7 @@ module.exports = class WorldState extends require('../../models/Interaction') {
if (!data.length && !Object.keys(data).length) {
return interaction.editReply(ctx.i18n`No ${field.charAt(0).toUpperCase() + field.slice(1)} Active`);
}
embed = new embeds[field](null, data, ctx);
embed = new embeds[field](null, data, { isCommand: true, i18n: ctx.i18n });
return interaction.editReply({ embeds: [embed] });
default:
break;
Expand Down

0 comments on commit 99d0852

Please sign in to comment.