Application Reviewing Bot Does What An Application Reviewing Bot Should Do: Accept Applications
This commit is contained in:
parent
7dcc0c2cc4
commit
199c2dba16
3 changed files with 122 additions and 0 deletions
|
@ -1,10 +1,15 @@
|
||||||
export const Constants = {
|
export const Constants = {
|
||||||
|
APPROVED_CHANNEL_ID: "1371073576903376896",
|
||||||
PENDING_CHANNEL_ID: "1370539719842070683",
|
PENDING_CHANNEL_ID: "1370539719842070683",
|
||||||
REJECTION_CHANNEL_ID: "1371073658403164261",
|
REJECTION_CHANNEL_ID: "1371073658403164261",
|
||||||
REVIEWER_ROLE_ID: "1375617676139040909",
|
REVIEWER_ROLE_ID: "1375617676139040909",
|
||||||
MOD_ROLE_ID: "1370539692143153152",
|
MOD_ROLE_ID: "1370539692143153152",
|
||||||
MANAGER_ROLE_ID: "1370539689659863091",
|
MANAGER_ROLE_ID: "1370539689659863091",
|
||||||
OWNER_ID: "886685857560539176",
|
OWNER_ID: "886685857560539176",
|
||||||
|
HERE_FOR_TAG: "1370898806249623643",
|
||||||
|
HERE_TO_CHAT: "1370898841309544589",
|
||||||
|
CAN_BOOST: "1371796535557361715",
|
||||||
|
FRIEND_ROLES: ["1370539694391165088", "1370539700862980117"],
|
||||||
COLORS: {
|
COLORS: {
|
||||||
NEW_REQ: 0xaaaaff,
|
NEW_REQ: 0xaaaaff,
|
||||||
BAD: 0xffaaaa,
|
BAD: 0xffaaaa,
|
||||||
|
|
116
src/joinRequestActions/accept.tsx
Normal file
116
src/joinRequestActions/accept.tsx
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
import { ComponentTypes, InteractionTypes, MessageFlags } from "oceanic.js";
|
||||||
|
import { client } from "..";
|
||||||
|
import { canUser } from "../utils/utils";
|
||||||
|
import { selfappReq } from "../utils/selfappReq";
|
||||||
|
import { Response } from "~/utils/types";
|
||||||
|
import { db } from "~/utils/database";
|
||||||
|
import { ComponentMessage } from "components-jsx/ComponentMessage";
|
||||||
|
import { Container } from "components-jsx/Container";
|
||||||
|
import { Divider } from "components-jsx/Divider";
|
||||||
|
import { TextDisplay } from "components-jsx/TextDisplay";
|
||||||
|
import { ApplicationContent } from "~/components/ApplicationContent";
|
||||||
|
import { User } from "~/components/User";
|
||||||
|
import { Constants } from "~/Constants";
|
||||||
|
|
||||||
|
client.on("interactionCreate", async (interaction) => {
|
||||||
|
if (interaction.type === InteractionTypes.MESSAGE_COMPONENT)
|
||||||
|
if (interaction.data.componentType === ComponentTypes.BUTTON) {
|
||||||
|
if (interaction.data.customID.split("-")[0] === "accept") {
|
||||||
|
await interaction.defer(MessageFlags.EPHEMERAL);
|
||||||
|
if (
|
||||||
|
!canUser(interaction.member!, "review") ||
|
||||||
|
(!canUser(interaction.member!, "owner") &&
|
||||||
|
interaction.data.customID.includes("friend"))
|
||||||
|
)
|
||||||
|
return await interaction.createFollowup({
|
||||||
|
flags: MessageFlags.EPHEMERAL,
|
||||||
|
content: "💢 nop"
|
||||||
|
});
|
||||||
|
|
||||||
|
const application = await db.get(
|
||||||
|
"SELECT * FROM applications WHERE message_id=?",
|
||||||
|
interaction.message.id
|
||||||
|
);
|
||||||
|
|
||||||
|
await db.run(
|
||||||
|
"DELETE FROM applications WHERE id=?",
|
||||||
|
application.id
|
||||||
|
);
|
||||||
|
await client.rest.channels.deleteMessage(
|
||||||
|
application.channel_id,
|
||||||
|
application.message_id
|
||||||
|
);
|
||||||
|
|
||||||
|
await selfappReq(
|
||||||
|
`/guilds/${interaction.guildID}/requests/id/${application.id}`,
|
||||||
|
"PATCH",
|
||||||
|
{
|
||||||
|
action: "APPROVED"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const user = await client.rest.users.get(application.user_id);
|
||||||
|
await interaction.createFollowup({
|
||||||
|
flags: MessageFlags.EPHEMERAL,
|
||||||
|
content: `<:blobcatgreen:1375806000312881233> Approved @${user.tag}'s join request!`
|
||||||
|
});
|
||||||
|
|
||||||
|
const response: Response = JSON.parse(application.responses);
|
||||||
|
|
||||||
|
const msg = await client.rest.channels.createMessage(
|
||||||
|
Constants.APPROVED_CHANNEL_ID,
|
||||||
|
<ComponentMessage>
|
||||||
|
<Container accentColor={Constants.COLORS.GOOD}>
|
||||||
|
<TextDisplay>## Join request accepted</TextDisplay>
|
||||||
|
<Divider />
|
||||||
|
<User user={user} />
|
||||||
|
<Divider />
|
||||||
|
<ApplicationContent
|
||||||
|
response={response}
|
||||||
|
includeDetails={true}
|
||||||
|
/>
|
||||||
|
</Container>
|
||||||
|
</ComponentMessage>
|
||||||
|
);
|
||||||
|
|
||||||
|
const member = await client.rest.guilds.getMember(
|
||||||
|
interaction.guildID!,
|
||||||
|
user.id
|
||||||
|
);
|
||||||
|
client.rest.guilds.editMember(interaction.guildID!, user.id, {
|
||||||
|
reason: `${user.tag}'s application has been accepted`,
|
||||||
|
roles: (() => {
|
||||||
|
const roles = member.roles;
|
||||||
|
response.hereFor.includes("tag") &&
|
||||||
|
roles.push(Constants.HERE_FOR_TAG);
|
||||||
|
response.hereFor.includes("chat") &&
|
||||||
|
roles.push(Constants.HERE_TO_CHAT);
|
||||||
|
response.canBoost && roles.push(Constants.CAN_BOOST);
|
||||||
|
interaction.data.customID.includes("friend") &&
|
||||||
|
roles.push(...Constants.FRIEND_ROLES);
|
||||||
|
return roles;
|
||||||
|
})()
|
||||||
|
});
|
||||||
|
|
||||||
|
await client.rest.request({
|
||||||
|
auth: `Bot ${process.env.BOT_TOKEN}`,
|
||||||
|
method: "POST",
|
||||||
|
path: `/channels/${application.thread_id}/messages`,
|
||||||
|
json: {
|
||||||
|
content: "",
|
||||||
|
flags: 0,
|
||||||
|
message_reference: {
|
||||||
|
channel_id: msg.channelID,
|
||||||
|
guild_id: msg.guildID!,
|
||||||
|
message_id: msg.id,
|
||||||
|
type: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await client.rest.channels.edit(application.thread_id, {
|
||||||
|
locked: true,
|
||||||
|
reason: `${user.tag}'s application has been accepted`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
|
@ -27,6 +27,7 @@ import { ApplicationContent } from "./components/ApplicationContent";
|
||||||
|
|
||||||
import("./joinRequestActions/lockUnlock");
|
import("./joinRequestActions/lockUnlock");
|
||||||
import("./joinRequestActions/interview");
|
import("./joinRequestActions/interview");
|
||||||
|
import("./joinRequestActions/accept");
|
||||||
|
|
||||||
export async function setupJoinRequestHandler(shard: Shard) {
|
export async function setupJoinRequestHandler(shard: Shard) {
|
||||||
shard.ws?.on("message", async (d) => {
|
shard.ws?.on("message", async (d) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue