Skip to content

Commit

Permalink
fix: close #331, close #300, close #270
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobiah committed May 27, 2020
1 parent 4c9d57b commit e4d61c5
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/CommonFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ const getChannel = (channelsParam, message, channels) => {
let { channel } = message;
let channelsColl;
if (message.guild) {
channelsColl = message.guild.channels;
channelsColl = message.guild.channels.cache;
} else {
channelsColl = new Collection();
channelsColl.set(message.channel.id, message.channel);
Expand Down
4 changes: 2 additions & 2 deletions src/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const scope = (process.env.SCOPE || 'worker').toUpperCase();
const ErrorEmbed = require('./embeds/ErrorEmbed');

let errorHook;
if (scope === 'worker' && process.env.CONTROL_WH_ID) {
errorHook = new WebhookClient(process.env.CONTROL_WH_ID, process.env.CONTROL_WH_TOKEN);
if (process.env.CONTROL_WH_ID) {
errorHook = new WebhookClient(process.env.CONTROL_WH_ID, process.env.CONTROL_WH_TOKEN);
}

/**
Expand Down
54 changes: 43 additions & 11 deletions src/commands/Ondemand/WhereIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,50 @@ class Whereis extends Command {
try {
query = query.trim().toLowerCase();
const queryWReplaces = query.replace(/prime/ig, 'p.').replace(/blueprint/ig, 'bp');
let results = await this.ws.search('drops', queryWReplaces);
const queryResults = (await this.ws.search('drops', queryWReplaces))
.map((result) => {
const r = {
item: result.item,
rarity: result.rarity,
chance: `${String(parseFloat(result.chance).toFixed(2)).padEnd(5, '0')}%`,
chanceNum: parseFloat(result.chance).toFixed(2),
place: result.place
.replace('Level ', '')
.replace(' Orb Vallis Bounty', '')
.replace(' Cetus Bounty', '')
.trim(),
};
r.place = r.place.split('/')[1] || r.place;
return r;
});

results = results.map(result => ({
item: result.item,
rarity: result.rarity,
chance: `${String(parseFloat(result.chance).toFixed(2)).padEnd(5, '0')}%`,
place: result.place
.replace('Level ', '')
.replace('Orb Vallis Bounty', 'Bounty')
.replace('Cetus Bounty', 'Bounty')
.trim(),
}));
let results = [];

const map = new Map();
for (const item of queryResults) {
const isRelic = item.place.includes('Relic');
const relic = item.place.split('(')[0].trim();
if (isRelic && (!map.has(relic) || map.get(relic) < item.chanceNum)) {
if (map.has(relic)) {
let indexToRemove;
results.forEach((urelic, index) => {
if (urelic.place.includes(relic)) {
indexToRemove = index;
}
});
if (typeof indexToRemove !== 'undefined') {
results.splice(indexToRemove, 1);
}
}
map.set(relic, item.chanceNum);
results.push(item);
} else if (!isRelic && (!map.has(item.place) || map.get(item.place) < item.chanceNum)) {
map.set(item.place, item.chanceNum);
results.push(item);
}
}

results = [...(new Set(results))];

const longestName = results.length ? results.map(result => result.item)
.reduce((a, b) => (a.length > b.length ? a : b)) : '';
Expand Down
8 changes: 6 additions & 2 deletions src/commands/Tracking/Track.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ class Track extends Command {
}

async run(message, ctx) {
this.logger.info('running track....');
const unsplitItems = getEventsOrItems(message);
const roomId = new RegExp(`${captures.channel}|here`, 'ig');

if (unsplitItems.length === 0) {
if (!unsplitItems.length) {
return this.failure(message, ctx.prefix);
}
const trackables = trackablesFromParameters(unsplitItems);
Expand All @@ -43,7 +44,10 @@ class Track extends Command {
trackables.items = trackables.items
.filter((elem, pos) => trackables.items.indexOf(elem) === pos);

const channelParam = message.strippedContent.match(roomId) ? message.strippedContent.match(roomId)[0].trim().replace(/<|>|#/ig, '') : undefined;
const channelParam = message.strippedContent.match(roomId)
? message.strippedContent.match(roomId)[0].trim().replace(/<|>|#/ig, '')
: undefined;

const channel = getChannel(channelParam, message);

if (trackables.events.length) {
Expand Down
8 changes: 6 additions & 2 deletions src/embeds/WhereisEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ class WhereisEmbed extends BaseEmbed {
this.fields = [];

resultsGroups.forEach((results, index) => {
const mappedResults = results.map(result => `\`${result.item.padEnd(nameWidth, '\u2003')} `
+ `| ${result.place.padEnd(relicWidth, '\u2003')} | ${result.rarity.charAt(0)}@${result.chance}\``);
const mappedResults = results.map((result) => {
const item = result.item.padEnd(nameWidth, '\u2003');
const place = (result.place.split('/')[1] || result.place).padEnd(relicWidth, '\u2003');
const chance = `${result.rarity.charAt(0)}@${result.chance}`;
return `\`${item} | ${place} | ${chance}\``;
});

const value = mappedResults.join('\n');
if (index > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/notifications/Notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class Notifier {
...rawData.weeklyChallenges.map(w => w.id),
rawData.arbitration && rawData.arbitration.enemy
? `arbitration:${new Date(rawData.arbitration.expiry).getTime()}`
: `arbitration:0`,
: 'arbitration:0',
...rawData.twitter.map(t => t.id),
...(rawData.nightwave.active ? rawData.nightwave.activeChallenges.map(c => c.id) : []),
);
Expand Down

0 comments on commit e4d61c5

Please sign in to comment.