diff --git a/src/commands/user-info.ts b/src/commands/user-info.ts new file mode 100644 index 0000000..9a8c160 --- /dev/null +++ b/src/commands/user-info.ts @@ -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; +} + +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; diff --git a/src/commands/user.ts b/src/commands/user.ts deleted file mode 100644 index 488e682..0000000 --- a/src/commands/user.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { - SlashCommandBuilder, - CommandInteraction, - GuildMember, -} from 'discord.js'; - -interface Command { - data: Omit; - execute: (interaction: CommandInteraction) => Promise; -} - -const command: Command = { - data: new SlashCommandBuilder() - .setName('user') - .setDescription('Provides information about the user.'), - execute: async (interaction) => { - if (interaction.member instanceof GuildMember) { - await interaction.reply( - `This command was run by ${interaction.user.username}, who joined this server on ${interaction.member.joinedAt}.` - ); - } - else { - await interaction.reply( - `This command was run by ${interaction.user.username}.` - ); - } - }, -}; - -export default command; diff --git a/src/db/schema.ts b/src/db/schema.ts index f4944ce..5c125e9 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -4,4 +4,6 @@ export const memberTable = pgTable('members', { id: integer().primaryKey().generatedAlwaysAsIdentity(), discordId: varchar('discord_id').notNull().unique(), discordUsername: varchar('discord_username').notNull(), + numberOfWarnings: integer('number_warnings').notNull().default(0), + numberOfBans: integer('number_bans').notNull().default(0), }); diff --git a/src/discord-bot.ts b/src/discord-bot.ts index b9b113c..076a437 100644 --- a/src/discord-bot.ts +++ b/src/discord-bot.ts @@ -3,7 +3,7 @@ import path from 'node:path'; import { Client, Collection, Events, GatewayIntentBits } from 'discord.js'; import { deployCommands } from './util/deployCommand.js'; -import { removeMember, setMembers } from './util/db.js'; +import { getMember, removeMember, setMembers } from './util/db.js'; const config = JSON.parse(fs.readFileSync('./config.json', 'utf8')); const { token, guildId } = config; diff --git a/src/util/db.ts b/src/util/db.ts index b1d78f4..2a9d3ea 100644 --- a/src/util/db.ts +++ b/src/util/db.ts @@ -43,3 +43,7 @@ export async function setMembers(nonBotMembers: any) { export async function removeMember(discordId: string) { await db.delete(memberTable).where(eq(memberTable.discordId, discordId)); } + +export async function getMember(discordId: string) { + return await db.select().from(memberTable).where(eq(memberTable.discordId, discordId)); +} \ No newline at end of file