From 7cb357e61d29c591e3c8b4e318d7330d0ae14da1 Mon Sep 17 00:00:00 2001 From: ScriptSorcerer20 Date: Sat, 25 Jan 2025 16:56:46 +0100 Subject: [PATCH] Implemented new Commands: help - list all commands timestamp - convert date to timestamp (still in progress) about - Bot porpose (still in progress) ping - check bot availability --- README.md | 21 ++++++------- commands/unique/timestamp.js | 60 ++++++++++++++++++++++++++++++++++++ commands/utility/about.js | 13 ++++++++ commands/utility/help.js | 23 ++++++++++++++ commands/utility/ping.js | 4 +-- package-lock.json | 10 ++++++ package.json | 1 + 7 files changed, 118 insertions(+), 14 deletions(-) create mode 100644 commands/unique/timestamp.js create mode 100644 commands/utility/about.js create mode 100644 commands/utility/help.js diff --git a/README.md b/README.md index cbb2413..4538c8b 100644 --- a/README.md +++ b/README.md @@ -6,19 +6,15 @@ Im going to make a To-do List for the features i want to implement for my Bot. (I will try to make these tools optional, because alot of bots already feature them) 1. **Basic Commands** - - [ ] Add a `!help` command to display a list of available commands. - - [ ] Implement a `!ping` command to check bot responsiveness. - - [ ] Add a `!about` command to describe the bot's purpose. + - [x] Add a `!help` command to display a list of available commands. + - [x] Implement a `!ping` command to check bot responsiveness. + - [ **in progress** ] Add a `!about` command to describe the bot's purpose. -2. **Welcome and Goodbye System** - - [ ] Create a system to welcome new users to the server with a customizable message. - - [ ] Implement a goodbye message when users leave the server. - -3. **Role Management** +2. **Role Management** - [ ] Set up a self-assignable role system (e.g., using reaction roles). - [ ] Allow admins to assign/remove roles with commands. -4. **Moderation Tools** +3. **Moderation Tools** - [ ] Add commands to mute, kick, and ban users. - [ ] Create an auto-moderation feature to delete spam or inappropriate content. - [ ] Implement a warning system with a strike counter. @@ -35,9 +31,10 @@ Im going to make a To-do List for the features i want to implement for my Bot. - [ ] Allow users to purchase roles using the currency with a command (e.g., `!buyrole [role name]`). 2. **Datetime Converter** - - [ ] Create a command to convert timezones: - - [ ] `!convert [time] [timezone] to [timezone]` to handle conversions. - - [ ] Support both 12-hour and 24-hour formats. + (Still in Progress, maybe i'll add visual Menu) + - [x] Create a command to convert timezones: + - [x] `!convert [time] [timezone] to [timezone]` to handle conversions. + - [x] Support both 12-hour and 24-hour formats. - [ ] Include a command to display server-specific or user-specific timezones. 3. **Minigames** diff --git a/commands/unique/timestamp.js b/commands/unique/timestamp.js new file mode 100644 index 0000000..01f2b57 --- /dev/null +++ b/commands/unique/timestamp.js @@ -0,0 +1,60 @@ +const { SlashCommandBuilder } = require('discord.js'); +const moment = require('moment'); // Install moment.js with `npm install moment` + +module.exports = { + data: new SlashCommandBuilder() + .setName('timestamp') + .setDescription('Convert a human-readable date to a Discord timestamp.') + .addStringOption(option => + option + .setName('date') + .setDescription('The date to convert (e.g., YYYY-MM-DD HH:mm)') + .setRequired(true) + ) + .addStringOption(option => + option + .setName('format') + .setDescription('The format for the timestamp') + .setRequired(false) + .addChoices( + { name: 'Short time', value: 't' }, + { name: 'Long time', value: 'T' }, + { name: 'Short date', value: 'd' }, + { name: 'Long date', value: 'D' }, + { name: 'Full date and time', value: 'f' }, + { name: 'Full date and time with weekday', value: 'F' }, + { name: 'Relative time', value: 'R' }, + )), + async execute(interaction) { + // Get user input + const dateInput = interaction.options.getString('date'); + const format = interaction.options.getString('format') || 'f'; // Default to 'f' format + + try { + // Convert the date to a Unix timestamp + const unixTimestamp = moment(dateInput, 'YYYY-MM-DD HH:mm').unix(); + + if (isNaN(unixTimestamp)) { + return interaction.reply({ + content: 'Invalid date. Use the format `YYYY-MM-DD HH:mm`.', + ephemeral: true, + }); + } + + // Construct the Discord timestamp + const discordTimestamp = ``; + + // Reply with the result + await interaction.reply( + `Here’s your Discord timestamp:\n${discordTimestamp}` + ); + } catch (error) { + console.error(error); + await interaction.reply({ + content: + 'Invalid date format. Please use the format `YYYY-MM-DD HH:mm` (e.g., `2025-01-25 14:30`).', + ephemeral: true, + }); + } + }, +}; \ No newline at end of file diff --git a/commands/utility/about.js b/commands/utility/about.js new file mode 100644 index 0000000..7bcf4c1 --- /dev/null +++ b/commands/utility/about.js @@ -0,0 +1,13 @@ +const {SlashCommandBuilder} = require("discord.js"); + +module.exports = { + data: new SlashCommandBuilder() + .setName("about") + .setDescription("Information about this bot"), + async execute(interaction) { + await interaction.reply({ + content: "This bot has some general commands for moderation, but includes on or two unqiue features, like the currenc system. It's a small project to enhanced the programming skills of the creator.", + ephemeral: true + }) + } +} \ No newline at end of file diff --git a/commands/utility/help.js b/commands/utility/help.js new file mode 100644 index 0000000..9936a41 --- /dev/null +++ b/commands/utility/help.js @@ -0,0 +1,23 @@ +const { SlashCommandBuilder} = require("discord.js"); + +module.exports = { + data: new SlashCommandBuilder() + .setName('help') + .setDescription('Gives all available commands.'), + async execute(interaction) { + // Map over the full command objects to get names and descriptions + const commandDetails = interaction.client.commands.map(cmd => ({ + name: cmd.data.name, + description: cmd.data.description, + })); + + // Format the commands into a user-friendly help message + const helpMessage = commandDetails + .map(detail => `/${detail.name} - ${detail.description}`) + .join('\n'); + + // Send the help message + await interaction.reply(`Here are all the available commands:\n\n${helpMessage}`); + + }, +}; \ No newline at end of file diff --git a/commands/utility/ping.js b/commands/utility/ping.js index 2fc8932..2b6a058 100644 --- a/commands/utility/ping.js +++ b/commands/utility/ping.js @@ -3,8 +3,8 @@ const { SlashCommandBuilder } = require('discord.js'); module.exports = { data: new SlashCommandBuilder() .setName('ping') - .setDescription('Replies with Pong!'), + .setDescription('Check if the bots responsivnes'), async execute(interaction) { - await interaction.reply('Pong!'); + await interaction.reply({ content: 'Pong! (Online)', ephemeral: true }); }, }; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ed1719c..bc330ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "better-sqlite3": "^11.3.0", "discord.js": "^14.17.3", "express": "^4.21.0", + "moment": "^2.30.1", "openai": "^4.67.3", "sqlite3": "^5.1.7" } @@ -1738,6 +1739,15 @@ "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==", "license": "MIT" }, + "node_modules/moment": { + "version": "2.30.1", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz", + "integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==", + "license": "MIT", + "engines": { + "node": "*" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", diff --git a/package.json b/package.json index a0a5fec..04bda05 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "better-sqlite3": "^11.3.0", "discord.js": "^14.17.3", "express": "^4.21.0", + "moment": "^2.30.1", "openai": "^4.67.3", "sqlite3": "^5.1.7" }