Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Dev to Main #103

Merged
merged 27 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
203ff7a
moved command descriptions in /help to github wiki due to discord's m…
vb2007 Dec 20, 2024
06cbd52
added commandData table schema
vb2007 Dec 20, 2024
7c70d51
changed id
vb2007 Dec 20, 2024
64c27ec
added data export
vb2007 Dec 20, 2024
568339d
added command option to /help
vb2007 Dec 20, 2024
f81fca6
updated packages
vb2007 Dec 21, 2024
2baf39a
started rewriting /help
vb2007 Dec 21, 2024
b4c4480
moved data.sql to table.sql
vb2007 Dec 21, 2024
61429d6
removed table name from insert queries
vb2007 Dec 21, 2024
67cfa0a
made /help work with specified commands
vb2007 Dec 21, 2024
d9d40c4
added handling commands from specified categories
vb2007 Dec 21, 2024
6a3d945
fixed uppercase category name, other small stuffs
vb2007 Dec 21, 2024
8fa1d9c
listed all commands if a parameter wasn't provided
vb2007 Dec 22, 2024
baefbb8
renamed folder after the table's name
vb2007 Dec 22, 2024
e7f8ddb
rewritten unit test to check the sql script instead of the /help command
vb2007 Dec 22, 2024
75438d0
added wiki references to /help
vb2007 Dec 22, 2024
a6348af
made the command names into a unique key
vb2007 Dec 22, 2024
83ecf0e
fixed sql split in unit test
vb2007 Dec 22, 2024
9a961a4
Merge pull request #101 from vb2007/dev-fixes
vb2007 Dec 22, 2024
7a54462
inserted userName with /pay
vb2007 Dec 22, 2024
6ee0986
added self payment prevention, updated logic
vb2007 Dec 22, 2024
267bd25
made userId unique in db
vb2007 Dec 22, 2024
d4b25c1
updatedt table definition comments
vb2007 Dec 22, 2024
083a246
fixed false logging issues
vb2007 Dec 22, 2024
7f9c104
fixed typo, added logging, decreased time
vb2007 Dec 22, 2024
6eed011
fixed typo in description
vb2007 Dec 22, 2024
0f8773c
Merge pull request #102 from vb2007/dev-pay-fixes
vb2007 Dec 22, 2024
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
209 changes: 87 additions & 122 deletions commands/utility/help.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { SlashCommandBuilder } = require("discord.js");
const { embedReplyPrimaryColorWithFields, embedReplyErrorColorWithFields } = require("../../helpers/embeds/embed-reply");
const { embedReplyPrimaryColorWithFields, embedReplyErrorColorWithFields, embedReplyFailureColor } = require("../../helpers/embeds/embed-reply");
const { logToFileAndDatabase } = require("../../helpers/logger");
const db = require("../../helpers/db");

