Initial Oceanic port (still unfinished), update packages, remove serverinfo and userinfo
This commit is contained in:
parent
bf90ae108a
commit
888f2f8b4a
49 changed files with 573 additions and 515 deletions
|
@ -1,4 +1,4 @@
|
|||
// eris doesn't come with a method to wait for interactions by default, so we make our own
|
||||
// oceanic doesn't come with a method to wait for interactions by default, so we make our own
|
||||
import { EventEmitter } from "events";
|
||||
|
||||
class InteractionCollector extends EventEmitter {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import InteractionCollector from "./awaitinteractions.js";
|
||||
import { ComponentInteraction } from "eris";
|
||||
import { ComponentInteraction } from "oceanic.js";
|
||||
|
||||
export default async (client, info, pages, timeout = 120000) => {
|
||||
const options = info.type === "classic" ? {
|
||||
messageReference: {
|
||||
channelID: info.channel.id,
|
||||
channelID: info.message.channelID,
|
||||
messageID: info.message.id,
|
||||
guildID: info.channel.guild ? info.channel.guild.id : undefined,
|
||||
guildID: info.message.guildID,
|
||||
failIfNotExists: false
|
||||
},
|
||||
allowedMentions: {
|
||||
|
@ -26,7 +26,7 @@ export default async (client, info, pages, timeout = 120000) => {
|
|||
name: "◀"
|
||||
},
|
||||
style: 1,
|
||||
custom_id: "back"
|
||||
customID: "back"
|
||||
},
|
||||
{
|
||||
type: 2,
|
||||
|
@ -36,7 +36,7 @@ export default async (client, info, pages, timeout = 120000) => {
|
|||
name: "▶"
|
||||
},
|
||||
style: 1,
|
||||
custom_id: "forward"
|
||||
customID: "forward"
|
||||
},
|
||||
{
|
||||
type: 2,
|
||||
|
@ -46,7 +46,7 @@ export default async (client, info, pages, timeout = 120000) => {
|
|||
name: "🔢"
|
||||
},
|
||||
style: 1,
|
||||
custom_id: "jump"
|
||||
customID: "jump"
|
||||
},
|
||||
{
|
||||
type: 2,
|
||||
|
@ -56,24 +56,24 @@ export default async (client, info, pages, timeout = 120000) => {
|
|||
name: "🗑"
|
||||
},
|
||||
style: 4,
|
||||
custom_id: "delete"
|
||||
customID: "delete"
|
||||
}
|
||||
]
|
||||
}]
|
||||
};
|
||||
let currentPage;
|
||||
if (info.type === "classic") {
|
||||
currentPage = await client.createMessage(info.message.channel.id, Object.assign(pages[page], options, pages.length > 1 ? components : {}));
|
||||
currentPage = await client.rest.channels.createMessage(info.message.channelID, Object.assign(pages[page], options, pages.length > 1 ? components : {}));
|
||||
} else {
|
||||
await info.interaction[info.interaction.acknowledged ? "editOriginalMessage" : "createMessage"](Object.assign(pages[page], pages.length > 1 ? components : {}));
|
||||
currentPage = await info.interaction.getOriginalMessage();
|
||||
await info.interaction[info.interaction.acknowledged ? "editOriginal" : "createMessage"](Object.assign(pages[page], pages.length > 1 ? components : {}));
|
||||
currentPage = await info.interaction.getOriginal();
|
||||
}
|
||||
|
||||
if (pages.length > 1) {
|
||||
const interactionCollector = new InteractionCollector(client, currentPage, ComponentInteraction, timeout);
|
||||
interactionCollector.on("interaction", async (interaction) => {
|
||||
if ((interaction.member ?? interaction.user).id === info.author.id) {
|
||||
switch (interaction.data.custom_id) {
|
||||
switch (interaction.data.customID) {
|
||||
case "back":
|
||||
await interaction.deferUpdate();
|
||||
page = page > 0 ? --page : pages.length - 1;
|
||||
|
@ -99,7 +99,7 @@ export default async (client, info, pages, timeout = 120000) => {
|
|||
type: 1,
|
||||
components: [{
|
||||
type: 3,
|
||||
custom_id: "seekDropdown",
|
||||
customID: "seekDropdown",
|
||||
placeholder: "Page Number",
|
||||
options: []
|
||||
}]
|
||||
|
@ -114,11 +114,11 @@ export default async (client, info, pages, timeout = 120000) => {
|
|||
}
|
||||
var promise;
|
||||
if (info.type === "classic") {
|
||||
promise = client.createMessage(info.message.channel.id, Object.assign({ content: "What page do you want to jump to?" }, {
|
||||
promise = client.rest.channels.createMessage(info.message.channelID, Object.assign({ content: "What page do you want to jump to?" }, {
|
||||
messageReference: {
|
||||
channelID: currentPage.channel.id,
|
||||
channelID: currentPage.channelID,
|
||||
messageID: currentPage.id,
|
||||
guildID: currentPage.channel.guild ? currentPage.channel.guild.id : undefined,
|
||||
guildID: currentPage.guildID,
|
||||
failIfNotExists: false
|
||||
},
|
||||
allowedMentions: {
|
||||
|
@ -132,9 +132,9 @@ export default async (client, info, pages, timeout = 120000) => {
|
|||
const dropdownCollector = new InteractionCollector(client, askMessage, ComponentInteraction, timeout);
|
||||
let ended = false;
|
||||
dropdownCollector.on("interaction", async (response) => {
|
||||
if (response.data.custom_id !== "seekDropdown") return;
|
||||
if (response.data.customID !== "seekDropdown") return;
|
||||
try {
|
||||
if (askMessage.channel.messages ? askMessage.channel.messages.has(askMessage.id) : await client.getMessage(askMessage.channel.id, askMessage.id).catch(() => undefined)) await askMessage.delete();
|
||||
await askMessage.delete();
|
||||
} catch {
|
||||
// no-op
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ export default async (client, info, pages, timeout = 120000) => {
|
|||
dropdownCollector.once("end", async () => {
|
||||
if (ended) return;
|
||||
try {
|
||||
if (askMessage.channel.messages ? askMessage.channel.messages.has(askMessage.id) : await client.getMessage(askMessage.channel.id, askMessage.id).catch(() => undefined)) await askMessage.delete();
|
||||
await askMessage.delete();
|
||||
} catch {
|
||||
// no-op
|
||||
}
|
||||
|
@ -159,7 +159,11 @@ export default async (client, info, pages, timeout = 120000) => {
|
|||
case "delete":
|
||||
await interaction.deferUpdate();
|
||||
interactionCollector.emit("end", true);
|
||||
if (currentPage.channel.messages ? currentPage.channel.messages.has(currentPage.id) : await client.getMessage(currentPage.channel.id, currentPage.id).catch(() => undefined)) await currentPage.delete();
|
||||
try {
|
||||
await currentPage.delete();
|
||||
} catch {
|
||||
// no-op
|
||||
}
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
|
@ -172,8 +176,10 @@ export default async (client, info, pages, timeout = 120000) => {
|
|||
for (const index of components.components[0].components.keys()) {
|
||||
components.components[0].components[index].disabled = true;
|
||||
}
|
||||
if (currentPage.channel.messages ? currentPage.channel.messages.has(currentPage.id) : await client.getMessage(currentPage.channel.id, currentPage.id).catch(() => undefined)) {
|
||||
try {
|
||||
await currentPage.edit(components);
|
||||
} catch {
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue