Skip to content

Commit

Permalink
Merge pull request #92 from vb2007/dev
Browse files Browse the repository at this point in the history
Merge Dev to Main
  • Loading branch information
vb2007 authored Oct 12, 2024
2 parents 986cb24 + 747c1d4 commit a0b6902
Show file tree
Hide file tree
Showing 18 changed files with 1,598 additions and 161 deletions.
41 changes: 41 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Discordbot contributing guide

Thank you for investing your time in contributing to this project.

When contributing, please make sure to always follow the project's [CODE OF CONDUCT](./CODE_OF_CONDUCT.md).

This guide will help you get some ground about how contributions work.

## Contributing

### Issues

If you found a bug, or you think the project needs new commands / features, please open an issue on the project's [issues page](https://github.com/vb2007/discordbot/issues/new).

If possible, please go with an issue template.

Before opening an issue, make sure it hasn't been reported already by somebody else. [Project's existing issues.](https://github.com/vb2007/discordbot/issues)

#### Reporting bugs

If you found a bug with the bot, please make sure to explain the issue with as much details as possible, and **attack screenshots / videos**.

### Pull requests

#### Basic steps for newcomers

1. Fork the repository
2. Clone your fork
3. Make your changes with relevant commit messages
4. Push your commits
5. When you're done, open a Pull Request (PR)

#### Making changes

When making changes to the codebase, please watch out for the following:

- Don't remove code that's essential for the project to work properly
- Try to write optimal code
- Make sure the project passes all unit tests after your changes

After you're done, make a Pull Request to the `dev` branch. If possible, please link an issue / issues to your PR.
20 changes: 20 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Security Policy

## Supported Versions

Currently, only the latest version of the project gets regular security updates and pathces.

If the latest version has any vulnerability, it is likely going to get patched in the next release.

I don't maintain any version that's not the latest.

| Version | Supported |
| -------- | ------------------ |
| > latest | :white_check_mark: |
| < latest | :x: |

## Reporting a Vulnerability

You can report a vulnerability on the [repository's security page](https://github.com/vb2007/discordbot/security).

When reporting, please explain the with as much details as possible.
10 changes: 5 additions & 5 deletions commands/administration/autorole-configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
var localEmbedResponse = embedReply(
embedColors.failure,
"AutoRole Configure: Error",
"You can only set autorole in a server.",
"You can only set up autorole in a server.",
interaction
);
}
Expand All @@ -43,12 +43,12 @@ module.exports = {
const autoRoleGuildId = query[0]?.guildId || null;
const autoRoleRoleId = query[0]?.roleId || null;

//if autorole has already been configured at this server...
//if autorole has already been configured for this server...
if (autoRoleRoleId == targetRole) {
var localEmbedResponse = embedReply(
embedColors.failure,
"AutoRole Configure: Error",
"Autorole has been already configured for this server with this role. :x:\nRun the command with another role to overwrite the current role.\nRun `/autorole-disable` to disable this feature.",
"Autorole has already been configured for this server with this role. :x:\nRun the command with another role to overwrite the current role.\nRun `/autorole-disable` to disable this feature completely.",
interaction
);
}
Expand All @@ -58,15 +58,15 @@ module.exports = {
var localEmbedResponse = embedReply(
embedColors.successSecondary,
"AutoRole Configure: Configuration Modified",
`The role that will get assigned to new members has been **modified** to \`@<${targetRole}>\` :white_check_mark:\nRun this command again to modify the role.\nRun \`/autorole-disable\` to disable this feature.`,
`The role that will get assigned to new members has been **modified** to <@&${targetRole}>. :white_check_mark:\nRun this command again to modify the role.\nRun \`/autorole-disable\` to disable this feature.`,
interaction
);
}
else {
var localEmbedResponse = embedReply(
embedColors.success,
"AutoRole Configure: Configuration Set",
`The role that will get assigned to new members has been **set** to \`@<${targetRole}>\` :white_check_mark:\nRun this command again to modify the role.\nRun \`/autorole-disable\` to disable this feature.`,
`The role that will get assigned to new members has been **set** to <@&${targetRole}>. :white_check_mark:\nRun this command again to modify the role.\nRun \`/autorole-disable\` to disable this feature.`,
interaction
);
}
Expand Down
138 changes: 138 additions & 0 deletions commands/administration/welcome-configure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
const { embedReplySuccessColor, embedReplySuccessSecondaryColor, embedReplyWarningColor, embedReplyFailureColor } = require("../../helpers/embed-reply");
const { logToFileAndDatabase } = require("../../helpers/logger");
const db = require("../../helpers/db");

module.exports = {
data: new SlashCommandBuilder()
.setName("welcome-configure")
.setDescription("Sets a welcome message that will be displayed for the new members in a specified channel.")
.addChannelOption(option =>
option
.setName("channel")
.setDescription("A channel where the welcome message will be displayed.")
.addChannelTypes(0) //= GUILD_TEXT aka. text channels
.setRequired(true)
)
.addStringOption(option =>
option
.setName("message")
//the description length is limited to 100 characters ¯\_(ツ)_/¯
.setDescription("A message that the new members will see.") //You can use the following placeholders: {user} - the new member's username, {server} - the server's name, {memberCount} - the server's member count.
.setRequired(true)
)
.addBooleanOption(option =>
option
.setName("embed")
.setDescription("Whether the message should be sent as an embed (doesn't supports pinging users).")
.setRequired(false)
)
.addIntegerOption(option =>
option
.setName("embed-color")
.setDescription("The HEX color of the embed message. Leave empty for default color.")
.setRequired(false)
)
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild)
.setDMPermission(false),
async execute(interaction) {
if (!interaction.inGuild()) {
var embedReply = embedReplyFailureColor(
"Welcome Configure: Error",
"You can only set a welcome message in a server.",
interaction
);
}
else if (!interaction.guild.members.me.permissions.has(PermissionFlagsBits.Administrator)) {
var embedReply = embedReplyFailureColor(
"Welcome Disable: Error",
"This feature requires **administrator** *(8)* privileges which the bot currently lacks.\nIf you want this feature to work, please re-invite the bot with accurate privileges.",
interaction
);
}
else {
try {
const channelId = interaction.options.getChannel("channel").id;
const welcomeMessage = interaction.options.getString("message");
const isEmbed = interaction.options.getBoolean("embed") || 0;
const embedColor = interaction.options.getInteger("embed-color") || null;

const guildId = interaction.guild.id;
const adderId = interaction.user.id;
const adderUsername = interaction.user.username;

const query = await db.query("SELECT channelId, message, isEmbed, embedColor FROM welcome WHERE guildId = ?", [guildId]);
const existingChannelId = query[0]?.channelId || null;
const existingWelcomeMessage = query[0]?.message || null;
const existingIsEmbed = query[0]?.isEmbed || 0;
const existingEmbedColor = query[0]?.embedColor || null;

//if welcome messages haven't been configured for the current server
if (!existingChannelId) {
var embedReply = embedReplySuccessColor(
"Welcome Configure: Configuration Set",
"The **welcome message** has been successfully **set**. :white_check_mark:\nRun this command again later if you want to modify the current configuration.\nRun `/welcome-disable` if you want to disable this feature.",
interaction
);
}
else {
//checks if anything has been modified in the the command
let modifications = [];
if (welcomeMessage != existingWelcomeMessage) {
modifications.push("**welcome message**");
}
if (isEmbed != existingIsEmbed) {
modifications.push("**embed option**");
}
if (embedColor != existingEmbedColor) {
modifications.push("**embed color**");
}
if (channelId != existingChannelId) {
modifications.push(`**welcome channel** to <#${channelId}>`);
}

//if the exact same welcome configuration is set for the current server (aka. nothing got modified)
if (modifications.length === 0) {
var embedReply = embedReplyWarningColor(
"Welcome Configure: Warning",
"The exact same welcome configuration has been set for this server already. :x:\nRun the command again with different options to overwrite the current configuration.\nRun `/welcome-disable`, if you want to disable this feature.",
interaction
);
}
//if the welcome configuration has been modified
else {
let modificationsMessage;
if (modifications.length === 1) {
modificationsMessage = modifications[0];
} else {
modificationsMessage = modifications.slice(0, -1).join(", ") + " and " + modifications[modifications.length - 1];
}

var embedReply = embedReplySuccessSecondaryColor(
"Welcome Configure: Configuration Modified",
`Successfully modified ${modificationsMessage}. :white_check_mark:\nRun the command again with different options to overwrite the current configuration.\nRun \`/welcome-disable\`, if you want to disable this feature.`,
interaction
);
}
}

await db.query("INSERT INTO welcome (guildId, channelId, message, isEmbed, embedColor, adderId, adderUsername) VALUES (?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE channelId = ?, message = ?, adderId = ?, adderUsername = ?, isEmbed = ?, embedColor = ?",
[guildId, channelId, welcomeMessage, isEmbed, embedColor, adderId, adderUsername, channelId, welcomeMessage, adderId, adderUsername, isEmbed, embedColor]
);
}
catch (error) {
var embedReply = embedReplyFailureColor(
"Welcome Configure: Error",
"There was an error while trying to configure the welcome messages.",
interaction
);
}
}

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

//logging
const response = JSON.stringify(embedReply.toJSON());
await logToFileAndDatabase(interaction, response);
}
}
62 changes: 62 additions & 0 deletions commands/administration/welcome-disable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
const { embedReplyPrimaryColor, embedReplyFailureColor, embedReplyWarningColor, embedReplySuccessColor } = require("../../helpers/embed-reply");
const { logToFileAndDatabase } = require("../../helpers/logger");
const db = require("../../helpers/db");

module.exports = {
data: new SlashCommandBuilder()
.setName("welcome-disable")
.setDescription("Disables welcome messages for the current server.")
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild)
.setDMPermission(false),
async execute(interaction) {
if (!interaction.inGuild()) {
var embedReply = embedReplyFailureColor(
"Welcome Disable: Error",
"You can only disable the welcome messages in a server.",
interaction
);
}
else if (!interaction.guild.members.me.permissions.has(PermissionFlagsBits.Administrator)) {
var embedReply = embedReplyFailureColor(
"Welcome Disable: Error",
"This feature requires **administrator** *(8)* privileges which the bot currently lacks.\nIf you want this feature to work, please re-invite the bot with accurate privileges.",
interaction
);
}
else {
try {
const currentGuildId = interaction.guild.id;
const query = await db.query("SELECT guildId FROM welcome WHERE guildId = ?", [currentGuildId]);
const welcomeGuildId = query[0]?.guildId || null;

if (welcomeGuildId) {
await db.query("DELETE FROM welcome WHERE guildId = ?", [welcomeGuildId]);

var embedReply = embedReplySuccessColor(
"Welcome Disable: Success",
"The welcome messages have been disabled successfully for this server.\nYou can re-enable them with the `/welcome-configure` command.",
interaction
);
}
else {
var embedReply = embedReplyWarningColor(
"Welcome Disable: Warning",
"Welcome messages have not been configured for this server.\nTherefore, you can't disable them.\nYou can enable this feature with the `/welcome-configure` command.",
interaction
);
}
}
catch (error) {
var embedReply = embedReplyFailureColor(
"Welcome Disable: Error",
"There was an error while trying to disable the welcome messages.",
interaction
);
// console.error(error);
}
}

await interaction.reply({ embeds: [embedReply] });
}
}
3 changes: 3 additions & 0 deletions commands/utility/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = {
"`/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."
};

Expand Down Expand Up @@ -68,6 +69,8 @@ module.exports = {
"**__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" +
"`/rename` - Renames a specified user to a specified nickname in the current server."
};

Expand Down
Loading

0 comments on commit a0b6902

Please sign in to comment.