mirror of
https://github.com/ahmadk953/poixpixel-discord-bot.git
synced 2025-05-10 10:43:06 +00:00
Refactored Command Deployment, Organized Code, and Fixed Linting
This commit is contained in:
parent
327035d883
commit
d8df48438d
9 changed files with 77 additions and 63 deletions
31
src/commands/util/members.ts
Normal file
31
src/commands/util/members.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import {
|
||||
SlashCommandBuilder,
|
||||
CommandInteraction,
|
||||
EmbedBuilder,
|
||||
} from 'discord.js';
|
||||
import { getAllMembers } from '../../util/db.js';
|
||||
|
||||
interface Command {
|
||||
data: Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
|
||||
execute: (interaction: CommandInteraction) => Promise<void>;
|
||||
}
|
||||
|
||||
const command: Command = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('members')
|
||||
.setDescription('Lists all non-bot members of the server'),
|
||||
execute: async (interaction) => {
|
||||
const members = await getAllMembers();
|
||||
const memberList = members
|
||||
.map((m) => `**${m.discordUsername}** (${m.discordId})`)
|
||||
.join('\n');
|
||||
const membersEmbed = new EmbedBuilder()
|
||||
.setTitle('Members')
|
||||
.setDescription(memberList)
|
||||
.setColor(0x0099ff)
|
||||
.addFields({ name: 'Total Members', value: members.length.toString() });
|
||||
await interaction.reply({ embeds: [membersEmbed] });
|
||||
},
|
||||
};
|
||||
|
||||
export default command;
|
17
src/commands/util/ping.ts
Normal file
17
src/commands/util/ping.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { SlashCommandBuilder, CommandInteraction } from 'discord.js';
|
||||
|
||||
interface Command {
|
||||
data: Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
|
||||
execute: (interaction: CommandInteraction) => Promise<void>;
|
||||
}
|
||||
|
||||
const command: Command = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('ping')
|
||||
.setDescription('Check the latency from you to the bot'),
|
||||
execute: async (interaction) => {
|
||||
await interaction.reply(`Pong! Latency: ${Date.now() - interaction.createdTimestamp}ms`);
|
||||
},
|
||||
};
|
||||
|
||||
export default command;
|
19
src/commands/util/server.ts
Normal file
19
src/commands/util/server.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { SlashCommandBuilder, CommandInteraction } from 'discord.js';
|
||||
|
||||
interface Command {
|
||||
data: Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
|
||||
execute: (interaction: CommandInteraction) => Promise<void>;
|
||||
}
|
||||
|
||||
const command: Command = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('server')
|
||||
.setDescription('Provides information about the server.'),
|
||||
execute: async (interaction) => {
|
||||
await interaction.reply(
|
||||
`The server ${interaction!.guild!.name} has ${interaction!.guild!.memberCount} members and was created on ${interaction!.guild!.createdAt}. It is ${new Date().getFullYear() - interaction!.guild!.createdAt.getFullYear()!} years old.`
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
export default command;
|
69
src/commands/util/user-info.ts
Normal file
69
src/commands/util/user-info.ts
Normal file
|
@ -0,0 +1,69 @@
|
|||
import {
|
||||
SlashCommandBuilder,
|
||||
CommandInteraction,
|
||||
EmbedBuilder,
|
||||
SlashCommandOptionsOnlyBuilder,
|
||||
} from 'discord.js';
|
||||
import { getMember } from '../../util/db.js';
|
||||
|
||||
interface Command {
|
||||
data: SlashCommandOptionsOnlyBuilder;
|
||||
execute: (interaction: CommandInteraction) => Promise<void>;
|
||||
}
|
||||
|
||||
const command: Command = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('userinfo')
|
||||
.setDescription('Provides information about the user.')
|
||||
.addUserOption((option) =>
|
||||
option
|
||||
.setName('user')
|
||||
.setDescription('The user whose information you want to retrieve.')
|
||||
.setRequired(true)
|
||||
),
|
||||
execute: async (interaction) => {
|
||||
const userOption = interaction.options.get('user');
|
||||
if (!userOption) {
|
||||
await interaction.reply('User not found');
|
||||
return;
|
||||
}
|
||||
const user = userOption.user;
|
||||
if (!user) {
|
||||
await interaction.reply('User not found');
|
||||
return;
|
||||
}
|
||||
const member = await getMember(user.id);
|
||||
const [memberData] = member;
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(`User Information - ${user?.username}`)
|
||||
.setColor(user.accentColor || 'Default')
|
||||
.addFields(
|
||||
{ name: 'Username', value: user.username, inline: false },
|
||||
{ name: 'User ID', value: user.id, inline: false },
|
||||
{
|
||||
name: 'Joined Server',
|
||||
value:
|
||||
interaction.guild?.members.cache
|
||||
.get(user.id)
|
||||
?.joinedAt?.toLocaleString() || 'Not available',
|
||||
inline: false,
|
||||
},
|
||||
{
|
||||
name: 'Account Created',
|
||||
value: user.createdAt.toLocaleString(),
|
||||
inline: false,
|
||||
},
|
||||
{
|
||||
name: 'Number of Warnings',
|
||||
value: memberData?.numberOfWarnings.toString() || '0',
|
||||
},
|
||||
{
|
||||
name: 'Number of Bans',
|
||||
value: memberData?.numberOfBans.toString() || '0',
|
||||
}
|
||||
);
|
||||
await interaction.reply({ embeds: [embed] });
|
||||
},
|
||||
};
|
||||
|
||||
export default command;
|
Loading…
Add table
Add a link
Reference in a new issue