Add unban, forceban, and addcase commands

This commit is contained in:
Dragory 2018-07-14 20:55:39 +03:00
parent b7f06c18d4
commit 6bf865af77
2 changed files with 100 additions and 3 deletions

View file

@ -5,6 +5,8 @@ export enum LogType {
MEMBER_MUTE_EXPIRED, MEMBER_MUTE_EXPIRED,
MEMBER_KICK, MEMBER_KICK,
MEMBER_BAN, MEMBER_BAN,
MEMBER_UNBAN,
MEMBER_FORCEBAN,
MEMBER_JOIN, MEMBER_JOIN,
MEMBER_LEAVE, MEMBER_LEAVE,
MEMBER_ROLE_ADD, MEMBER_ROLE_ADD,
@ -31,5 +33,7 @@ export enum LogType {
COMMAND, COMMAND,
SPAM_DELETE, SPAM_DELETE,
CENSOR CENSOR,
CASE_CREATE
} }

View file

@ -73,7 +73,8 @@ export class ModActionsPlugin extends Plugin {
mute: false, mute: false,
kick: false, kick: false,
ban: false, ban: false,
view: false view: false,
addcase: false
}, },
overrides: [ overrides: [
{ {
@ -84,7 +85,8 @@ export class ModActionsPlugin extends Plugin {
mute: true, mute: true,
kick: true, kick: true,
ban: true, ban: true,
view: true view: true,
addcase: true
} }
} }
] ]
@ -418,6 +420,97 @@ export class ModActionsPlugin extends Plugin {
}); });
} }
@d.command("unban", "<userId:string> [reason:string$]")
@d.permission("ban")
async unbanCmd(msg: Message, args: any) {
try {
await this.guild.unbanMember(args.userId, args.reason);
} catch (e) {
msg.channel.createMessage(errorMessage("Failed to unban member"));
return;
}
// Confirm the action
msg.channel.createMessage(successMessage("Member unbanned!"));
// Create a case
this.createCase(args.userId, msg.author.id, CaseType.Unban, null, args.reason);
// Log the action
this.serverLogs.log(LogType.MEMBER_UNBAN, {
mod: stripObjectToScalars(msg.member, ["user"]),
userId: args.userId
});
}
@d.command("forceban", "<userId:string> [reason:string$]")
@d.permission("ban")
async forcebanCmd(msg: Message, args: any) {
// If the user exists as a guild member, make sure we can act on them first
const member = this.guild.members.get(args.userId);
if (member && !this.canActOn(msg.member, member)) {
msg.channel.createMessage(
errorMessage("Cannot forceban this user: insufficient permissions")
);
return;
}
try {
await this.guild.banMember(args.userId, 1, args.reason);
} catch (e) {
msg.channel.createMessage(errorMessage("Failed to forceban member"));
return;
}
// Confirm the action
msg.channel.createMessage(successMessage("Member forcebanned!"));
// Create a case
this.createCase(args.userId, msg.author.id, CaseType.Ban, null, args.reason);
// Log the action
this.serverLogs.log(LogType.MEMBER_FORCEBAN, {
mod: stripObjectToScalars(msg.member, ["user"]),
userId: args.userId
});
}
@d.command("addcase", "<type:string> <target:userId> [reason:string$]")
@d.permission("addcase")
async addcaseCmd(msg: Message, args: any) {
// Verify the user id is a valid snowflake-ish
if (!args.type.match(/^[0-9]{17,20}$/)) {
msg.channel.createMessage(errorMessage("Cannot add case: invalid user id"));
return;
}
// If the user exists as a guild member, make sure we can act on them first
const member = this.guild.members.get(args.userId);
if (member && !this.canActOn(msg.member, member)) {
msg.channel.createMessage(
errorMessage("Cannot add case on this user: insufficient permissions")
);
return;
}
// Verify the case type is valid
const type: string = args.type[0].toUpperCase() + args.type.slice(1).toLowerCase();
if (!CaseType[type]) {
msg.channel.createMessage(errorMessage("Cannot add case: invalid case type"));
return;
}
// Create the case
await this.createCase(args.userId, msg.author.id, CaseType[type], null, args.reason);
// Log the action
msg.channel.createMessage(successMessage("Case created!"));
this.serverLogs.log(LogType.CASE_CREATE, {
mod: stripObjectToScalars(msg.member, ["user"]),
userId: args.userId
});
}
/** /**
* Display a case or list of cases * Display a case or list of cases
* If the argument passed is a case id, display that case * If the argument passed is a case id, display that case