3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 20:35:02 +00:00

Start move to d.js

This commit is contained in:
Dark 2021-05-31 03:30:55 +02:00
parent a9e0466e33
commit 9fc045cd38
No known key found for this signature in database
GPG key ID: 384C4B4F5B1E25A8
17 changed files with 339 additions and 6317 deletions

View file

@ -1,4 +1,4 @@
import { Client, Emoji, MemberPartial, Message, MessageContent, TextableChannel } from "eris";
import { APIMessage, Client, Message, MessageReaction, PartialUser, TextChannel, User } from "discord.js";
import { Awaitable } from "knub/dist/utils";
import { MINUTES, noop } from "../utils";
import Timeout = NodeJS.Timeout;
@ -17,19 +17,19 @@ const defaultOpts: PaginateMessageOpts = {
export async function createPaginatedMessage(
client: Client,
channel: TextableChannel,
channel: TextChannel | User,
totalPages: number,
loadPageFn: LoadPageFn,
opts: Partial<PaginateMessageOpts> = {},
): Promise<Message> {
const fullOpts = { ...defaultOpts, ...opts } as PaginateMessageOpts;
const firstPageContent = await loadPageFn(1);
const message = await channel.createMessage(firstPageContent);
const message = await channel.send(firstPageContent);
let page = 1;
let pageLoadId = 0; // Used to avoid race conditions when rapidly switching pages
const reactionListener = async (reactionMessage: Message, emoji: Emoji, reactor: MemberPartial) => {
if (reactionMessage.id !== message.id) {
const reactionListener = async (reactionMessage: MessageReaction, reactor: User | PartialUser) => {
if (reactionMessage.message.id !== message.id) {
return;
}
@ -37,14 +37,14 @@ export async function createPaginatedMessage(
return;
}
if (reactor.id === client.user.id) {
if (reactor.id === client.user!.id) {
return;
}
let pageDelta = 0;
if (emoji.name === "⬅️") {
if (reactionMessage.emoji.name === "⬅️") {
pageDelta = -1;
} else if (emoji.name === "➡️") {
} else if (reactionMessage.emoji.name === "➡️") {
pageDelta = 1;
}
@ -65,7 +65,7 @@ export async function createPaginatedMessage(
}
message.edit(newPageContent).catch(noop);
message.removeReaction(emoji.name, reactor.id);
reactionMessage.users.remove(reactor.id).catch(noop);
refreshTimeout();
};
client.on("messageReactionAdd", reactionListener);
@ -76,7 +76,7 @@ export async function createPaginatedMessage(
const refreshTimeout = () => {
clearTimeout(timeout);
timeout = setTimeout(() => {
message.removeReactions().catch(noop);
message.reactions.removeAll().catch(noop);
client.off("messageReactionAdd", reactionListener);
}, fullOpts.timeout);
};
@ -84,8 +84,8 @@ export async function createPaginatedMessage(
refreshTimeout();
// Add reactions
message.addReaction("⬅️").catch(noop);
message.addReaction("➡️").catch(noop);
message.react("⬅️").catch(noop);
message.react("➡️").catch(noop);
return message;
}