mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-07 19:17:19 +00:00

* update pkgs
Signed-off-by: GitHub <noreply@github.com>
* new knub typings
Signed-off-by: GitHub <noreply@github.com>
* more pkg updates
Signed-off-by: GitHub <noreply@github.com>
* more fixes
Signed-off-by: GitHub <noreply@github.com>
* channel typings
Signed-off-by: GitHub <noreply@github.com>
* more message utils typings fixes
Signed-off-by: GitHub <noreply@github.com>
* migrate permissions
Signed-off-by: GitHub <noreply@github.com>
* fix: InternalPoster webhookables
Signed-off-by: GitHub <noreply@github.com>
* djs typings: Attachment & Util
Signed-off-by: GitHub <noreply@github.com>
* more typings
Signed-off-by: GitHub <noreply@github.com>
* fix: rename permissionNames
Signed-off-by: GitHub <noreply@github.com>
* more fixes
Signed-off-by: GitHub <noreply@github.com>
* half the number of errors
* knub commands => messageCommands
Signed-off-by: GitHub <noreply@github.com>
* configPreprocessor => configParser
Signed-off-by: GitHub <noreply@github.com>
* fix channel.messages
Signed-off-by: GitHub <noreply@github.com>
* revert automod any typing
Signed-off-by: GitHub <noreply@github.com>
* more configParser typings
Signed-off-by: GitHub <noreply@github.com>
* revert
Signed-off-by: GitHub <noreply@github.com>
* remove knub type params
Signed-off-by: GitHub <noreply@github.com>
* fix more MessageEmbed / MessageOptions
Signed-off-by: GitHub <noreply@github.com>
* dumb commit for @almeidx to see why this is stupid
Signed-off-by: GitHub <noreply@github.com>
* temp disable custom_events
Signed-off-by: GitHub <noreply@github.com>
* more minor typings fixes - 23 err left
Signed-off-by: GitHub <noreply@github.com>
* update djs dep
* +debug build method (revert this)
Signed-off-by: GitHub <noreply@github.com>
* Revert "+debug build method (revert this)"
This reverts commit a80af1e729
.
* Redo +debug build (Revert this)
Signed-off-by: GitHub <noreply@github.com>
* uniform before/after Load shorthands
Signed-off-by: GitHub <noreply@github.com>
* remove unused imports & add prettier plugin
Signed-off-by: GitHub <noreply@github.com>
* env fixes for web platform hosting
Signed-off-by: GitHub <noreply@github.com>
* feat: knub v32-next; related fixes
* fix: allow legacy keys in change_perms action
* fix: request Message Content intent
* fix: use Knub's config validation logic in API
* fix(dashboard): fix error when there are no message and/or slash commands in a plugin
* fix(automod): start_thread action thread options
* fix(CustomEvents): message command types
* chore: remove unneeded type annotation
* feat: add forum channel icon; use thread icon for news threads
* chore: make tslint happy
* chore: fix formatting
---------
Signed-off-by: GitHub <noreply@github.com>
Co-authored-by: almeidx <almeidx@pm.me>
Co-authored-by: Dragory <2606411+Dragory@users.noreply.github.com>
104 lines
3.4 KiB
TypeScript
104 lines
3.4 KiB
TypeScript
import { GuildMember } from "discord.js";
|
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
|
import { LogType } from "../../../data/LogType";
|
|
import { logger } from "../../../logger";
|
|
import { canActOn, sendErrorMessage } from "../../../pluginUtils";
|
|
import { resolveMember, resolveRoleId, successMessage } from "../../../utils";
|
|
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
|
import { rolesCmd } from "../types";
|
|
|
|
export const MassRemoveRoleCmd = rolesCmd({
|
|
trigger: "massremoverole",
|
|
permission: "can_mass_assign",
|
|
|
|
signature: {
|
|
role: ct.string(),
|
|
members: ct.string({ rest: true }),
|
|
},
|
|
|
|
async run({ message: msg, args, pluginData }) {
|
|
msg.channel.send(`Resolving members...`);
|
|
|
|
const members: GuildMember[] = [];
|
|
const unknownMembers: string[] = [];
|
|
for (const memberId of args.members) {
|
|
const member = await resolveMember(pluginData.client, pluginData.guild, memberId);
|
|
if (member) members.push(member);
|
|
else unknownMembers.push(memberId);
|
|
}
|
|
|
|
for (const member of members) {
|
|
if (!canActOn(pluginData, msg.member, member, true)) {
|
|
sendErrorMessage(
|
|
pluginData,
|
|
msg.channel,
|
|
"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) {
|
|
sendErrorMessage(pluginData, msg.channel, "Invalid role id");
|
|
return;
|
|
}
|
|
|
|
const config = await pluginData.config.getForMessage(msg);
|
|
if (!config.assignable_roles.includes(roleId)) {
|
|
sendErrorMessage(pluginData, msg.channel, "You cannot remove that role");
|
|
return;
|
|
}
|
|
|
|
const role = pluginData.guild.roles.cache.get(roleId);
|
|
if (!role) {
|
|
pluginData.getPlugin(LogsPlugin).logBotAlert({
|
|
body: `Unknown role configured for 'roles' plugin: ${roleId}`,
|
|
});
|
|
sendErrorMessage(pluginData, msg.channel, "You cannot remove that role");
|
|
return;
|
|
}
|
|
|
|
const membersWithTheRole = members.filter((m) => m.roles.cache.has(roleId));
|
|
let assigned = 0;
|
|
const failed: string[] = [];
|
|
const didNotHaveRole = members.length - membersWithTheRole.length;
|
|
|
|
msg.channel.send(
|
|
`Removing role **${role.name}** from ${membersWithTheRole.length} ${
|
|
membersWithTheRole.length === 1 ? "member" : "members"
|
|
}...`,
|
|
);
|
|
|
|
for (const member of membersWithTheRole) {
|
|
try {
|
|
pluginData.state.logs.ignoreLog(LogType.MEMBER_ROLE_REMOVE, member.id);
|
|
await member.roles.remove(roleId);
|
|
pluginData.getPlugin(LogsPlugin).logMemberRoleRemove({
|
|
member,
|
|
roles: [role],
|
|
mod: msg.author,
|
|
});
|
|
assigned++;
|
|
} catch (e) {
|
|
logger.warn(`Error when removing role via !massremoverole: ${e.message}`);
|
|
failed.push(member.id);
|
|
}
|
|
}
|
|
|
|
let resultMessage = `Removed role **${role.name}** from ${assigned} ${assigned === 1 ? "member" : "members"}!`;
|
|
if (didNotHaveRole) {
|
|
resultMessage += ` ${didNotHaveRole} ${didNotHaveRole === 1 ? "member" : "members"} didn't have the role.`;
|
|
}
|
|
|
|
if (failed.length) {
|
|
resultMessage += `\nFailed to remove the role from the following members: ${failed.join(", ")}`;
|
|
}
|
|
|
|
if (unknownMembers.length) {
|
|
resultMessage += `\nUnknown members: ${unknownMembers.join(", ")}`;
|
|
}
|
|
|
|
msg.channel.send(successMessage(resultMessage));
|
|
},
|
|
});
|