Skip to content

Commit 37d5011

Browse files
committed
Update for discord.js deprecations
1 parent a7f42b7 commit 37d5011

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async function main() {
6666
// maintain database of ids
6767
// suggestion tracker: Content, author, votes, link.
6868

69-
client.on("ready", () => {
69+
client.on("clientReady", () => {
7070
M.log(`Logged in as ${client.user!.tag}`);
7171
});
7272

src/modules/wheatley/components/pin-archive.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,22 @@ export default class PinArchive extends BotComponent {
108108
}
109109
}
110110

111+
async fetch_all_pins(channel: Discord.GuildTextBasedChannel) {
112+
const current_pins = new Map<string, Discord.Message<true>>();
113+
let before: Date | undefined = undefined;
114+
while (true) {
115+
const { items, hasMore } = await channel.messages.fetchPins(before ? { before } : undefined);
116+
for (const pin of items) {
117+
current_pins.set(pin.message.id, pin.message);
118+
}
119+
if (!hasMore || items.length === 0) {
120+
break;
121+
}
122+
before = items[items.length - 1].pinnedAt;
123+
}
124+
return current_pins;
125+
}
126+
111127
async update_for_channel(channel: Discord.TextBasedChannel) {
112128
if (
113129
channel.isDMBased() ||
@@ -116,13 +132,13 @@ export default class PinArchive extends BotComponent {
116132
) {
117133
return;
118134
}
119-
const current_pins = await channel.messages.fetchPinned();
135+
const current_pins = await this.fetch_all_pins(channel);
120136
const database_current_pins = await this.database.pins
121137
.find({ channel: channel.id, current_pin: true })
122138
.toArray();
123139
// two things to handle: new pins and pins that are now no longer pins
124140
// ensure current pins are marked as such
125-
for (const [_, message] of current_pins) {
141+
for (const [, message] of current_pins) {
126142
const res = await this.database.pins.updateOne(
127143
{ channel: channel.id, message: message.id },
128144
{ $set: { current_pin: true } },

src/wheatley.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export class Wheatley {
194194
setup_metrics_server(config.metrics.port, config.metrics.hostname);
195195
}
196196

197-
this.client.on("ready", () => {
197+
this.client.on("clientReady", () => {
198198
M.log("Wheatley starting in the following guilds:");
199199
(async () => {
200200
await this.client.guilds.fetch();

0 commit comments

Comments
 (0)