mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 14:11:50 +00:00
Some fixes for slowmodes not being removed properly
This commit is contained in:
parent
930296973a
commit
f63ae2f4cc
1 changed files with 32 additions and 16 deletions
|
@ -120,18 +120,16 @@ export class SlowmodePlugin extends ZeppelinPlugin<ISlowmodePluginConfig> {
|
||||||
* Clears bot-maintained slowmode from the specified user id on the specified channel.
|
* Clears bot-maintained slowmode from the specified user id on the specified channel.
|
||||||
* This reverts the channel permissions changed above and clears the database entry.
|
* This reverts the channel permissions changed above and clears the database entry.
|
||||||
*/
|
*/
|
||||||
async clearBotSlowmodeFromUserId(channel: GuildChannel & TextChannel, userId: string) {
|
async clearBotSlowmodeFromUserId(channel: GuildChannel & TextChannel, userId: string, force = false) {
|
||||||
// We only need to tweak permissions if there is an existing permission override
|
try {
|
||||||
// In most cases there should be, since one is created in applySlowmodeToUserId()
|
// Remove permission overrides from the channel for this user
|
||||||
const existingOverride = channel.permissionOverwrites.get(userId);
|
// Previously we diffed the overrides so we could clear the "send messages" override without touching other
|
||||||
if (existingOverride) {
|
// overrides. Unfortunately, it seems that was a bit buggy - we didn't always receive the event for the changed
|
||||||
if (existingOverride.allow === 0 && existingOverride.deny === ErisConstants.Permissions.sendMessages) {
|
// overrides and then we also couldn't diff against them. For consistency's sake, we just delete the override now.
|
||||||
// If the only override for this user is what we applied earlier, remove the entire permission overwrite
|
await channel.deletePermission(userId);
|
||||||
await channel.deletePermission(userId);
|
} catch (e) {
|
||||||
} else {
|
if (!force) {
|
||||||
// Otherwise simply negate the sendMessages permission from the denied permissions
|
throw e;
|
||||||
const newDeniedPermissions = existingOverride.deny & ~ErisConstants.Permissions.sendMessages;
|
|
||||||
await channel.editPermission(userId, existingOverride.allow, newDeniedPermissions, "member");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,9 +203,16 @@ export class SlowmodePlugin extends ZeppelinPlugin<ISlowmodePluginConfig> {
|
||||||
/**
|
/**
|
||||||
* COMMAND: Clear slowmode from a specific user on a specific channel
|
* COMMAND: Clear slowmode from a specific user on a specific channel
|
||||||
*/
|
*/
|
||||||
@d.command("slowmode clear", "<channel:channel> <user:resolvedUserLoose>")
|
@d.command("slowmode clear", "<channel:channel> <user:resolvedUserLoose>", {
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: "force",
|
||||||
|
type: "bool",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
@d.permission("can_manage")
|
@d.permission("can_manage")
|
||||||
async clearSlowmodeCmd(msg: Message, args: { channel: GuildChannel & TextChannel; user: User }) {
|
async clearSlowmodeCmd(msg: Message, args: { channel: GuildChannel & TextChannel; user: User; force?: boolean }) {
|
||||||
const channelSlowmode = await this.slowmodes.getChannelSlowmode(args.channel.id);
|
const channelSlowmode = await this.slowmodes.getChannelSlowmode(args.channel.id);
|
||||||
if (!channelSlowmode) {
|
if (!channelSlowmode) {
|
||||||
msg.channel.createMessage(errorMessage("Channel doesn't have slowmode!"));
|
msg.channel.createMessage(errorMessage("Channel doesn't have slowmode!"));
|
||||||
|
@ -215,7 +220,7 @@ export class SlowmodePlugin extends ZeppelinPlugin<ISlowmodePluginConfig> {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.clearBotSlowmodeFromUserId(args.channel, args.user.id);
|
await this.clearBotSlowmodeFromUserId(args.channel, args.user.id, args.force);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return this.sendErrorMessage(
|
return this.sendErrorMessage(
|
||||||
msg.channel,
|
msg.channel,
|
||||||
|
@ -414,7 +419,18 @@ export class SlowmodePlugin extends ZeppelinPlugin<ISlowmodePluginConfig> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.clearBotSlowmodeFromUserId(channel as GuildChannel & TextChannel, user.user_id);
|
try {
|
||||||
|
await this.clearBotSlowmodeFromUserId(channel as GuildChannel & TextChannel, user.user_id);
|
||||||
|
} catch (e) {
|
||||||
|
logger.error(e);
|
||||||
|
|
||||||
|
const realUser = this.bot.users.get(user.user_id) || new UnknownUser({ id: user.user_id });
|
||||||
|
this.logs.log(LogType.BOT_ALERT, {
|
||||||
|
body: `Failed to clear slowmode permissions from {userMention(user)} in {channelMention(channel)}`,
|
||||||
|
user: stripObjectToScalars(realUser),
|
||||||
|
channel: stripObjectToScalars(channel),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue