-
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 #98 from vb2007/dev
Merge Dev to Main
- Loading branch information
Showing
86 changed files
with
1,692 additions
and
414 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
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
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,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); | ||
} | ||
} |
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,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] }); | ||
} | ||
} |
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,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); | ||
} | ||
} |
Oops, something went wrong.