Skip to content

Commit 763e848

Browse files
ebm5025Ed Morgan
andauthored
Fixes from upgrade (#228)
* Reload private bot sheet data on timer (#224) * Use member cache instead of full fetch (#225) * Fixes from upgrade - auc names, perm checks, data refreshing --------- Co-authored-by: Ed Morgan <edwardmorgan706@gmail.com>
1 parent 3b89db2 commit 763e848

18 files changed

Lines changed: 216 additions & 130 deletions

src/db/invite-simple.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
PrimaryGeneratedColumn,
66
} from "typeorm";
77
import { Members } from "../features/invite-list/update-invite-action";
8+
import { GuildMember } from "discord.js";
89

910
@Entity({})
1011
export class InviteSimple {
@@ -28,12 +29,12 @@ export class InviteSimple {
2829
return score;
2930
}
3031

31-
public getDiscordDisplayName(members: Members) {
32-
const member = members?.get(this.discordId);
32+
public getDiscordDisplayName(members: GuildMember[]) {
33+
const member = members?.find(m => m.id === this.discordId);
3334
return member ? `**${member.displayName}** (<@${member.id}>)` : `**Left the server** (<@${this.discordId}>)`;
3435
}
3536

36-
public getRichLabel(members: Members) {
37+
public getRichLabel(members: GuildMember[]) {
3738
const displayName = this.getDiscordDisplayName(members);
3839
return `${this.altNote}${displayName} <t:${this.time}:R>`;
3940
}

src/features/bank-hours/remove-subcommand.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { updateBankRequestInfo } from "../bank-request-info/update-action";
99
import { BankHour } from "../../db/bank-hour";
1010
import { Subcommand } from "../../shared/command/subcommand";
1111
import { requireInteractionMemberRole } from "../../shared/command/util";
12+
import { getMember } from "../..";
1213

1314
enum Option {
1415
BankHourID = "hourid",
@@ -63,7 +64,7 @@ class Remove extends Subcommand {
6364
const weeklyBankAvailabilities = dataSource.getRepository(BankHour);
6465
const bankHour = await weeklyBankAvailabilities.findBy({});
6566
await Promise.all(
66-
bankHour.map(async (h) => interaction.guild?.members.fetch(h.userId))
67+
bankHour.map(async (h) => getMember(h.userId))
6768
);
6869
return bankHour?.map((h) => ({
6970
name: `${

src/features/bp/request-bot-button-command.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { knightRoleId, raiderRoleId } from "../../config";
1313
import { getClassAbreviation } from "../../shared/classes";
1414
import { PublicAccountsFactory } from "../../services/bot/bot-factory";
1515
import { log } from "../../shared/logger";
16+
import { getMember } from "../..";
1617

1718
export class RequestBotButtonCommand extends ButtonCommand {
1819
constructor(name: string) {
@@ -30,7 +31,7 @@ export class RequestBotButtonCommand extends ButtonCommand {
3031

3132
const name = interaction.customId.split("_")[1];
3233
try {
33-
const guildUser = await interaction.guild?.members.fetch(
34+
const guildUser = await getMember(
3435
interaction.user.id
3536
);
3637
log(

src/features/invite-list/cleanup-invites-command.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { InviteSimple } from "../../db/invite-simple";
66
import { ButtonCommand } from "../../shared/command/button-command";
77
import { requireInteractionMemberPermission } from "../../shared/command/util";
88
import { updateInviteListInfo } from "./update-invite-action";
9+
import { getMembers } from "../..";
910

1011
const SECONDS = 1000;
1112
const MINUTES = 60 * SECONDS;
@@ -29,7 +30,7 @@ class CleanupInvitesCommand extends ButtonCommand {
2930

3031
const [altInvites, mainInvites] = partition(oldInvites, (o) => o.alt);
3132

32-
await interaction.guild?.members.fetch();
33+
await getMembers();
3334
await this.removeMains(mainInvites, interaction);
3435
await this.removeAlts(altInvites, interaction);
3536
const removed = await this.removeFromInviteList(oldInvites);

src/features/invite-list/ping-invite-list-button-command.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
PermissionFlagsBits,
66
Permissions,
77
} from "discord.js";
8-
import { getGuild } from "../..";
8+
import { getGuild, getMember } from "../..";
99
import { inviteListChannelId } from "../../config";
1010
import { dataSource } from "../../db/data-source";
1111
import { InviteSimple } from "../../db/invite-simple";
@@ -37,10 +37,10 @@ export const getAttentionMessage = async (users: string[]) => {
3737
const guild = await getGuild();
3838
const statuses = await Promise.all(
3939
users.map(async (user) => {
40-
const { presence } = await guild.members.fetch({
40+
const { presence } = await getMember(
4141
user,
42-
withPresences: true,
43-
});
42+
true
43+
);
4444
return {
4545
user,
4646
status: getPresenceIcon(presence?.status),

src/features/invite-list/update-invite-action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Please post your best availability in this channel (including time zone) and we
117117
);
118118
}
119119

120-
private async getInviteEmbed(members: Members) {
120+
private async getInviteEmbed(members: GuildMember[]) {
121121
const needInvite = await dataSource.getRepository(InviteSimple).findBy({});
122122
return new EmbedBuilder({
123123
title: `Need Invite (${needInvite.length})`,

src/features/raid-bots/park-bot-button-command.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import { PublicAccountsFactory } from "../../services/bot/bot-factory";
1313
import { BOT_SPREADSHEET_COLUMNS } from "../../services/sheet-updater/public-sheet";
1414
import { log } from "../../shared/logger";
15+
import { getMember } from "../..";
1516

1617
export class ParkBotButtonCommand extends ButtonCommand {
1718
constructor(name: string) {
@@ -27,7 +28,7 @@ import {
2728
});
2829

2930
const name = interaction.customId.split("_")[1];
30-
const guildUser = await interaction.guild?.members.fetch(
31+
const guildUser = await getMember(
3132
interaction.user.id
3233
);
3334
log(`${guildUser?.nickname || guildUser?.user.username} clicked bot park button for ${name}`);

src/features/raid-bots/park-subcommand.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { LocationService } from "../../services/location";
55
import { PublicAccountsFactory } from "../../services/bot/bot-factory";
66
import { BOT_SPREADSHEET_COLUMNS } from "../../services/sheet-updater/public-sheet";
77
import { log } from "../../shared/logger"
8+
import { getMember } from "../..";
89

910
export enum Option {
1011
Name = "name",
@@ -45,7 +46,7 @@ export class ParkSubcommand extends Subcommand {
4546
`${name} was released in its previous location`
4647
);
4748
}
48-
const guildUser = await interaction.guild?.members.fetch(
49+
const guildUser = await getMember(
4950
interaction.user.id
5051
);
5152
log(

src/features/raid-bots/requestclass-subcommand.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { LocationService } from "../../services/location";
1515
import { PublicAccountsFactory } from "../../services/bot/bot-factory";
1616
import { BOT_SPREADSHEET_COLUMNS } from "../../services/sheet-updater/public-sheet";
1717
import { log } from "../../shared/logger";
18+
import { getMember } from "../..";
1819

1920

2021
export enum Option {
@@ -48,7 +49,7 @@ export class RequestClassSubcommand extends Subcommand {
4849
const release = await this.mutex.acquire();
4950
const publicAccounts = PublicAccountsFactory.getService();
5051

51-
const guildUser = await interaction.guild?.members.fetch(
52+
const guildUser = await getMember(
5253
interaction.user.id
5354
);
5455

src/features/raid-bots/requestzone-subcommand.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { LocationService } from "../../services/location";
1515
import { PublicAccountsFactory } from "../../services/bot/bot-factory";
1616
import { BOT_SPREADSHEET_COLUMNS } from "../../services/sheet-updater/public-sheet";
1717
import { log } from "../../shared/logger";
18+
import { getMember } from "../..";
1819

1920
export enum Option {
2021
Location = "location",
@@ -40,7 +41,7 @@ export class RequestZoneSubcommand extends Subcommand {
4041
const release = await this.mutex.acquire();
4142
const publicAccounts = PublicAccountsFactory.getService();
4243

43-
const guildUser = await interaction.guild?.members.fetch(
44+
const guildUser = await getMember(
4445
interaction.user.id
4546
);
4647

0 commit comments

Comments
 (0)