mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-07 19:17:19 +00:00
Fixes, refactoring and PR feedback
This commit is contained in:
parent
0be54912c4
commit
893a77d562
202 changed files with 1037 additions and 1069 deletions
|
@ -7,6 +7,7 @@ import { MassAddRoleCmd } from "./commands/MassAddRoleCmd";
|
|||
import { MassRemoveRoleCmd } from "./commands/MassRemoveRoleCmd";
|
||||
import { RemoveRoleCmd } from "./commands/RemoveRoleCmd";
|
||||
import { RolesPluginType, zRolesConfig } from "./types";
|
||||
import { CommonPlugin } from "../Common/CommonPlugin";
|
||||
|
||||
const defaultOptions: PluginOptions<RolesPluginType> = {
|
||||
config: {
|
||||
|
@ -50,4 +51,8 @@ export const RolesPlugin = guildPlugin<RolesPluginType>()({
|
|||
|
||||
state.logs = new GuildLogs(guild.id);
|
||||
},
|
||||
|
||||
beforeStart(pluginData) {
|
||||
pluginData.state.common = pluginData.getPlugin(CommonPlugin);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -19,21 +19,19 @@ export const AddRoleCmd = rolesCmd({
|
|||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
if (!canActOn(pluginData, msg.member, args.member, true)) {
|
||||
pluginData
|
||||
.getPlugin(CommonPlugin)
|
||||
.sendErrorMessage(msg, "Cannot add roles to this user: insufficient permissions");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "Cannot add roles to this user: insufficient permissions");
|
||||
return;
|
||||
}
|
||||
|
||||
const roleId = await resolveRoleId(pluginData.client, pluginData.guild.id, args.role);
|
||||
if (!roleId) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Invalid role id");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "Invalid role id");
|
||||
return;
|
||||
}
|
||||
|
||||
const config = await pluginData.config.getForMessage(msg);
|
||||
if (!config.assignable_roles.includes(roleId)) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You cannot assign that role");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "You cannot assign that role");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -43,12 +41,12 @@ export const AddRoleCmd = rolesCmd({
|
|||
pluginData.getPlugin(LogsPlugin).logBotAlert({
|
||||
body: `Unknown role configured for 'roles' plugin: ${roleId}`,
|
||||
});
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You cannot assign that role");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "You cannot assign that role");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.member.roles.cache.has(roleId)) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Member already has that role");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "Member already has that role");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -60,8 +58,6 @@ export const AddRoleCmd = rolesCmd({
|
|||
roles: [role],
|
||||
});
|
||||
|
||||
pluginData
|
||||
.getPlugin(CommonPlugin)
|
||||
.sendSuccessMessage(msg, `Added role **${role.name}** to ${verboseUserMention(args.member.user)}!`);
|
||||
void pluginData.state.common.sendSuccessMessage(msg, `Added role **${role.name}** to ${verboseUserMention(args.member.user)}!`);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -30,22 +30,20 @@ export const MassAddRoleCmd = rolesCmd({
|
|||
|
||||
for (const member of members) {
|
||||
if (!canActOn(pluginData, msg.member, member, true)) {
|
||||
pluginData
|
||||
.getPlugin(CommonPlugin)
|
||||
.sendErrorMessage(msg, "Cannot add roles to 1 or more specified members: insufficient permissions");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "Cannot add roles to 1 or more specified members: insufficient permissions");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const roleId = await resolveRoleId(pluginData.client, pluginData.guild.id, args.role);
|
||||
if (!roleId) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Invalid role id");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "Invalid role id");
|
||||
return;
|
||||
}
|
||||
|
||||
const config = await pluginData.config.getForMessage(msg);
|
||||
if (!config.assignable_roles.includes(roleId)) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You cannot assign that role");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "You cannot assign that role");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -54,7 +52,7 @@ export const MassAddRoleCmd = rolesCmd({
|
|||
pluginData.getPlugin(LogsPlugin).logBotAlert({
|
||||
body: `Unknown role configured for 'roles' plugin: ${roleId}`,
|
||||
});
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You cannot assign that role");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "You cannot assign that role");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,22 +29,20 @@ export const MassRemoveRoleCmd = rolesCmd({
|
|||
|
||||
for (const member of members) {
|
||||
if (!canActOn(pluginData, msg.member, member, true)) {
|
||||
pluginData
|
||||
.getPlugin(CommonPlugin)
|
||||
.sendErrorMessage(msg, "Cannot add roles to 1 or more specified members: insufficient permissions");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "Cannot add roles to 1 or more specified members: insufficient permissions");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const roleId = await resolveRoleId(pluginData.client, pluginData.guild.id, args.role);
|
||||
if (!roleId) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Invalid role id");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "Invalid role id");
|
||||
return;
|
||||
}
|
||||
|
||||
const config = await pluginData.config.getForMessage(msg);
|
||||
if (!config.assignable_roles.includes(roleId)) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You cannot remove that role");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "You cannot remove that role");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -53,7 +51,7 @@ export const MassRemoveRoleCmd = rolesCmd({
|
|||
pluginData.getPlugin(LogsPlugin).logBotAlert({
|
||||
body: `Unknown role configured for 'roles' plugin: ${roleId}`,
|
||||
});
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You cannot remove that role");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "You cannot remove that role");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,21 +19,19 @@ export const RemoveRoleCmd = rolesCmd({
|
|||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
if (!canActOn(pluginData, msg.member, args.member, true)) {
|
||||
pluginData
|
||||
.getPlugin(CommonPlugin)
|
||||
.sendErrorMessage(msg, "Cannot remove roles from this user: insufficient permissions");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "Cannot remove roles from this user: insufficient permissions");
|
||||
return;
|
||||
}
|
||||
|
||||
const roleId = await resolveRoleId(pluginData.client, pluginData.guild.id, args.role);
|
||||
if (!roleId) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Invalid role id");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "Invalid role id");
|
||||
return;
|
||||
}
|
||||
|
||||
const config = await pluginData.config.getForMessage(msg);
|
||||
if (!config.assignable_roles.includes(roleId)) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You cannot remove that role");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "You cannot remove that role");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -43,12 +41,12 @@ export const RemoveRoleCmd = rolesCmd({
|
|||
pluginData.getPlugin(LogsPlugin).logBotAlert({
|
||||
body: `Unknown role configured for 'roles' plugin: ${roleId}`,
|
||||
});
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "You cannot remove that role");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "You cannot remove that role");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args.member.roles.cache.has(roleId)) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Member doesn't have that role");
|
||||
void pluginData.state.common.sendErrorMessage(msg, "Member doesn't have that role");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -59,8 +57,6 @@ export const RemoveRoleCmd = rolesCmd({
|
|||
roles: [role],
|
||||
});
|
||||
|
||||
pluginData
|
||||
.getPlugin(CommonPlugin)
|
||||
.sendSuccessMessage(msg, `Removed role **${role.name}** from ${verboseUserMention(args.member.user)}!`);
|
||||
void pluginData.state.common.sendSuccessMessage(msg, `Removed role **${role.name}** from ${verboseUserMention(args.member.user)}!`);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { BasePluginType, guildPluginMessageCommand } from "knub";
|
||||
import { BasePluginType, guildPluginMessageCommand, pluginUtils } from "knub";
|
||||
import z from "zod";
|
||||
import { GuildLogs } from "../../data/GuildLogs";
|
||||
import { CommonPlugin } from "../Common/CommonPlugin";
|
||||
|
||||
export const zRolesConfig = z.strictObject({
|
||||
can_assign: z.boolean(),
|
||||
|
@ -12,6 +13,7 @@ export interface RolesPluginType extends BasePluginType {
|
|||
config: z.infer<typeof zRolesConfig>;
|
||||
state: {
|
||||
logs: GuildLogs;
|
||||
common: pluginUtils.PluginPublicInterface<typeof CommonPlugin>;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue