mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
Mutes: clear mutes if the user is banned; add command for clearing mutes from banned users
This commit is contained in:
parent
55b27674e6
commit
0eac1ab436
1 changed files with 43 additions and 3 deletions
|
@ -1,13 +1,14 @@
|
||||||
import { Member, TextableChannel } from "eris";
|
import { Member, Message, TextableChannel, User } from "eris";
|
||||||
import { GuildCases } from "../data/GuildCases";
|
import { GuildCases } from "../data/GuildCases";
|
||||||
import moment from "moment-timezone";
|
import moment from "moment-timezone";
|
||||||
import { ZeppelinPlugin } from "./ZeppelinPlugin";
|
import { ZeppelinPlugin } from "./ZeppelinPlugin";
|
||||||
import { GuildActions } from "../data/GuildActions";
|
import { GuildActions } from "../data/GuildActions";
|
||||||
import { GuildMutes } from "../data/GuildMutes";
|
import { GuildMutes } from "../data/GuildMutes";
|
||||||
import { DBDateFormat, chunkMessageLines, stripObjectToScalars } from "../utils";
|
import { DBDateFormat, chunkMessageLines, stripObjectToScalars, successMessage } from "../utils";
|
||||||
import humanizeDuration from "humanize-duration";
|
import humanizeDuration from "humanize-duration";
|
||||||
import { LogType } from "../data/LogType";
|
import { LogType } from "../data/LogType";
|
||||||
import { GuildLogs } from "../data/GuildLogs";
|
import { GuildLogs } from "../data/GuildLogs";
|
||||||
|
import { decorators as d } from "knub";
|
||||||
|
|
||||||
export class MutesPlugin extends ZeppelinPlugin {
|
export class MutesPlugin extends ZeppelinPlugin {
|
||||||
public static pluginName = "mutes";
|
public static pluginName = "mutes";
|
||||||
|
@ -22,7 +23,18 @@ export class MutesPlugin extends ZeppelinPlugin {
|
||||||
return {
|
return {
|
||||||
config: {
|
config: {
|
||||||
mute_role: null
|
mute_role: null
|
||||||
}
|
},
|
||||||
|
permissions: {
|
||||||
|
cleanup: false
|
||||||
|
},
|
||||||
|
overrides: [
|
||||||
|
{
|
||||||
|
level: ">=100",
|
||||||
|
permissions: {
|
||||||
|
cleanup: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,6 +149,34 @@ export class MutesPlugin extends ZeppelinPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@d.event("guildBanAdd")
|
||||||
|
async onGuildBanAdd(_, user: User) {
|
||||||
|
const mute = await this.mutes.findExistingMuteForUserId(user.id);
|
||||||
|
if (mute) {
|
||||||
|
this.mutes.clear(user.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@d.command("clear_banned_mutes")
|
||||||
|
@d.permission("cleanup")
|
||||||
|
async clearBannedMutesCmd(msg: Message) {
|
||||||
|
const activeMutes = await this.mutes.getActiveMutes();
|
||||||
|
const bans = await this.guild.getBans();
|
||||||
|
const bannedIds = bans.map(b => b.id);
|
||||||
|
|
||||||
|
await msg.channel.createMessage("Clearing mutes from banned users...");
|
||||||
|
|
||||||
|
let cleared = 0;
|
||||||
|
for (const mute of activeMutes) {
|
||||||
|
if (bannedIds.includes(mute.user_id)) {
|
||||||
|
await this.mutes.clear(mute.user_id);
|
||||||
|
cleared++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.channel.createMessage(successMessage(`Cleared mutes from banned users!`));
|
||||||
|
}
|
||||||
|
|
||||||
protected async clearExpiredMutes() {
|
protected async clearExpiredMutes() {
|
||||||
const expiredMutes = await this.mutes.getExpiredMutes();
|
const expiredMutes = await this.mutes.getExpiredMutes();
|
||||||
for (const mute of expiredMutes) {
|
for (const mute of expiredMutes) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue