Add command to add servers from invites with eligibility check
This commit is contained in:
parent
3b09d2d679
commit
f13695c524
7 changed files with 151 additions and 39 deletions
46
backend/src/plugins/BotControl/functions/isEligible.ts
Normal file
46
backend/src/plugins/BotControl/functions/isEligible.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
import { User } from "discord.js";
|
||||
import { BotControlPluginType } from "../types";
|
||||
import { GlobalPluginData } from "knub";
|
||||
import { GuildInvite } from "../../../utils";
|
||||
|
||||
const REQUIRED_MEMBER_COUNT = 5000;
|
||||
|
||||
export async function isEligible(
|
||||
pluginData: GlobalPluginData<BotControlPluginType>,
|
||||
user: User,
|
||||
invite: GuildInvite,
|
||||
): Promise<{ result: boolean; explanation: string }> {
|
||||
if ((await pluginData.state.apiPermissionAssignments.getByUserId(user.id)).length) {
|
||||
return {
|
||||
result: true,
|
||||
explanation: "User is an existing bot operator",
|
||||
};
|
||||
}
|
||||
|
||||
if (invite.guild.features.includes("PARTNERED")) {
|
||||
return {
|
||||
result: true,
|
||||
explanation: "Server is partnered",
|
||||
};
|
||||
}
|
||||
|
||||
if (invite.guild.features.includes("VERIFIED")) {
|
||||
return {
|
||||
result: true,
|
||||
explanation: "Server is verified",
|
||||
};
|
||||
}
|
||||
|
||||
const memberCount = invite.memberCount || 0;
|
||||
if (memberCount >= REQUIRED_MEMBER_COUNT) {
|
||||
return {
|
||||
result: true,
|
||||
explanation: `Server has ${memberCount} members, which is equal or higher than the required ${REQUIRED_MEMBER_COUNT}`,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
result: false,
|
||||
explanation: "Server does not meet requirements",
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue