3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-14 22:05:01 +00:00

feat: add member cache; handle all role changes with RoleManagerPlugin; exit gracefully

This commit is contained in:
Dragory 2023-05-07 17:56:55 +03:00
parent fd60a09947
commit fa50110766
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
48 changed files with 755 additions and 264 deletions

View file

@ -3,6 +3,7 @@ import { GuildLogs } from "../../data/GuildLogs";
import { makeIoTsConfigParser } from "../../pluginUtils";
import { trimPluginDescription } from "../../utils";
import { LogsPlugin } from "../Logs/LogsPlugin";
import { RoleManagerPlugin } from "../RoleManager/RoleManagerPlugin";
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
import { AddRoleCmd } from "./commands/AddRoleCmd";
import { MassAddRoleCmd } from "./commands/MassAddRoleCmd";
@ -43,7 +44,7 @@ export const RolesPlugin = zeppelinGuildPlugin<RolesPluginType>()({
configSchema: ConfigSchema,
},
dependencies: () => [LogsPlugin],
dependencies: () => [LogsPlugin, RoleManagerPlugin],
configParser: makeIoTsConfigParser(ConfigSchema),
defaultOptions,

View file

@ -1,9 +1,9 @@
import { GuildChannel } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { LogType } from "../../../data/LogType";
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { resolveRoleId, verboseUserMention } from "../../../utils";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { RoleManagerPlugin } from "../../RoleManager/RoleManagerPlugin";
import { rolesCmd } from "../types";
export const AddRoleCmd = rolesCmd({
@ -49,9 +49,7 @@ export const AddRoleCmd = rolesCmd({
return;
}
pluginData.state.logs.ignoreLog(LogType.MEMBER_ROLE_ADD, args.member.id);
await args.member.roles.add(roleId);
pluginData.getPlugin(RoleManagerPlugin).addRole(args.member.id, roleId);
pluginData.getPlugin(LogsPlugin).logMemberRoleAdd({
mod: msg.author,

View file

@ -1,10 +1,10 @@
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 { RoleManagerPlugin } from "../../RoleManager/RoleManagerPlugin";
import { rolesCmd } from "../types";
export const MassAddRoleCmd = rolesCmd({
@ -72,8 +72,7 @@ export const MassAddRoleCmd = rolesCmd({
for (const member of membersWithoutTheRole) {
try {
pluginData.state.logs.ignoreLog(LogType.MEMBER_ROLE_ADD, member.id);
await member.roles.add(roleId);
pluginData.getPlugin(RoleManagerPlugin).addRole(member.id, roleId);
pluginData.getPlugin(LogsPlugin).logMemberRoleAdd({
member,
roles: [role],

View file

@ -1,10 +1,9 @@
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 { RoleManagerPlugin } from "../../RoleManager/RoleManagerPlugin";
import { rolesCmd } from "../types";
export const MassRemoveRoleCmd = rolesCmd({
@ -71,19 +70,13 @@ export const MassRemoveRoleCmd = rolesCmd({
);
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);
}
pluginData.getPlugin(RoleManagerPlugin).removeRole(member.id, roleId);
pluginData.getPlugin(LogsPlugin).logMemberRoleRemove({
member,
roles: [role],
mod: msg.author,
});
assigned++;
}
let resultMessage = `Removed role **${role.name}** from ${assigned} ${assigned === 1 ? "member" : "members"}!`;

View file

@ -1,9 +1,9 @@
import { GuildChannel } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { LogType } from "../../../data/LogType";
import { canActOn, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { resolveRoleId, verboseUserMention } from "../../../utils";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { RoleManagerPlugin } from "../../RoleManager/RoleManagerPlugin";
import { rolesCmd } from "../types";
export const RemoveRoleCmd = rolesCmd({
@ -49,10 +49,7 @@ export const RemoveRoleCmd = rolesCmd({
return;
}
pluginData.state.logs.ignoreLog(LogType.MEMBER_ROLE_REMOVE, args.member.id);
await args.member.roles.remove(roleId);
pluginData.getPlugin(RoleManagerPlugin).removeRole(args.member.id, roleId);
pluginData.getPlugin(LogsPlugin).logMemberRoleRemove({
mod: msg.author,
member: args.member,