mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-13 21:57:18 +00:00
excluded managed roles from being removed
This commit is contained in:
parent
fa7d5d0526
commit
b0dcefba81
2 changed files with 30 additions and 13 deletions
|
@ -51,22 +51,34 @@ export class GuildMutes extends BaseGuildRepository {
|
|||
return this.mutes.findOne({ where: result.identifiers[0] });
|
||||
}
|
||||
|
||||
async updateExpiryTime(userId, newExpiryTime) {
|
||||
async updateExpiryTime(userId, newExpiryTime, rolesToRestore?: string[]) {
|
||||
const expiresAt = newExpiryTime
|
||||
? moment()
|
||||
.add(newExpiryTime, "ms")
|
||||
.format("YYYY-MM-DD HH:mm:ss")
|
||||
: null;
|
||||
|
||||
return this.mutes.update(
|
||||
{
|
||||
guild_id: this.guildId,
|
||||
user_id: userId,
|
||||
},
|
||||
{
|
||||
expires_at: expiresAt,
|
||||
},
|
||||
);
|
||||
if (rolesToRestore && rolesToRestore.length) {
|
||||
return this.mutes.update(
|
||||
{
|
||||
guild_id: this.guildId,
|
||||
user_id: userId,
|
||||
},
|
||||
{
|
||||
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[]> {
|
||||
|
|
|
@ -187,7 +187,9 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
// remove roles
|
||||
if (!Array.isArray(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);
|
||||
}
|
||||
} else {
|
||||
|
@ -223,7 +225,10 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
let notifyResult: UserNotificationResult = { method: null, success: true };
|
||||
|
||||
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 {
|
||||
await this.mutes.addMute(user.id, muteTime, rolesToRestore);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue