3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Add dev command to check server eligibility

This commit is contained in:
Dragory 2021-04-10 23:36:21 +03:00
parent 5f3c94d064
commit e57175dcc3
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
3 changed files with 63 additions and 0 deletions

View file

@ -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) {

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

View file

@ -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>;