-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from vb2007/dev
Merge Dev to Main
- Loading branch information
Showing
18 changed files
with
1,598 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.