Add command to add servers from invites with eligibility check

This commit is contained in:
Dragory 2021-09-05 17:07:50 +03:00
parent 3b09d2d679
commit f13695c524
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
7 changed files with 151 additions and 39 deletions

View 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",
};
}