3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-07-16 14:47:18 +00:00

excluded managed roles from being removed

This commit is contained in:
roflmaoqwerty 2020-08-13 21:18:07 +10:00
parent fa7d5d0526
commit b0dcefba81
2 changed files with 30 additions and 13 deletions

View file

@ -51,22 +51,34 @@ export class GuildMutes extends BaseGuildRepository {
return this.mutes.findOne({ where: result.identifiers[0] }); return this.mutes.findOne({ where: result.identifiers[0] });
} }
async updateExpiryTime(userId, newExpiryTime) { async updateExpiryTime(userId, newExpiryTime, rolesToRestore?: string[]) {
const expiresAt = newExpiryTime const expiresAt = newExpiryTime
? moment() ? moment()
.add(newExpiryTime, "ms") .add(newExpiryTime, "ms")
.format("YYYY-MM-DD HH:mm:ss") .format("YYYY-MM-DD HH:mm:ss")
: null; : null;
if (rolesToRestore && rolesToRestore.length) {
return this.mutes.update( return this.mutes.update(
{ {
guild_id: this.guildId, guild_id: this.guildId,
user_id: userId, user_id: userId,
}, },
{ {
expires_at: expiresAt, expires_at: expiresAt,
}, roles_to_restore: rolesToRestore,
); },
);
} else {
return this.mutes.update(
{
guild_id: this.guildId,
user_id: userId,
},
{
expires_at: expiresAt,
},
);
}
} }
async getActiveMutes(): Promise<Mute[]> { async getActiveMutes(): Promise<Mute[]> {

View file

@ -187,7 +187,9 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
// remove roles // remove roles
if (!Array.isArray(removeRoles)) { if (!Array.isArray(removeRoles)) {
if (removeRoles) { if (removeRoles) {
memberOptions.roles = []; // exclude managed roles from being removed
const managedRoles = this.guild.roles.filter(x => x.managed).map(y => y.id);
memberOptions.roles = managedRoles.filter(x => member.roles.includes(x));
await member.edit(memberOptions); await member.edit(memberOptions);
} }
} else { } else {
@ -223,7 +225,10 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
let notifyResult: UserNotificationResult = { method: null, success: true }; let notifyResult: UserNotificationResult = { method: null, success: true };
if (existingMute) { if (existingMute) {
await this.mutes.updateExpiryTime(user.id, muteTime); if (existingMute.roles_to_restore.length || rolesToRestore.length) {
rolesToRestore = Array.from(new Set([...existingMute.roles_to_restore, ...rolesToRestore]));
}
await this.mutes.updateExpiryTime(user.id, muteTime, rolesToRestore);
} else { } else {
await this.mutes.addMute(user.id, muteTime, rolesToRestore); await this.mutes.addMute(user.id, muteTime, rolesToRestore);
} }