Skip to content

Commit

Permalink
Merge pull request #98 from vb2007/dev
Browse files Browse the repository at this point in the history
Merge Dev to Main
  • Loading branch information
vb2007 authored Dec 17, 2024
2 parents a0b6902 + b69b5e7 commit 53971ae
Show file tree
Hide file tree
Showing 86 changed files with 1,692 additions and 414 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TOKEN=BOT-TOKE-GOES-HERE
CLIENT_ID=-BOT-CLIENT-ID-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
Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ I don't maintain any version that's not the latest.

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.
When reporting, please explain the vulnerability with as much details as possible.
6 changes: 3 additions & 3 deletions commands/administration/autorole-configure.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
const { embedReply } = require("../../helpers/embed-reply");
const { embedReply } = require("../../helpers/embeds/embed-reply");
const { embedColors } = require("../../config.json");
const { logToFileAndDatabase } = require("../../helpers/logger");
const db = require("../../helpers/db");
Expand Down Expand Up @@ -39,7 +39,7 @@ module.exports = {
const adderId = interaction.user.id;
const guildId = interaction.guild.id;

const query = await db.query("SELECT guildId, roleId FROM autorole WHERE guildId = ?", [guildId]);
const query = await db.query("SELECT guildId, roleId FROM configAutorole WHERE guildId = ?", [guildId]);
const autoRoleGuildId = query[0]?.guildId || null;
const autoRoleRoleId = query[0]?.roleId || null;

Expand Down Expand Up @@ -71,7 +71,7 @@ module.exports = {
);
}

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]);
await db.query("INSERT INTO configAutorole (guildId, roleId, adderId, adderUsername) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE roleId = ?, adderId = ?, adderUsername = ?", [guildId, targetRole, adderId, adderUsername, targetRole, adderId, adderUsername]);
}
}
catch (error) {
Expand Down
10 changes: 5 additions & 5 deletions commands/administration/autorole-disable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
const { embedReply } = require("../../helpers/embed-reply");
const { embedReply } = require("../../helpers/embeds/embed-reply");
const { embedColors } = require("../../config.json");
const { logToFileAndDatabase } = require("../../helpers/logger");
const db = require("../../helpers/db");
Expand Down Expand Up @@ -31,24 +31,24 @@ module.exports = {
try {
const currentGuildId = interaction.guild.id;
//we need rows, because the query gives back a messed up array
const query = await db.query("SELECT guildId FROM autorole WHERE guildId = ?", [currentGuildId]);
const query = await db.query("SELECT guildId FROM configAutorole WHERE guildId = ?", [currentGuildId]);
const autoroleGuildId = query[0]?.guildId || null;

if (autoroleGuildId) {
await db.query("DELETE FROM autorole WHERE guildId = ?", [autoroleGuildId]);
await db.query("DELETE FROM configAutorole WHERE guildId = ?", [autoroleGuildId]);

var localEmbedResponse = embedReply(
embedColors.success,
"AutoRole Disable: Success",
"The autorole feature has been disabled succesfully.\nYou can re-enable it with `/autorole-configure`.",
"The autorole feature has been disabled succesfully. :white_check_mark:\nYou can re-enable it with `/autorole-configure`.",
interaction
);
}
else {
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`.",
"Autorole has not been configured for this server. :x:\nTherefore, you can't disable it.\nYou can enable this feature with `/autorole-configure`.",
interaction
);
}
Expand Down
128 changes: 128 additions & 0 deletions commands/administration/bridge-configure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
const { embedReplySuccessColor, embedReplyFailureColor, embedReplySuccessSecondaryColor } = require("../../helpers/embeds/embed-reply");
const { logToFileAndDatabase } = require("../../helpers/logger");
const db = require("../../helpers/db");

module.exports = {
data: new SlashCommandBuilder()
.setName("bridge-configure")
.setDescription("Sets up bridging between a source channel on another server and a destination channel.") //...on the current one. [discord character limit]
.addStringOption(option =>
option
.setName("source-channel-id")
.setDescription("The ID of the source channel on another server.")
.setRequired(true)
)
.addChannelOption(option =>
option
.setName("destination-channel")
.setDescription("A channel where the bot will send the bridged messages.")
.addChannelTypes(0)
.setRequired(true)
)
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild)
.setDMPermission(false),
async execute(interaction) {
if (!interaction.inGuild()) {
var embedReply = embedReplyFailureColor(
"Bridge Configure: Error",
"You can only set up bridging in a server.",
interaction
);
}
else {
try {
const sourceChannelId = interaction.options.getString("source-channel-id");
const destinationChannel = interaction.options.getChannel("destination-channel");

const guildId = interaction.guild.id;
const guildName = interaction.guild.name;
const destinationChannelId = destinationChannel.id;
const destinationChannelName = destinationChannel.name;
const interactionUserId = interaction.user.id;
const interactionUsername = interaction.user.username;

const query = await db.query("SELECT destinationChannelId, sourceChannelId, destinationGuildId FROM configBridging WHERE sourceChannelId = ? AND destinationChannelId = ?", [sourceChannelId, destinationChannelId]);
const destinationGuildId = query[0]?.destinationGuildId || null;
const existingSourceChannelId = query[0]?.sourceChannelId || null;
const existingDestinationChannelId = query[0]?.destinationChannelId || null;

if (existingSourceChannelId == sourceChannelId && existingDestinationChannelId == destinationChannelId && destinationGuildId == guildId) {
var embedReply = embedReplyFailureColor(
"Bridge Configure: Error",
`Bridging has already been configured for the channel <#${sourceChannelId}> (\`${sourceChannelId}\`). :x:\n`,
interaction
);
}
else if (existingSourceChannelId == sourceChannelId && destinationGuildId == guildId) {
var embedReply = embedReplySuccessSecondaryColor(
"Bridge Configure: Configuration Modified",
`The destination channel for <#${sourceChannelId}> (\`${sourceChannelId}\`) has been updated to <#${destinationChannelId}>. :white_check_mark:\nRun this command again to modify the channel.`,
);

await db.query("UPDATE configBridging SET destinationChannelId = ?, destinationChannelName = ?, adderId = ?, adderUsername = ? WHERE sourceChannelId = ? AND destinationChannelId = ?",
[
destinationChannelId,
destinationChannelName,
interactionUserId,
interactionUsername,
sourceChannelId,
destinationChannelId
]
);
}
else if (existingSourceChannelId != sourceChannelId && destinationGuildId == guildId) {
var embedReply = embedReplySuccessColor(
"Bridge Configure: Success",
`Another channel has been added to bridging successfully. :white_check_mark:\nMessages from <#${sourceChannelId}> (\`${sourceChannelId}\`) will now get bridged to <#${destinationChannelId}>.`,
);

await db.query("INSERT INTO configBridging (sourceChannelId, destinationGuildId, destinationGuildName, destinationChannelId, destinationChannelName, adderId, adderUsername) VALUES (?, ?, ?, ?, ?, ?, ?)",
[
sourceChannelId,
guildId,
guildName,
destinationChannelId,
destinationChannelName,
interactionUserId,
interactionUsername
]
);
}
else {
var embedReply = embedReplySuccessColor(
"Bridge Configure: Success",
`Bridging has been successfully configured. :white_check_mark:\nMessages from <#${sourceChannelId}> (\`${sourceChannelId}\`) will now get bridged to <#${destinationChannelId}>.`,
interaction
);

await db.query("INSERT INTO configBridging (sourceChannelId, destinationGuildId, destinationGuildName, destinationChannelId, destinationChannelName, adderId, adderUsername) VALUES (?, ?, ?, ?, ?, ?, ?)",
[
sourceChannelId,
guildId,
guildName,
destinationChannelId,
destinationChannelName,
interactionUserId,
interactionUsername
]
);
}
}
catch (error) {
console.error(`Failed to configure bridging: ${error.message}\n${error.stack}`);
var embedReply = embedReplyFailureColor(
"Bridge Configure: Error",
"Failed to configure bridging. Please try again.",
interaction
);
}
}

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

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

