55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import { ComponentTypes, InteractionTypes, MessageFlags } from "oceanic.js";
|
|
import { client } from "..";
|
|
import { db } from "../utils/database";
|
|
import { PendingApplicationMessage } from "../components/PendingApplicationMessage";
|
|
import { canUser } from "../utils/utils";
|
|
|
|
client.on("interactionCreate", async (interaction) => {
|
|
if (interaction.type === InteractionTypes.MESSAGE_COMPONENT)
|
|
if (interaction.data.componentType === ComponentTypes.BUTTON) {
|
|
if (!interaction.data.customID.includes("lock")) return;
|
|
|
|
if (!canUser(interaction.member!, "owner"))
|
|
return await interaction.createMessage({
|
|
flags: MessageFlags.EPHEMERAL,
|
|
content: "💢 nop"
|
|
});
|
|
|
|
const application = await db.get(
|
|
"SELECT * FROM applications WHERE message_id=?",
|
|
interaction.message.id
|
|
);
|
|
console.log(application);
|
|
|
|
switch (interaction.data.customID.split("-")[0]) {
|
|
case "lock": {
|
|
await interaction.editParent(
|
|
<PendingApplicationMessage
|
|
id={application.id}
|
|
response={JSON.parse(application.responses)}
|
|
user={await client.rest.users.get(
|
|
application.user_id
|
|
)}
|
|
locked={true}
|
|
threadID={application.thread_id}
|
|
/>
|
|
);
|
|
break;
|
|
}
|
|
case "unlock": {
|
|
await interaction.editParent(
|
|
<PendingApplicationMessage
|
|
id={application.id}
|
|
response={JSON.parse(application.responses)}
|
|
user={await client.rest.users.get(
|
|
application.user_id
|
|
)}
|
|
locked={false}
|
|
threadID={application.thread_id}
|
|
/>
|
|
);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
});
|