- Fix commands relying on MemberWrapper instead of UserWrapper

- Add vckick command
This commit is contained in:
D3vision 2023-12-07 23:43:49 +01:00
parent 427f07c5bb
commit 45bf4efce4
5 changed files with 50 additions and 16 deletions

View File

@ -3,7 +3,7 @@ import DiscordClient from '../../../DiscordClient.js';
import { Nickname } from '../../../infractions/index.js'; import { Nickname } from '../../../infractions/index.js';
import { CommandError, ModerationCommand } from '../../../interfaces/index.js'; import { CommandError, ModerationCommand } from '../../../interfaces/index.js';
import InvokerWrapper from '../../wrappers/InvokerWrapper.js'; import InvokerWrapper from '../../wrappers/InvokerWrapper.js';
import UserWrapper from '../../wrappers/UserWrapper.js'; import MemberWrapper from '../../wrappers/MemberWrapper.js';
class DehoistCommand extends ModerationCommand class DehoistCommand extends ModerationCommand
{ {
@ -22,15 +22,15 @@ class DehoistCommand extends ModerationCommand
} }
async execute (invoker: InvokerWrapper, { users, ...args }: CommandParams) async execute (invoker: InvokerWrapper<true>, { users, ...args }: CommandParams)
{ {
if (!users) if (!users)
throw new CommandError(invoker, { index: 'MODERATION_MISSING_USERS' }); throw new CommandError(invoker, { index: 'MODERATION_MISSING_USERS' });
const wrappers = await Promise.all(users.asUsers.map(user => this.client.getUserWrapper(user))); const wrappers = await Promise.all(users!.asUsers.map(user => invoker.guild.memberWrapper(user)));
return this.client.moderation.handleInfraction(Nickname, invoker, { return this.client.moderation.handleInfraction(Nickname, invoker, {
targets: wrappers.filter(Boolean) as UserWrapper[], targets: wrappers.filter(Boolean) as MemberWrapper[],
args, args,
data: { data: {
dehoist: true dehoist: true

View File

@ -3,7 +3,7 @@ import DiscordClient from '../../../DiscordClient.js';
import { Kick } from '../../../infractions/index.js'; import { Kick } from '../../../infractions/index.js';
import { ModerationCommand } from '../../../interfaces/index.js'; import { ModerationCommand } from '../../../interfaces/index.js';
import InvokerWrapper from '../../wrappers/InvokerWrapper.js'; import InvokerWrapper from '../../wrappers/InvokerWrapper.js';
import UserWrapper from '../../wrappers/UserWrapper.js'; import MemberWrapper from '../../wrappers/MemberWrapper.js';
class KickCommand extends ModerationCommand class KickCommand extends ModerationCommand
{ {
@ -21,11 +21,11 @@ class KickCommand extends ModerationCommand
}); });
} }
async execute (invoker: InvokerWrapper, { users, ...args }: CommandParams) async execute (invoker: InvokerWrapper<true>, { users, ...args }: CommandParams)
{ {
const wrappers = await Promise.all(users!.asUsers.map(user => this.client.getUserWrapper(user))); const wrappers = await Promise.all(users!.asUsers.map(user => invoker.guild.memberWrapper(user)));
return this.client.moderation.handleInfraction(Kick, invoker, { return this.client.moderation.handleInfraction(Kick, invoker, {
targets: wrappers.filter(Boolean) as UserWrapper[], targets: wrappers.filter(Boolean) as MemberWrapper[],
args args
}); });
} }

View File

@ -2,9 +2,9 @@ import { CommandError, ModerationCommand } from '../../../interfaces/index.js';
import DiscordClient from '../../../DiscordClient.js'; import DiscordClient from '../../../DiscordClient.js';
import InvokerWrapper from '../../wrappers/InvokerWrapper.js'; import InvokerWrapper from '../../wrappers/InvokerWrapper.js';
import { CommandOptionType, CommandParams } from '../../../../../@types/Client.js'; import { CommandOptionType, CommandParams } from '../../../../../@types/Client.js';
import UserWrapper from '../../wrappers/UserWrapper.js';
import Addrole from '../../../infractions/Addrole.js'; import Addrole from '../../../infractions/Addrole.js';
import Removerole from '../../../infractions/Removerole.js'; import Removerole from '../../../infractions/Removerole.js';
import MemberWrapper from '../../wrappers/MemberWrapper.js';
class AddroleCommand extends ModerationCommand class AddroleCommand extends ModerationCommand
{ {
@ -46,7 +46,7 @@ class AddroleCommand extends ModerationCommand
} }
async execute (invoker: InvokerWrapper, { users, roles, ...args }: CommandParams) async execute (invoker: InvokerWrapper<true>, { users, roles, ...args }: CommandParams)
{ {
if (!users) if (!users)
@ -56,9 +56,9 @@ class AddroleCommand extends ModerationCommand
const Infraction = invoker.subcommand!.name === 'add' ? Addrole : Removerole; const Infraction = invoker.subcommand!.name === 'add' ? Addrole : Removerole;
const wrappers = await Promise.all(users.asUsers.map(user => this.client.getUserWrapper(user))); const wrappers = await Promise.all(users!.asUsers.map(user => invoker.guild.memberWrapper(user)));
return this.client.moderation.handleInfraction(Infraction, invoker, { return this.client.moderation.handleInfraction(Infraction, invoker, {
targets: wrappers.filter(Boolean) as UserWrapper[], targets: wrappers.filter(Boolean) as MemberWrapper[],
args, args,
data: { data: {
roleIds: roles.asRoles.map((r) => r.id), roleIds: roles.asRoles.map((r) => r.id),

View File

@ -3,7 +3,7 @@ import DiscordClient from '../../../DiscordClient.js';
import { Unmute } from '../../../infractions/index.js'; import { Unmute } from '../../../infractions/index.js';
import { CommandError, ModerationCommand } from '../../../interfaces/index.js'; import { CommandError, ModerationCommand } from '../../../interfaces/index.js';
import InvokerWrapper from '../../wrappers/InvokerWrapper.js'; import InvokerWrapper from '../../wrappers/InvokerWrapper.js';
import UserWrapper from '../../wrappers/UserWrapper.js'; import MemberWrapper from '../../wrappers/MemberWrapper.js';
class UnmuteCommand extends ModerationCommand class UnmuteCommand extends ModerationCommand
{ {
@ -22,7 +22,7 @@ class UnmuteCommand extends ModerationCommand
}); });
} }
async execute (invoker: InvokerWrapper, { users, ...args }: CommandParams) async execute (invoker: InvokerWrapper<true>, { users, ...args }: CommandParams)
{ {
if (!users) if (!users)
throw new CommandError(invoker, { index: 'MODERATION_MISSING_USERS' }); throw new CommandError(invoker, { index: 'MODERATION_MISSING_USERS' });
@ -35,9 +35,9 @@ class UnmuteCommand extends ModerationCommand
else if (!me!.permissions.has('ManageRoles')) else if (!me!.permissions.has('ManageRoles'))
throw new CommandError(invoker, { index: 'INHIBITOR_CLIENTPERMISSIONS_ERROR', formatParams: { command: this.name, missing: 'ManageRoles' } }); throw new CommandError(invoker, { index: 'INHIBITOR_CLIENTPERMISSIONS_ERROR', formatParams: { command: this.name, missing: 'ManageRoles' } });
const wrappers = await Promise.all(users.asUsers.map(user => this.client.getUserWrapper(user))); const wrappers = await Promise.all(users!.asUsers.map(user => invoker.guild.memberWrapper(user)));
return this.client.moderation.handleInfraction(Unmute, invoker, { return this.client.moderation.handleInfraction(Unmute, invoker, {
targets: wrappers.filter(Boolean) as UserWrapper[], targets: wrappers.filter(Boolean) as MemberWrapper[],
args args
}); });
} }

View File

@ -0,0 +1,34 @@
import { CommandParams } from '../../../../../@types/Client.js';
import DiscordClient from '../../../DiscordClient.js';
import { VcKick } from '../../../infractions/index.js';
import { ModerationCommand } from '../../../interfaces/index.js';
import InvokerWrapper from '../../wrappers/InvokerWrapper.js';
import MemberWrapper from '../../wrappers/MemberWrapper.js';
class VcKickCommand extends ModerationCommand
{
constructor (client: DiscordClient)
{
super(client, {
name: 'vckick',
description: 'Kick people from a VC.',
moduleName: 'moderation',
options: [],
guildOnly: true,
showUsage: true,
memberPermissions: [ 'MoveMembers' ],
clientPermissions: [ 'MoveMembers' ],
});
}
async execute (invoker: InvokerWrapper<true>, { users, ...args }: CommandParams)
{
const wrappers = await Promise.all(users!.asUsers.map(user => invoker.guild.memberWrapper(user)));
return this.client.moderation.handleInfraction(VcKick, invoker, {
targets: wrappers.filter(Boolean) as MemberWrapper[],
args
});
}
}
export default VcKickCommand;