module.exports = {
data: new SlashCommandBuilder()
Expand All @@ -18,137 +19,101 @@ module.exports = {
{ name: "Administration", value: "administration" },
)
.setRequired(false))
.addStringOption(option =>
option
.setName("command")
.setDescription("Specify a command's name you would like to know more information about.")
.setRequired(false))
.setDMPermission(true),
async execute(interaction) {
const commandCategory = interaction.options.getString("category");

const utilityCommands =
{ name: "Utility", value:
"`/help` - Displays this message.\n" +
"`/ping` - Displays the discord API's current latency.\n" +
"`/ping-db` - Displays the current latency between the bot and it's database.\n" +
"`/server` - Provides information about the current server.\n" +
"`/user` - Provides information about a specified user.\n" +
"`/translate` - Translates a message from any language to any language.\n" +
"`/say` - Makes the bot say a specified message."
};

const funCommands =
{ name: "Fun", value:
"`/coinflip` - Flips a coin that has a 50/50 chance landing on heads or tails.\n" +
"`/randompic` - Send a random picture using the [picsum.photos](https://picsum.photos/) API.\n" +
"`/randomfeet` - I have nothing to say about my greatest shame...\n" +
"`/911-countdown` - Displays huw much time is left until Spetember 11th."
};

const economyCommands =
{ name: "Economy", value:
"`/work` - Lets you work for a random amount of money.\n" +
"`/beg` - Lets you beg for a random (or no) amount of money.\n" +
"`/rob` - Steals a random amount of money from the target user, and adds it to your balance.\n" +
"`/balance` - Displays the user's current bank and handheld balance.\n" +
"`/deposit` - Deposits money into the user's bank account. It has a daily limit for free deposits, but the users can choose to pay a small deposit fee if they exceed the limit.\n" +
"`/withdraw` - Withdraws money from the user's bank account.\n" +
"`/pay` - Transfers money from one user to another.\n" +
"`/roulette` - Lets you pick a color, then gives you a great price if you guess the color right.\n" +
"`/leaderboard` - Displays users with the most money on the server."
};

const moderationCommands =
{ name: "Moderation", value:
"**__NOTE__**: The following commands require relevant **moderation permissions** for both the bot and the command's executor to work.\n" +
"`/warn` - Warns a specified member on the server.\n" +
"`/timeout` - Times out a specified member for a specified time.\n" +
"`/kick` - Kicks a specified member from the server.\n" +
"`/ban` - Bans a specified member from the server.\n" +
"`/purge` - Purges (mass deletes) a specified amount of messages from the current channel."
};

const administrationCommands =
{ name: "Administration", value:
"**__NOTE__**: The following commands require relevant **administration permissions** for both the bot and the command's executor to work.\n" +
"`/autorole-configure` - Sets / modifies the autorole feature. When a new member joins the server, a specified role will get assigned to them automatically.\n" +
"`/autorole-disable` - Disables the autorole feature. New members won't get the specified role automatically on join anymore.\n" +
"`/welcome-configure` - Sets / modifies the welcome messages feature. When a new member joins the server, the bot send a specified welcome message.\n" +
"`/welcome-disable` - Disables the welcome messages feature. The bot won't send a welcome message on join anymore.\n" +
"`/logging-configure` - Sets / modifies the channel where event on the server will get logged.\n" +
"`/logging-disable` - Disables the logging feature. The bot won't log the events on the server anymore.\n" +
"`/bridge-configure` - Bridges all messages from one channel to another.\n" +
"`/bridge-disable` - Disables briding for a target channel.\n" +
"`/rename` - Renames a specified user to a specified nickname in the current server."
};

const tipField =
{ name: "Tip.", value:
"**Friendly reminder**: You can use `/help <category>` to get a list of commands from a specific category. :grin:"
const commandName = interaction.options.getString("command");

if (commandCategory && commandName) {
var embedReply = embedReplyFailureColor(
"Help: Error",
"Please only provide one parameter at a time for the command.",
interaction
);
}
else if (commandCategory) {
const commandsQuery = await db.query("SELECT name, category FROM commandData WHERE category = ? ORDER BY name", [commandCategory]);

if (commandsQuery.length === 0) {
var embedReply = embedReplyFailureColor(
"Help: Error",
"Invalid command category provided as parameter.\nPlease choose a valid category: `utility`, `fun`, `economy`, `moderation`, `administration`.",
interaction
);
}
else {
const commandsList = commandsQuery
.map(cmd => `\`/${cmd.name}\``)
.join(", ");

const errorField =
{ name: "Error", value:
"Invalid command category provided as parameter.\n" +
"Please choose a valid category: `utility`, `fun`, `economy`, `moderation`, `administration`."
var embedReply = embedReplyPrimaryColorWithFields(
`Help - ${commandCategory.charAt(0).toUpperCase() + commandCategory.slice(1)} Commands`,
`Here is a list of the bot's currently available **${commandCategory}** commands:`,
[{ name: "Commands", value: commandsList }],
interaction
);
}
}
else if (commandName) {
const commandQuery = await db.query("SELECT category, description FROM commandData WHERE name = ?", [commandName]);
const category = commandQuery[0]?.category || null;
const description = commandQuery[0]?.description || null;

if (!description) {
var embedReply = embedReplyFailureColor(
"Help - Error",
`There is no such command as \`/${commandName}\`.\nPlease provide a valid command name.`,
interaction
);
}
else {
var embedReply = embedReplyPrimaryColorWithFields(
`Help - /${commandName}`,
"You can check out all commands with descriptions on [the bot's wiki](https://github.com/vb2007/discordbot/wiki/Commands)",
[
{ name: "Category", value: category.charAt(0).toUpperCase() + category.slice(1) },
{ name: "Description", value: description }
],
interaction
);
}
}
else {
const allCommandsQuery = await db.query("SELECT name, category FROM commandData ORDER BY category, name");

let embedReply;
if (!commandCategory) {
embedReply = embedReplyPrimaryColorWithFields(
"Help - All Commands.",
"Here is a list of the bot's currently avaliable commands:",
[ utilityCommands, funCommands, economyCommands, moderationCommands, administrationCommands, tipField ],
//grouping commands by category
const commandsByCategory = allCommandsQuery.reduce((acc, cmd) => {
if (!acc[cmd.category]) {
acc[cmd.category] = [];
}
acc[cmd.category].push(cmd.name);
return acc;
}, {});

//fields for each category
const categoryFields = Object.entries(commandsByCategory).map(([category, commands]) => ({
name: category.charAt(0).toUpperCase() + category.slice(1),
value: commands.map(cmd => `\`/${cmd}\``).join(", ")
}));

var embedReply = embedReplyPrimaryColorWithFields(
"Help - All Commands",
"You can check out all commands with descriptions on [the bot's wiki](https://github.com/vb2007/discordbot/wiki/Commands)",
[
...categoryFields,
{
name: "Tip.",
value: "You can use `/help <category>` to get a list of commands from a specific category."
}
],
interaction
);
}
else {
switch (commandCategory) {
case "utility":
embedReply = embedReplyPrimaryColorWithFields(
"Help - Utility Commands.",
"Here is a list of the bot's currently avaliable **utility** commands:",
[ utilityCommands ],
interaction
);
break;
case "fun":
embedReply = embedReplyPrimaryColorWithFields(
"Help - Fun Commands.",
"Here is a list of the bot's currently avaliable **fun** commands:",
[ funCommands ],
interaction
);
break;
case "economy":
embedReply = embedReplyPrimaryColorWithFields(
"Help - Economy Commands.",
"Here is a list of the bot's currently avaliable **economy** commands:",
[ economyCommands ],
interaction
);
break;
case "moderation":
embedReply = embedReplyPrimaryColorWithFields(
"Help - Moderation Commands.",
"Here is a list of the bot's currently avaliable **moderation** commands:",
[ moderationCommands ],
interaction
);
break;
case "administration":
embedReply = embedReplyPrimaryColorWithFields(
"Help - Administration Commands.",
"Here is a list of the bot's currently avaliable **administration** commands:",
[ administrationCommands ],
interaction
);
break;
default:
embedReply = embedReplyErrorColorWithFields(
"Help - Utility Commands.",
"Here is a list of the bot's currently avaliable **utility** commands:",
[ errorField ],
interaction
);
}
}

await interaction.reply({ embeds: [embedReply] });

Expand Down
57 changes: 30 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading