Add dev command to check server eligibility
This commit is contained in:
parent
5f3c94d064
commit
e57175dcc3
3 changed files with 63 additions and 0 deletions
|
@ -17,10 +17,12 @@ import { Configs } from "../../data/Configs";
|
|||
import { ApiPermissionAssignments } from "../../data/ApiPermissionAssignments";
|
||||
import { ListDashboardUsersCmd } from "./commands/ListDashboardUsersCmd";
|
||||
import { ListDashboardPermsCmd } from "./commands/ListDashboardPermsCmd";
|
||||
import { EligibleCmd } from "./commands/EligibleCmd";
|
||||
|
||||
const defaultOptions = {
|
||||
config: {
|
||||
can_use: false,
|
||||
can_eligible: false,
|
||||
update_cmd: null,
|
||||
},
|
||||
};
|
||||
|
@ -41,6 +43,7 @@ export const BotControlPlugin = zeppelinGlobalPlugin<BotControlPluginType>()("bo
|
|||
RemoveDashboardUserCmd,
|
||||
ListDashboardUsersCmd,
|
||||
ListDashboardPermsCmd,
|
||||
EligibleCmd,
|
||||
],
|
||||
|
||||
onLoad(pluginData) {
|
||||
|
|
59
backend/src/plugins/BotControl/commands/EligibleCmd.ts
Normal file
59
backend/src/plugins/BotControl/commands/EligibleCmd.ts
Normal file
|
@ -0,0 +1,59 @@
|
|||
import { botControlCmd } from "../types";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { resolveInvite, verboseUserMention } from "../../../utils";
|
||||
|
||||
const REQUIRED_MEMBER_COUNT = 5000;
|
||||
|
||||
export const EligibleCmd = botControlCmd({
|
||||
trigger: ["eligible", "is_eligible", "iseligible"],
|
||||
permission: "can_eligible",
|
||||
|
||||
signature: {
|
||||
user: ct.resolvedUser(),
|
||||
inviteCode: ct.string(),
|
||||
},
|
||||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
if ((await pluginData.state.apiPermissionAssignments.getByUserId(args.user.id)).length) {
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
`${verboseUserMention(args.user)} is an existing bot operator. They are eligible!`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const invite = await resolveInvite(pluginData.client, args.inviteCode, true);
|
||||
if (!invite || !invite.guild) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Could not resolve server from invite");
|
||||
return;
|
||||
}
|
||||
|
||||
if (invite.guild.features.includes("PARTNERED")) {
|
||||
sendSuccessMessage(pluginData, msg.channel, `Server is partnered. It is eligible!`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (invite.guild.features.includes("VERIFIED")) {
|
||||
sendSuccessMessage(pluginData, msg.channel, `Server is verified. It is eligible!`);
|
||||
return;
|
||||
}
|
||||
|
||||
const memberCount = invite.memberCount || 0;
|
||||
if (memberCount >= REQUIRED_MEMBER_COUNT) {
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
`Server has ${memberCount} members, which is equal or higher than the required ${REQUIRED_MEMBER_COUNT}. It is eligible!`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
sendErrorMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
`Server **${invite.guild.name}** (\`${invite.guild.id}\`) is not eligible`,
|
||||
);
|
||||
},
|
||||
});
|
|
@ -8,6 +8,7 @@ import { Configs } from "../../data/Configs";
|
|||
|
||||
export const ConfigSchema = t.type({
|
||||
can_use: t.boolean,
|
||||
can_eligible: t.boolean,
|
||||
update_cmd: tNullable(t.string),
|
||||
});
|
||||
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
|
||||
|
|
Loading…
Add table
Reference in a new issue