Skip to content

Commit

Permalink
Merge pull request #65 from vb2007/dev
Browse files Browse the repository at this point in the history
Merge Dev to Main
  • Loading branch information
vb2007 authored Sep 21, 2024
2 parents f090144 + e3c333b commit 8973b74
Show file tree
Hide file tree
Showing 42 changed files with 1,848 additions and 1,162 deletions.
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
TOKEN=BOT-TOKE-GOES-HERE
CLIENT_ID=-BOT-CLIENT-ID-GOES-HERE

DATABASE_HOST_ADDRESS=AN-IP-ADDRESS-OR-DOMAIN-TO-YOUR-DATABASE
DATABASE_NAME=YOUR-DATABASE-NAME
DATABASE_USER=YOUR-DATABASES-USERNAME
DATABASE_PASSWORD=YOUR-DATABASES-PASSWORD
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Use Node.js
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
config.json
/node_modules
/test
Expand Down
33 changes: 8 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# Discord bot

A simple discord bot of mine developed with discord.js (Node.js).

I mainly use it to get the active developer badge on Discord.
A simple discord bot of mine developed with **Node.js**'s [discord.js](https://www.npmjs.com/package/discord.js?activeTab=readme) package.

## Invite the bot

**You can invite the bot to your server using [THIS](https://discord.com/oauth2/authorize?client_id=1163073430309044234&scope=bot&permissions=8) link.**

The bot requires administartor permissions.
The bot requires administartor permissions (*&permissions=8*).

I'm hosting it, should be online 24/7.

Expand All @@ -18,31 +16,16 @@ I'm hosting it, should be online 24/7.

Do the following for setting up the application from sratch:

1. Clone the repo.
2. Create a `config.json` file in the repo's folder and paste the content above, then fill it out with the correct details:
```json
{
"token" : "[your token]",
"clientId" : "[your client id]",

"databaseHostAddress" : "[database host ip]:[database host port]",
"databaseName" : "[database name]",
"databaseUser" : "[database username]",
"databasePassword" : "[database user's password]",

"logToFile" : "[True/False]",
"logToDatabase" : "[True/False]"
}
```
3. Like you would with any other node.js app, install dependencies with with the `npm i` command.
1. Clone the repository.
2. Create a `.env` file, or rename the existing [.env.example](./.env.example) file, and fill it out with the required data.
3. Create a `config.json` file, or rename the existing [config.json.example](./config.json.example) file, and fill it out with the required configuration settings.
4. Like you would with any other node.js app, install dependencies with with the `npm i` command.

### Setting up a database for the bot

Some of the bot's features require a MariaDB database.

If you already have a working database, and filled up the details in the `config.json` file for the connection, you can run `npm run create-tables`.
Some of the bot's features **require a MariaDB database**.

This will automatically create the tables based on the SQL queries that can be found in the [sql folder](sql/).
If you already have a working database, and have filled up the connection details in the `.env` file for the connection, you can just run `npm run create-tables`. This will automatically create the tables based on the SQL queries that can be found in the [sql folder](sql/).

Otherwise, please refer to [THIS](documentation/mariadb-setup.md) documentation for addittional help about setting up a database.

Expand Down
112 changes: 0 additions & 112 deletions archived-commands/index2.js

This file was deleted.

55 changes: 36 additions & 19 deletions commands/administration/autorole-configure.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { EmbedBuilder, SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
const { embedReply } = require("../../helpers/embed-reply");
const { embedColors } = require("../../config.json");
const { logToFileAndDatabase } = require("../../helpers/logger");
const db = require("../../helpers/db");

Expand All @@ -15,10 +17,20 @@ module.exports = {
.setDMPermission(false),
async execute(interaction) {
if (!interaction.inGuild()) {
var replyContent = "You can only set autorole in a server.";
var localEmbedResponse = embedReply(
embedColors.failure,
"AutoRole Configure: Error",
"You can only set autorole in a server.",
interaction
);
}
else if (!interaction.guild.members.me.permissions.has(PermissionFlagsBits.Administrator)) {
var replyContent = "This feature requires **administrator** *(8)* privileges witch the bot currently lacks.\nIf you want this feature to work, please re-invite the bot with accurate privileges."
var localEmbedResponse = embedReply(
embedColors.failure,
"AutoRole Configure: Error",
"This feature requires **administrator** *(8)* privileges witch the bot currently lacks.\nIf you want this feature to work, please re-invite the bot with accurate privileges.",
interaction
);
}
else {
try {
Expand All @@ -33,16 +45,32 @@ module.exports = {

//if autorole has already been configured at this server...
if (autoRoleRoleId == targetRole) {
replyContent = "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.";
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.",
interaction
);
}
else {
if (autoRoleGuildId == guildId) {
//if the target role is already the role that's in the database, then we don't need to insert data
replyContent = `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.`;
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.`,
interaction
);
}
else {
var replyContent = `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."`
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.`,
interaction
);
}

await db.query("INSERT INTO autorole (guildId, roleId, adderId, adderUsername) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE roleId = ?, adderId = ?, adderUsername = ?", [guildId, targetRole, adderId, adderUsername, targetRole, adderId, adderUsername]);
}
}
Expand All @@ -51,21 +79,10 @@ module.exports = {
}
}

var embedReply = new EmbedBuilder({
color: 0x5F0FD6,
title: "Configuring autorole.",
description: replyContent,
timestamp: new Date().toISOString(),
footer: {
text: `Requested by: ${interaction.user.username}` ,
icon_url: interaction.user.displayAvatarURL({ dynamic: true }),
},
});

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

//logging
const response = JSON.stringify(embedReply.toJSON());
const response = JSON.stringify(localEmbedResponse.toJSON());
await logToFileAndDatabase(interaction, response);
}
}
47 changes: 29 additions & 18 deletions commands/administration/autorole-disable.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { EmbedBuilder, SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
const { embedReply } = require("../../helpers/embed-reply");
const { embedColors } = require("../../config.json");
const { logToFileAndDatabase } = require("../../helpers/logger");
const db = require("../../helpers/db");

Expand All @@ -10,10 +12,20 @@ module.exports = {
.setDMPermission(false),
async execute(interaction) {
if (!interaction.inGuild()) {
var replyContent = "You can only disable autorole in a server."
var localEmbedResponse = embedReply(
embedColors.failure,
"AutoRole Disable: Error",
"You can only disable autorole in a server.",
interaction
);
}
else if (!interaction.guild.members.me.permissions.has(PermissionFlagsBits.Administartor)) {
var replyContent = "This feature requires **administrator** *(8)* privileges witch the bot currently lacks.\nIf you want this feature to work, please re-invite the bot with accurate privileges."
var localEmbedResponse = embedReply(
embedColors.failure,
"AutoRole Disable: Error",
"This feature requires **administrator** *(8)* privileges witch the bot currently lacks.\nIf you want this feature to work, please re-invite the bot with accurate privileges.",
interaction
);
}
else {
try {
Expand All @@ -25,32 +37,31 @@ module.exports = {
if (autoroleGuildId) {
await db.query("DELETE FROM autorole WHERE guildId = ?", [autoroleGuildId]);

var replyContent = "The autorole feature has been disabled succesfully.\nYou can re-enable it with `/autorole-configure`.";
var localEmbedResponse = embedReply(
embedColors.success,
"AutoRole Disable: Success",
"The autorole feature has been disabled succesfully.\nYou can re-enable it with `/autorole-configure`.",
interaction
);
}
else {
var replyContent = "Autorole has not been configured for this server.\nTherefore, you can't disable it.\nYou can enable this feature with `/autorole-configure`";
var localEmbedResponse = embedReply(
embedColors.warning,
"AutoRole Disable: Warning",
"Autorole has not been configured for this server.\nTherefore, you can't disable it.\nYou can enable this feature with `/autorole-configure`.",
interaction
);
}
}
catch (error) {
console.error(error);
}
}

var embedReply = new EmbedBuilder({
color: 0x5F0FD6,
title: "Disabling autorole.",
description: replyContent,
timestamp: new Date().toISOString(),
footer: {
text: `Requested by: ${interaction.user.username}` ,
icon_url: interaction.user.displayAvatarURL({ dynamic: true }),
},
});

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

//logging
const response = JSON.stringify(embedReply.toJSON());
const response = JSON.stringify(localEmbedResponse.toJSON());
await logToFileAndDatabase(interaction, response);
},
};
Loading

0 comments on commit 8973b74

Please sign in to comment.