module.exports = {
data: new SlashCommandBuilder()
.setName("bridge-disable")
.setDescription("Disables bridging from a source channel on another server.")
.addStringOption(option =>
option
.setName("source-channel-id")
.setDescription("The ID of the source channel you want to disable the briding for on another server.")
.setRequired(true)
)
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild)
.setDMPermission(false),
async execute(interaction) {
if (!interaction.inGuild()) {
var embedReply = embedReplyFailureColor(
"Bridge Disable: Error",
"You can only disable bridging in a server.",
interaction
);
}
else {
try {
const sourceChannelId = interaction.options.getString("source-channel-id");
const guildId = interaction.guild.id;

const query = await db.query("SELECT sourceChannelId, destinationGuildId FROM configBridging WHERE sourceChannelId = ? AND destinationGuildId = ?", [sourceChannelId, guildId]);
const existingGuildId = query[0]?.destinationGuildId || null;
const existingSourceChannelId = query[0]?.sourceChannelId || null;

if (existingSourceChannelId && existingGuildId) {
await db.query("DELETE FROM configBridging WHERE sourceChannelId = ? AND destinationGuildId = ?", [sourceChannelId, guildId]);
var embedReply = embedReplySuccessColor(
"Bridge Disable: Success",
`Bridging has been disabled for the channel <#${sourceChannelId}> (\`${sourceChannelId}\`). :white_check_mark:\nYou can re-enable this feature with \`/bridge-configure\`.`,
interaction
);
}
else {
var embedReply = embedReplyFailureColor(
"Bridge Disable: Error",
`Bridging has not been configured for the channel <#${sourceChannelId}> (\`${sourceChannelId}\`). :x:\nTherefore, you can't disable it.\nYou can enable this feature with \`/bridge-configure\`.`,
interaction
);
}
}
catch (error) {
console.error(`Error while disabling bridging: ${error}`);
var embedReply = embedReplyFailureColor(
"Bridge Disable: Error",
"An error occurred while disabling the bridging feature.\nPlease try again.",
interaction
);
}
}

await interaction.reply({ embeds: [embedReply] });
}
}
99 changes: 99 additions & 0 deletions commands/administration/logging-configure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
const { SlashCommandBuilder, PermissionFlagsBits } = require("discord.js");
const { embedReplySuccessColor, embedReplySuccessSecondaryColor, embedReplyFailureColor } = require("../../helpers/embeds/embed-reply");
const { logToFileAndDatabase } = require("../../helpers/logger");
const db = require("../../helpers/db");

module.exports = {
data: new SlashCommandBuilder()
.setName("logging-configure")
.setDescription("Sets up logging with various options for the current server.")
.addChannelOption(option =>
option
.setName("target-channel")
.setDescription("A channel where the bot will send the logged data.")
.addChannelTypes(0) //= text channels
.setRequired(true)
)
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild)
.setDMPermission(false),
async execute(interaction) {
if (!interaction.inGuild()) {
var embedReply = embedReplyFailureColor(
"Logging Configure: Error",
"You can only set up logging in a server.",
interaction
);
}
else if (!interaction.guild.members.me.permissions.has(PermissionFlagsBits.Administrator)) {
var embedReply = embedReplyFailureColor(
"Logging Configure: Error",
"Logging some actions requires **administrator** *(8)* privileges which the bot currently lacks.\nIf you want this feature to work properly, please re-invite the bot with accurate privileges.",
interaction
);
}
else {
try {
const targetChannel = interaction.options.getChannel("target-channel");
const interactionUserId = interaction.user.id;
const interactionUsername = interaction.user.username
const targetChannelId = targetChannel.id;
const targetChannelName = targetChannel.name;
const guildId = interaction.guild.id;

const query = await db.query("SELECT guildId, logChannelId FROM configLogging WHERE guildId = ?", [guildId]);
const existingGuildId = query[0]?.guildId || null;
const existingLogChannelId = query[0]?.logChannelId || null;

if (existingLogChannelId == targetChannelId) {
var embedReply = embedReplyFailureColor(
"Logging Configure: Error",
`Logging has already been configured for this server for the channel <#${targetChannelId}>. :x:\nRun the command with another channel to overwrite the current channel.`,
interaction
);
}
else {
if (existingGuildId == guildId) {
var embedReply = embedReplySuccessSecondaryColor(
"Logging Configure: Configuration Modified",
`The logging channel has been updated to <#${targetChannelId}>. :white_check_mark:\nRun this command again to modify the channel.\nRun \`/logging-disable\` to disable this feature completely.`,
interaction
);

await db.query("UPDATE configLogging SET logChannelId = ?, logChannelName = ?, lastModifierId = ?, lastModifierName = ? WHERE guildId = ?",
[
targetChannelId, targetChannelName, interactionUserId, interactionUsername, guildId
]
);
}
else {
var embedReply = embedReplySuccessColor(
"Logging Configure: Configuration Set",
`Logging has been set up for this server in <#${targetChannelId}>. :white_check_mark:\nRun this command again to modify the channel.\nRun \`/logging-disable\` to disable this feature completely.`,
interaction
);

await db.query("INSERT INTO configLogging (guildId, logChannelId, logChannelName, firstConfigurerId, firstConfigurerName) VALUES (?, ?, ?, ?, ?)",
[
guildId, targetChannelId, targetChannelName, interactionUserId, interactionUsername
]
);
}
}
}
catch (error) {
// console.error(`Failed to configure logging: ${error}`);
var embedReply = embedReplyFailureColor(
"Logging Configure: Error",
"Failed to configure logging. Please try again.",
interaction
);
}
}

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

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

0 comments on commit 53971ae

Please sign in to comment.