Skip to content

Commit

Permalink
Re-apply discord.js-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel Moschkin committed Oct 29, 2023
1 parent e20ff84 commit 94aec32
Show file tree
Hide file tree
Showing 41 changed files with 7,955 additions and 1,564 deletions.
4,314 changes: 3,092 additions & 1,222 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,30 @@
"dependencies": {
"as-table": "^1.0.55",
"chokidar": "^3.4.0",
"discord-api-types": "^0.18.1",
"discord.js": "git+https://github.com/discordjs/discord.js.git#f8703e3e59839d7380795ecf719d5bac691860a4",
"discord-api-types": "^0.37.60",
"discord.js": "^14.13.0",
"dotenv": "^8.2.0",
"fuse.js": "^6.2.0",
"js-levenshtein": "^1.1.6",
"node-cache": "^5.1.1",
"node-fetch": "^2.6.1",
"pg": "^8.3.3",
"reflect-metadata": "^0.1.13",
"sequelize": "^6.3.3",
"sequelize-typescript": "^2.0.0-beta.0",
"sequelize": "^6.5.0",
"sequelize-typescript": "^2.0.0",
"sqlite3": "^5.0.0",
"winston": "^3.2.1",
"winston-daily-rotate-file": "^4.5.0",
"yargs": "^15.3.1"
},
"devDependencies": {
"@types/bluebird": "^3.5.32",
"@types/node": "^14.14.10",
"@types/js-levenshtein": "^1.1.1",
"@types/node": "^14.18.63",
"@types/node-fetch": "^2.5.7",
"@types/validator": "^13.1.0",
"@types/ws": "^7.4.4",
"@types/yargs": "^15.0.5",
"typescript": "^4.1.2"
"typescript": "^5.2.2"
}
}
6 changes: 3 additions & 3 deletions src/commands/associate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import { Message } from 'discord.js';
import { ApplicationCommandOptionType, Message } from 'discord.js';
import yargs from 'yargs';
import { loadProfile, createUserFromMessage, associateUser, getDbidFromDiscord, loadRemoteProfile } from '../utils/profile';
import { discordUserFromMessage, sendAndCache } from '../utils/discord';
Expand All @@ -11,7 +11,7 @@ async function asyncHandler(message: Message, dbid: string, devpull: boolean, ac
await new Promise<void>(resolve => setImmediate(() => resolve()));

let user = await createUserFromMessage(message);
if (devpull){
if (devpull || process.env.DEV_PULL_ALWAYS?.toString() === '1'){
if (process.env.NODE_ENV === 'production') {
sendAndCache(message, `This is a dev-only command.`, {asReply: true, ephemeral: true});
return;
Expand Down Expand Up @@ -81,7 +81,7 @@ class Associate implements Definitions.Command {
options = [
{
name: 'dbid',
type: 'STRING',
type: ApplicationCommandOptionType.String,
description: 'your DBID',
required: true
}
Expand Down
8 changes: 4 additions & 4 deletions src/commands/behold.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message } from 'discord.js';
import { ApplicationCommandOptionType, Message } from 'discord.js';
import yargs from 'yargs';

import { calculateBehold, isValidBehold } from '../utils/beholdcalc';
Expand Down Expand Up @@ -35,19 +35,19 @@ class Behold implements Definitions.Command {
options = [
{
name: 'url',
type: 'STRING',
type: ApplicationCommandOptionType.String,
description: 'address of a png or jpg image',
required: true,
},
{
name: 'threshold',
type: 'INTEGER',
type: ApplicationCommandOptionType.Integer,
description: 'lower the threshold for crew detection; the lower it is, the higher the chance for false positives',
required: false,
},
{
name: 'base',
type: 'BOOLEAN',
type: ApplicationCommandOptionType.Boolean,
description: 'ignore user profile if available',
required: false,
},
Expand Down
10 changes: 5 additions & 5 deletions src/commands/best.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message } from 'discord.js';
import { ApplicationCommandOptionType, Message } from 'discord.js';
import yargs from 'yargs';

import { DCData } from '../data/DCData';
Expand Down Expand Up @@ -59,7 +59,7 @@ class Best implements Definitions.Command {
options = [
{
name: 'type',
type: 'STRING',
type: ApplicationCommandOptionType.String,
description: 'type of search to do',
required: true,
choices: [
Expand All @@ -70,7 +70,7 @@ class Best implements Definitions.Command {
},
{
name: 'skill',
type: 'STRING',
type: ApplicationCommandOptionType.String,
description: 'skill to search',
required: true,
choices: [
Expand All @@ -84,7 +84,7 @@ class Best implements Definitions.Command {
},
{
name: 'secondskill',
type: 'STRING',
type: ApplicationCommandOptionType.String,
description: '(optional) second skill to search',
required: false,
choices: [
Expand All @@ -98,7 +98,7 @@ class Best implements Definitions.Command {
},
{
name: 'stars',
type: 'INTEGER',
type: ApplicationCommandOptionType.Integer,
description: 'limit the search to given number of stars or below',
required: false,
choices: [
Expand Down
131 changes: 109 additions & 22 deletions src/commands/cheapestfffe.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Message, MessageEmbed } from 'discord.js';
import { Message, EmbedBuilder, ApplicationCommandOptionType } from 'discord.js';
import yargs from 'yargs';

import { DCData } from '../data/DCData';
import { formatSources, formatRecipe } from '../utils/items';
import { colorFromRarity } from '../utils/crew';
import { colorFromRarity, formatCollectionName } from '../utils/crew';
import { getEmoteOrString, sendAndCache } from '../utils/discord';
import CONFIG from '../utils/config';
import { loadFullProfile, userFromMessage } from '../utils/profile';
import { loadFullProfile, toTimestamp, userFromMessage } from '../utils/profile';
import { getNeededItems } from '../utils/equipment';

function bonusName(bonus: string) {
Expand All @@ -20,6 +20,7 @@ function bonusName(bonus: string) {

async function asyncHandler(
message: Message,
fuse?: number
) {
// This is just to break up the flow and make sure any exceptions end up in the .catch, not thrown during yargs command execution
await new Promise<void>(resolve => setImmediate(() => resolve()));
Expand All @@ -36,12 +37,38 @@ async function asyncHandler(
let profileItems = profile.player.character.items;
let candidatesForImmortalisation = profileCrew.filter((c: any) => {
if (c.level === 100) {
// let needed = getNeededItems(c.symbol, c.level);
// if (!needed) {
// return false;
// }
// return true;
return false;
}
if (c.rarity === crew.find((d) => d.symbol === c.symbol)?.max_rarity) {
let findcrew = crew.find((d) => d.symbol === c.symbol);

if (!fuse) {
if (c.rarity === findcrew?.max_rarity) {
c.max_rarity = findcrew?.max_rarity;
return true;
}
else {
return false;
}
}

let fnum = 0;

if (typeof fuse === 'number') {
fnum = fuse;
}

if (c.rarity === (findcrew?.max_rarity ?? 0) - fnum) {
c.max_rarity = findcrew?.max_rarity;
return true;
}
return false;
else {
return false;
}
});

candidatesForImmortalisation = candidatesForImmortalisation.map((c: any) => {
Expand Down Expand Up @@ -77,43 +104,103 @@ async function asyncHandler(
requiredFactionItems,
craftCost: needed.craftCost,
}
}).sort((a: any, b: any) => a.requiredChronCost - b.requiredChronCost);
}).sort((a: any, b: any) => {
let r = 0;
if (!r) r = (b.rarity/b.max_rarity) - (a.rarity/a.max_rarity);
if (!r) r = a.requiredChronCost - b.requiredChronCost;
return r;
});


const embeds = candidatesForImmortalisation.slice(0, 5).map((can: any) => {
const matched = crew.find((crew) => crew.symbol === can.symbol);

const matched = crew.find((crew) => {
return crew.symbol === can.symbol
});

if (!matched) {
return;
}
return new MessageEmbed()
.setTitle(`${matched.name} (Level ${can.level})`)
.setDescription(`Missing item costs:`)
.setThumbnail(`${CONFIG.ASSETS_URL}${matched.imageUrlPortrait}`)
.setColor(colorFromRarity(matched.max_rarity))
.addField(getEmoteOrString(message, 'chrons', 'Chrons'), Math.round(can.requiredChronCost), true)
.addField(getEmoteOrString(message, 'shuttle', 'Faction'), `${can.requiredFactionItems} items`, true)
.addField(getEmoteOrString(message, 'credits', 'Credits'), can.craftCost, true)
.setFooter(`${matched.name} is in ${matched.collections.length === 0 ? 'no collections' : `the following collections: ${matched.collections.join(', ')}`}`);

return new EmbedBuilder()
.setTitle(`${matched.name} (Level ${can.level})`)
.setDescription(`Missing item costs:`)
.setThumbnail(`${CONFIG.ASSETS_URL}${matched.imageUrlPortrait}`)
.setColor(colorFromRarity(matched.max_rarity))
.addFields(
{
name: 'Rarity',
value: '⭐'.repeat(can.rarity) + '🌑'.repeat(matched.max_rarity - can.rarity),
inline: false
},
{
name: getEmoteOrString(message, 'chrons', 'Chrons'),
value: Math.round(can.requiredChronCost).toString(),
inline: true
},
{
name: getEmoteOrString(message, 'shuttle', 'Faction'),
value: `${can.requiredFactionItems} items`,
inline: true
},
{
name: getEmoteOrString(message, 'credits', 'Credits'),
value: can.craftCost.toString(),
inline: true
},
{
name: `${matched.name} is in the following collections: `,
value: !matched?.collections?.length ? 'No Collections' : matched?.collections?.map(c => formatCollectionName(c))?.join(", ") ?? '',
inline: true
}
)
//.setFooter({ text: `${matched.name} is in ${matched.collections.length === 0 ? 'no collections' : `the following collections: ${matched.collections.join(', ')}`}` });
});

sendAndCache(message,
`Cheapest candidates for immortalisation for **${user.profiles[0].captainName}**'s roster (last updated ${user.profiles[0].lastUpdate.toDateString()})`,
{ embeds }
);
if (fuse) {
sendAndCache(message,
`Cheapest candidates for immortalisation that need ${fuse} fuse${fuse === 1 ? '' : 's'} for **${user.profiles[0].captainName}**'s roster (last updated ${toTimestamp(profile.lastModified ?? user.profiles[0].lastUpdate)})`,
{ embeds }
);
}
else {
sendAndCache(message,
`Cheapest candidates for immortalisation for **${user.profiles[0].captainName}**'s roster (last updated ${toTimestamp(profile.lastModified ?? user.profiles[0].lastUpdate)})`,
{ embeds }
);
}
}

class CheapestFFFE implements Definitions.Command {
name = 'cheapestfffe';
command = 'cheapestfffe';
aliases = [];
describe = 'Shows FF crew on your roster who are cheapest to FE';
options = [{
name: 'fuseneed',
type: ApplicationCommandOptionType.Integer,
description: 'show crew with the specified needed fuses',
required: false,
default: 0,
choices: [
{ name: '1', value: 1 },
{ name: '2', value: 2 },
{ name: '3', value: 3 },
{ name: '4', value: 4 },
{ name: '5', value: 5 },
]
}]
builder(yp: yargs.Argv): yargs.Argv {
return yp;
return yp.option('fuseneed', {
alias: 'f',
desc: 'show crew with the specified needed fuses'
});
}

handler(args: yargs.Arguments) {
let message = <Message>args.message;
args.promisedResult = asyncHandler(message);
let fuse = args.fuseneed as number;
args.promisedResult = asyncHandler(message, fuse);
}
}

Expand Down
Loading

0 comments on commit 94aec32

Please sign in to comment.