Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/commands/admin/CrashCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PermissionsBitField } from 'discord.js';
import { Command, CommandContext } from '@structures/Command.js';
import { Command, CommandContext, CommandCheckFlags } from '@structures/Command.js';
import { ExtendedClient } from '@structures/Client.js';
import { Embeds } from '@utils/Embeds.js';
import { Constants } from '@utils/Constants.js';
Expand All @@ -10,19 +10,12 @@ export default class CrashCommand extends Command {
name: 'crash',
description: 'Crash the bot',
requiredPermissions: [PermissionsBitField.Flags.Administrator],
checkFlags: CommandCheckFlags.Author | CommandCheckFlags.Guild,
});
}

public async execute(client: ExtendedClient, context: CommandContext): Promise<void> {
const author = context.interaction?.user || context.message?.author;

if (!author) {
await context.reply({
embeds: [Embeds.error('Unable to identify the command author.')],
});

return;
}
const author = context.author!;

if (!Constants.TRUSTED_USER_IDS.includes(author.id)) {
await context.reply({
Expand Down
13 changes: 3 additions & 10 deletions src/commands/admin/DevResetCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PermissionsBitField } from 'discord.js';
import { Command, CommandContext } from '@structures/Command.js';
import { Command, CommandContext, CommandCheckFlags } from '@structures/Command.js';
import { ExtendedClient } from '@structures/Client.js';
import { Embeds } from '@utils/Embeds.js';
import { Constants } from '@utils/Constants.js';
Expand All @@ -10,19 +10,12 @@ export default class DevResetCommand extends Command {
name: 'devreset',
description: 'Reset the chat bot',
requiredPermissions: [PermissionsBitField.Flags.Administrator],
checkFlags: CommandCheckFlags.Author | CommandCheckFlags.Guild,
});
}

public async execute(client: ExtendedClient, context: CommandContext): Promise<void> {
const author = context.interaction?.user || context.message?.author;

if (!author) {
await context.reply({
embeds: [Embeds.error('Unable to identify the command author.')],
});

return;
}
const author = context.author!;

if (!Constants.TRUSTED_USER_IDS.includes(author.id)) {
await context.reply({
Expand Down
13 changes: 4 additions & 9 deletions src/commands/admin/SyncCommand.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
import { PermissionFlagsBits } from 'discord.js';
import { ExtendedClient } from '@structures/Client.js';
import { Command, CommandContext } from '@structures/Command.js';
import { Constants } from '@utils/Constants.js';
import { Command, CommandContext, CommandCheckFlags } from '@structures/Command.js';
import { Embeds } from '@utils/Embeds.js';
import { Constants } from '@utils/Constants.js';

export default class SyncCommand extends Command {
constructor() {
super({
name: 'sync',
description: "Cleanup each member's roles",
requiredPermissions: [PermissionFlagsBits.Administrator],
checkFlags: CommandCheckFlags.Guild,
});
}

public async execute(client: ExtendedClient, context: CommandContext): Promise<void> {
const guild = context.interaction?.guild ?? context.message?.guild;

if (!guild) {
return await context.reply({
embeds: [Embeds.error('This command can only be used in a server.')],
});
}
const guild = context.guild!;

const members = await guild.members.fetch();
const communityRole = guild.roles.cache.get(Constants.ROLES.COMMUNITY);
Expand Down
13 changes: 3 additions & 10 deletions src/commands/admin/UpdateGeminiKeyCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MessageFlags, PermissionFlagsBits } from 'discord.js';
import { ExtendedClient } from '@structures/Client.js';
import { Command, CommandContext } from '@structures/Command.js';
import { Command, CommandContext, CommandCheckFlags } from '@structures/Command.js';
import { Argument } from '@structures/Argument.js';
import { Embeds } from '@utils/Embeds.js';
import { Constants } from '@utils/Constants.js';
Expand All @@ -11,6 +11,7 @@ export default class UpdateGeminiKeyCommand extends Command {
name: 'updategeminikey',
description: 'Update the Gemini API key',
requiredPermissions: [PermissionFlagsBits.Administrator],
checkFlags: CommandCheckFlags.Author | CommandCheckFlags.Guild,
args: [
new Argument({
name: 'key',
Expand All @@ -23,15 +24,7 @@ export default class UpdateGeminiKeyCommand extends Command {
}

public async execute(client: ExtendedClient, context: CommandContext): Promise<void> {
const author = context.interaction?.user || context.message?.author;

if (!author) {
await context.reply({
embeds: [Embeds.error('Unable to identify the command author.')],
});

return;
}
const author = context.author!;

if (!Constants.TRUSTED_USER_IDS.includes(author.id)) {
await context.reply({
Expand Down
13 changes: 4 additions & 9 deletions src/commands/moderation/BanCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PermissionFlagsBits } from 'discord.js';
import { ExtendedClient } from '@structures/Client.js';
import { Command, CommandContext } from '@structures/Command.js';
import { Command, CommandContext, CommandCheckFlags } from '@structures/Command.js';
import { Embeds } from '@utils/Embeds.js';
import { Argument } from '@structures/Argument.js';

Expand All @@ -10,6 +10,7 @@ export default class BanCommand extends Command {
name: 'ban',
description: 'Ban a user from the server',
requiredPermissions: [PermissionFlagsBits.BanMembers],
checkFlags: CommandCheckFlags.Author | CommandCheckFlags.Guild,
args: [
new Argument({
name: 'user',
Expand All @@ -28,14 +29,8 @@ export default class BanCommand extends Command {
}

public async execute(client: ExtendedClient, context: CommandContext): Promise<void> {
const guild = context.interaction?.guild ?? context.message?.guild;
const author = context.interaction?.user ?? context.message?.author;

if (!guild) {
return await context.reply({
embeds: [Embeds.error('This command can only be used in a server.')],
});
}
const guild = context.guild!;
const author = context.author!;

const user = guild.members.cache.get(context.args.user as string);

Expand Down
11 changes: 2 additions & 9 deletions src/commands/moderation/ClearCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PermissionFlagsBits, TextChannel } from 'discord.js';
import { ExtendedClient } from '@structures/Client.js';
import { Command, CommandContext } from '@structures/Command.js';
import { Command, CommandContext, CommandCheckFlags } from '@structures/Command.js';
import { Embeds } from '@utils/Embeds.js';
import { Argument } from '@structures/Argument.js';

Expand All @@ -10,6 +10,7 @@ export default class ClearCommand extends Command {
name: 'clear',
description: 'Clear messages from a channel',
requiredPermissions: [PermissionFlagsBits.ManageMessages],
checkFlags: CommandCheckFlags.None,
args: [
new Argument({
name: 'amount',
Expand All @@ -22,14 +23,6 @@ export default class ClearCommand extends Command {
}

public async execute(client: ExtendedClient, context: CommandContext): Promise<void> {
const guild = context.interaction?.guild ?? context.message?.guild;

if (!guild) {
return await context.reply({
embeds: [Embeds.error('This command can only be used in a server.')],
});
}

const amount = context.args.amount as number;

if (!amount || isNaN(amount) || amount < 1 || amount > 100) {
Expand Down
13 changes: 4 additions & 9 deletions src/commands/moderation/KickCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PermissionFlagsBits } from 'discord.js';
import { ExtendedClient } from '@structures/Client.js';
import { Command, CommandContext } from '@structures/Command.js';
import { Command, CommandContext, CommandCheckFlags } from '@structures/Command.js';
import { Embeds } from '@utils/Embeds.js';
import { Argument } from '@structures/Argument.js';

Expand All @@ -10,6 +10,7 @@ export default class KickCommand extends Command {
name: 'kick',
description: 'Kick a user from the server',
requiredPermissions: [PermissionFlagsBits.KickMembers],
checkFlags: CommandCheckFlags.Author | CommandCheckFlags.Guild,
args: [
new Argument({
name: 'user',
Expand All @@ -28,14 +29,8 @@ export default class KickCommand extends Command {
}

public async execute(client: ExtendedClient, context: CommandContext): Promise<void> {
const guild = context.interaction?.guild ?? context.message?.guild;
const author = context.interaction?.user ?? context.message?.author;

if (!guild) {
return await context.reply({
embeds: [Embeds.error('This command can only be used in a server.')],
});
}
const guild = context.guild!;
const author = context.author!;

const user = guild.members.cache.get(context.args.user as string);

Expand Down
13 changes: 4 additions & 9 deletions src/commands/moderation/LockCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PermissionFlagsBits, TextChannel } from 'discord.js';
import { ExtendedClient } from '@structures/Client.js';
import { Command, CommandContext } from '@structures/Command.js';
import { Command, CommandContext, CommandCheckFlags } from '@structures/Command.js';
import { Embeds } from '@utils/Embeds.js';
import { Argument } from '@structures/Argument.js';

Expand All @@ -10,6 +10,7 @@ export default class LockCommand extends Command {
name: 'lock',
description: 'Lock a channel',
requiredPermissions: [PermissionFlagsBits.ManageChannels],
checkFlags: CommandCheckFlags.Guild,
args: [
new Argument({
name: 'channel',
Expand All @@ -22,16 +23,10 @@ export default class LockCommand extends Command {
}

public async execute(client: ExtendedClient, context: CommandContext): Promise<void> {
const guild = context.interaction?.guild ?? context.message?.guild;

if (!guild) {
return await context.reply({
embeds: [Embeds.error('This command can only be used in a server.')],
});
}
const guild = context.guild!;

const channel = context.args.channel
? guild?.channels.cache.get(context.args.channel as string)
? guild.channels.cache.get(context.args.channel as string)
: (context.interaction?.channel ?? context.message?.channel);

if (!channel || !channel.isTextBased()) {
Expand Down
13 changes: 4 additions & 9 deletions src/commands/moderation/MuteCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Argument } from '@structures/Argument.js';
import { ExtendedClient } from '@structures/Client.js';
import { Command, CommandContext } from '@structures/Command.js';
import { Command, CommandContext, CommandCheckFlags } from '@structures/Command.js';
import { PermissionsBitField } from 'discord.js';
import { Embeds } from '@utils/Embeds.js';

Expand All @@ -10,6 +10,7 @@ export default class MuteCommand extends Command {
name: 'mute',
description: 'Mute a user',
requiredPermissions: [PermissionsBitField.Flags.ModerateMembers],
checkFlags: CommandCheckFlags.Author | CommandCheckFlags.Guild,
args: [
new Argument({
name: 'user',
Expand All @@ -34,14 +35,8 @@ export default class MuteCommand extends Command {
}

public async execute(client: ExtendedClient, context: CommandContext): Promise<void> {
const guild = context.interaction?.guild ?? context.message?.guild;
const author = context.interaction?.user ?? context.message?.author;

if (!guild) {
return await context.reply({
embeds: [Embeds.error('This command can only be used in a server.')],
});
}
const guild = context.guild!;
const author = context.author!;

const user = guild.members.cache.get(context.args.user as string);

Expand Down
19 changes: 7 additions & 12 deletions src/commands/moderation/PurgeCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PermissionFlagsBits, TextChannel } from 'discord.js';
import { ExtendedClient } from '@structures/Client.js';
import { Command, CommandContext } from '@structures/Command.js';
import { Command, CommandContext, CommandCheckFlags } from '@structures/Command.js';
import { Embeds } from '@utils/Embeds.js';
import { Argument } from '@structures/Argument.js';

Expand All @@ -10,6 +10,7 @@ export default class PurgeCommand extends Command {
name: 'purge',
description: 'Purge and recreate a channel',
requiredPermissions: [PermissionFlagsBits.ManageChannels],
checkFlags: CommandCheckFlags.Author | CommandCheckFlags.Guild,
args: [
new Argument({
name: 'channel',
Expand All @@ -22,17 +23,11 @@ export default class PurgeCommand extends Command {
}

public async execute(client: ExtendedClient, context: CommandContext): Promise<void> {
const guild = context.interaction?.guild ?? context.message?.guild;
const author = context.interaction?.user ?? context.message?.author;

if (!guild) {
return await context.reply({
embeds: [Embeds.error('This command can only be used in a server.')],
});
}
const guild = context.guild!;
const author = context.author!;

const originalChannel = context.args.channel
? guild?.channels.cache.get(context.args.channel as string)
? guild.channels.cache.get(context.args.channel as string)
: (context.interaction?.channel ?? context.message?.channel);

if (!originalChannel || !originalChannel.isTextBased()) {
Expand All @@ -56,10 +51,10 @@ export default class PurgeCommand extends Command {
}

await newChannel.setPosition(textChannel.position);
await textChannel.delete(`Purged by ${author?.tag}`);
await textChannel.delete(`Purged by ${author.tag}`);

await newChannel.send({
embeds: [Embeds.success(`Channel purged by ${author?.tag}`)],
embeds: [Embeds.success(`Channel purged by ${author.tag}`)],
});
}
}
13 changes: 4 additions & 9 deletions src/commands/moderation/RoleCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PermissionFlagsBits } from 'discord.js';
import { ExtendedClient } from '@structures/Client.js';
import { Command, CommandContext } from '@structures/Command.js';
import { Command, CommandContext, CommandCheckFlags } from '@structures/Command.js';
import { Embeds } from '@utils/Embeds.js';
import { Argument } from '@structures/Argument.js';

Expand All @@ -10,6 +10,7 @@ export default class RoleCommand extends Command {
name: 'role',
description: 'Give or remove a role from a user',
requiredPermissions: [PermissionFlagsBits.ManageRoles],
checkFlags: CommandCheckFlags.Author | CommandCheckFlags.Guild,
args: [
new Argument({
name: 'user',
Expand All @@ -28,14 +29,8 @@ export default class RoleCommand extends Command {
}

public async execute(client: ExtendedClient, context: CommandContext): Promise<void> {
const guild = context.interaction?.guild ?? context.message?.guild;
const author = context.interaction?.user ?? context.message?.author;

if (!guild) {
return await context.reply({
embeds: [Embeds.error('This command can only be used in a server.')],
});
}
const guild = context.guild!;
const author = context.author!;

const user = guild.members.cache.get(context.args.user as string);

Expand Down
Loading
Loading