Skip to content

Commit 5c1475c

Browse files
authored
Update bot wom types (#295)
1 parent 6d4e189 commit 5c1475c

33 files changed

+162
-161
lines changed

hack.d.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"@sapphire/discord.js-utilities": "^7.1.6",
4848
"@sentry/node": "^7.28.0",
4949
"@sentry/tracing": "^7.28.0",
50-
"@wise-old-man/utils": "^3.3.15",
50+
"@wise-old-man/utils": "^4.0.4",
5151
"axios": "^1.9.0",
5252
"canvas": "^2.6.1",
5353
"cors": "^2.8.5",

src/commands/autocomplete.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CountryProps, getMetricName, METRICS, PeriodProps, PERIODS } from '@wise-old-man/utils';
1+
import { CountryProps, MetricProps, METRICS, PeriodProps, PERIODS } from '@wise-old-man/utils';
22
import { CUSTOM_COMMANDS } from './custom';
33

44
interface AutoCompleteOption {
@@ -30,7 +30,7 @@ export function getPeriodOptions(currentValue: string): AutoCompleteOption[] {
3030
export function getMetricOptions(currentValue: string): AutoCompleteOption[] {
3131
return METRICS.filter(metric => (!currentValue ? true : matches(currentValue, metric))).map(
3232
metric => ({
33-
name: getMetricName(metric),
33+
name: MetricProps[metric].name,
3434
value: metric
3535
})
3636
);

src/commands/instances/general/HelpCommand.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { GroupDetails } from '@wise-old-man/utils';
1+
import { GroupDetailsResponse } from '@wise-old-man/utils';
22
import { ApplicationCommandOptionType, ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';
3-
import config from '../../../config';
43
import { CUSTOM_COMMANDS } from '../../../commands/custom';
4+
import config from '../../../config';
55
import prisma, { getServer } from '../../../services/prisma';
66
import womClient from '../../../services/wiseoldman';
77
import {
88
Command,
99
CommandConfig,
10+
CommandError,
1011
NotificationName,
11-
NotificationType,
12-
CommandError
12+
NotificationType
1313
} from '../../../utils';
1414

1515
const BOT_URL = 'https://bot.wiseoldman.net';
@@ -72,7 +72,7 @@ class HelpCommand extends Command {
7272
return;
7373
}
7474

75-
let group: GroupDetails | null = null;
75+
let group: GroupDetailsResponse | null = null;
7676

7777
if (groupId && groupId > -1) {
7878
try {

src/commands/instances/group/GroupCompetitionCommand.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import {
2-
CompetitionDetails,
2+
CompetitionDetailsResponse,
33
CompetitionStatus,
44
CompetitionStatusProps,
55
CompetitionType,
66
CompetitionTypeProps,
77
formatNumber,
8-
isCompetitionStatus,
98
MetricProps
109
} from '@wise-old-man/utils';
1110
import { ApplicationCommandOptionType, ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';
@@ -59,8 +58,11 @@ class GroupCompetitionCommand extends Command {
5958

6059
// Extract the "status" param, or fallback to "ongoing"
6160
const statusParam = interaction.options.getString('status');
61+
6262
const status =
63-
statusParam !== null && isCompetitionStatus(statusParam) ? statusParam : CompetitionStatus.ONGOING;
63+
statusParam !== null && statusParam in CompetitionStatusProps
64+
? (statusParam as CompetitionStatus)
65+
: CompetitionStatus.ONGOING;
6466

6567
// Extract the "competition_id" param, or fallback to the default competition
6668
const competitionIdParam = interaction.options.getInteger('competition_id');
@@ -82,21 +84,21 @@ class GroupCompetitionCommand extends Command {
8284
}
8385
}
8486

85-
function getFooterDate(competition: CompetitionDetails) {
87+
function getFooterDate(competition: CompetitionDetailsResponse) {
8688
return getCompetitionStatus(competition) === CompetitionStatus.UPCOMING
8789
? new Date(competition.startsAt)
8890
: new Date(competition.endsAt);
8991
}
9092

91-
function getFooterLabel(competition: CompetitionDetails) {
93+
function getFooterLabel(competition: CompetitionDetailsResponse) {
9294
const status = getCompetitionStatus(competition);
9395

9496
if (status === CompetitionStatus.UPCOMING) return 'Starts at';
9597
if (status === CompetitionStatus.ONGOING) return 'Ends at';
9698
return 'Ended at';
9799
}
98100

99-
function buildContent(competition: CompetitionDetails) {
101+
function buildContent(competition: CompetitionDetailsResponse) {
100102
const { metric, type, participations, participantCount } = competition;
101103
const timeLeft = getCompetitionTimeLeft(competition).split(' ');
102104

@@ -135,7 +137,7 @@ function buildContent(competition: CompetitionDetails) {
135137
return lines.join('\n');
136138
}
137139

138-
function aggregateTeamData(competition: CompetitionDetails) {
140+
function aggregateTeamData(competition: CompetitionDetailsResponse) {
139141
const participants = competition.participations;
140142

141143
if (!participants || participants.length === 0) return [];

src/commands/instances/group/GroupCompetitionsCommand.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {
2-
CompetitionListItem,
2+
CompetitionResponse,
33
CompetitionStatus,
44
CompetitionTypeProps,
5-
GroupDetails
5+
GroupDetailsResponse
66
} from '@wise-old-man/utils';
77
import { ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';
8-
import womClient, { getCompetitionStatus, getCompetitionTimeLeft } from '../../../services/wiseoldman';
98
import config from '../../../config';
9+
import womClient, { getCompetitionStatus, getCompetitionTimeLeft } from '../../../services/wiseoldman';
1010
import { Command, CommandConfig, CommandError, getEmoji, getLinkedGroupId } from '../../../utils';
1111
import { createPaginatedEmbed } from '../../pagination';
1212

@@ -71,7 +71,7 @@ class GroupCompetitionsCommand extends Command {
7171
}
7272
}
7373

74-
function buildCompetitionsList(competitions: CompetitionListItem[]) {
74+
function buildCompetitionsList(competitions: CompetitionResponse[]) {
7575
return competitions
7676
.map(c => ({ ...c, status: getCompetitionStatus(c) }))
7777
.sort(
@@ -95,7 +95,7 @@ function buildCompetitionsList(competitions: CompetitionListItem[]) {
9595
});
9696
}
9797

98-
function buildPages(group: GroupDetails, competitions: CompetitionListItem[]) {
98+
function buildPages(group: GroupDetailsResponse, competitions: CompetitionResponse[]) {
9999
const competitionsList = buildCompetitionsList(competitions);
100100
const pageCount = Math.ceil(competitionsList.length / COMPETITIONS_PER_PAGE);
101101

src/commands/instances/group/GroupGainedCommand.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import {
22
formatNumber,
3-
getMetricName,
43
isMetric,
54
Metric,
5+
MetricProps,
66
parsePeriodExpression,
77
PeriodProps
88
} from '@wise-old-man/utils';
99
import { ApplicationCommandOptionType, ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';
10-
import womClient, { parseMetricAbbreviation } from '../../../services/wiseoldman';
1110
import config from '../../../config';
12-
import { Command, CommandConfig, CommandError, getEmoji, getLinkedGroupId, bold } from '../../../utils';
11+
import womClient, { parseMetricAbbreviation } from '../../../services/wiseoldman';
12+
import { bold, Command, CommandConfig, CommandError, getEmoji, getLinkedGroupId } from '../../../utils';
1313

1414
const CONFIG: CommandConfig = {
1515
name: 'gained',
@@ -61,12 +61,12 @@ class GroupGainedCommand extends Command {
6161
period in PeriodProps
6262
? `period=${period}`
6363
: `startDate=${new Date(
64-
Date.now() - parsePeriodExpression(period).durationMs
64+
Date.now() - parsePeriodExpression(period)!.durationMs
6565
).toISOString()}&endDate=${new Date().toISOString()}`;
6666

6767
const response = new EmbedBuilder()
6868
.setColor(config.visuals.blue)
69-
.setTitle(`${getEmoji(metric)} ${group.name} ${getMetricName(metric)} gains (${period})`)
69+
.setTitle(`${getEmoji(metric)} ${group.name} ${MetricProps[metric].name} gains (${period})`)
7070
.setURL(`https://wiseoldman.net/groups/${groupId}/gained?${urlPeriod}&metric=${metric}`)
7171
.setFooter({ text: `Tip: Try /group gained metric: zulrah period: day` })
7272
.setDescription(gainedList);

src/commands/instances/group/GroupHiscoresCommand.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { formatNumber, getMetricName, GroupHiscoresEntry, Metric } from '@wise-old-man/utils';
1+
import { formatNumber, GroupHiscoresEntryResponse, Metric, MetricProps } from '@wise-old-man/utils';
22
import { ApplicationCommandOptionType, ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';
3-
import womClient, { parseMetricAbbreviation } from '../../../services/wiseoldman';
43
import config from '../../../config';
4+
import womClient, { parseMetricAbbreviation } from '../../../services/wiseoldman';
55
import { bold, Command, CommandConfig, CommandError, getEmoji, getLinkedGroupId } from '../../../utils';
66

77
const CONFIG: CommandConfig = {
@@ -41,7 +41,7 @@ class GroupHiscoresCommand extends Command {
4141

4242
const response = new EmbedBuilder()
4343
.setColor(config.visuals.blue)
44-
.setTitle(`${getEmoji(metric)} ${group.name} ${getMetricName(metric)} hiscores`)
44+
.setTitle(`${getEmoji(metric)} ${group.name} ${MetricProps[metric].name} hiscores`)
4545
.setDescription(hiscoresList)
4646
.setURL(`https://wiseoldman.net/groups/${groupId}/hiscores?metric=${metric}`)
4747
.setFooter({ text: `Tip: Try /group hiscores metric: zulrah` });
@@ -50,7 +50,7 @@ class GroupHiscoresCommand extends Command {
5050
}
5151
}
5252

53-
function getValue(result: GroupHiscoresEntry): string {
53+
function getValue(result: GroupHiscoresEntryResponse): string {
5454
if ('level' in result.data) {
5555
return `${result.data.level} (${formatNumber(result.data.experience || 0, true)})`;
5656
}

src/commands/instances/group/GroupRecordsCommand.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import {
22
formatNumber,
3-
getMetricName,
43
isMetric,
54
isPeriod,
65
Metric,
6+
MetricProps,
77
Period,
88
PeriodProps,
99
PERIODS
1010
} from '@wise-old-man/utils';
1111
import { ApplicationCommandOptionType, ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';
12-
import womClient, { parseMetricAbbreviation } from '../../../services/wiseoldman';
1312
import config from '../../../config';
13+
import womClient, { parseMetricAbbreviation } from '../../../services/wiseoldman';
1414
import { bold, Command, CommandConfig, CommandError, getEmoji, getLinkedGroupId } from '../../../utils';
1515

1616
const CONFIG: CommandConfig = {
@@ -60,7 +60,7 @@ class GroupRecordsCommand extends Command {
6060

6161
const response = new EmbedBuilder()
6262
.setColor(config.visuals.blue)
63-
.setTitle(`${getEmoji(metric)} ${group.name} ${getMetricName(metric)} records (${period})`)
63+
.setTitle(`${getEmoji(metric)} ${group.name} ${MetricProps[metric].name} records (${period})`)
6464
.setDescription(recordsList)
6565
.setURL(`https://wiseoldman.net/groups/${groupId}/records?period=${period}&metric=${metric}`)
6666
.setFooter({ text: `Tip: Try /group records metric: zulrah period: day` });

0 commit comments

Comments
 (0)