Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Dev to Main #98

Merged
merged 102 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
7254526
updated packages
vb2007 Oct 14, 2024
1daaafc
added logging configure / disable commands + base concept for logging…
vb2007 Oct 15, 2024
adaac3d
updated sql table schemas for logging
vb2007 Oct 18, 2024
ac9967a
added messageCreate event and logging script, updated table schema
vb2007 Oct 19, 2024
713a433
fixed logging
vb2007 Oct 19, 2024
bc3255e
added table schema for logging configuration
vb2007 Oct 19, 2024
c2cffba
updated table schema, updated logging-configure
vb2007 Oct 19, 2024
b3dfddc
added base for logging-disable
vb2007 Oct 20, 2024
816300f
added base logic for logging-disable
vb2007 Oct 20, 2024
a6c378f
fixed typos
vb2007 Oct 20, 2024
e0c0dbc
made logging to local db configureable
vb2007 Oct 20, 2024
4e7ea10
added events for logging (thx https://github.com/devdeem/Logger-Bot/t…
vb2007 Oct 20, 2024
a1986b5
replaced logging.js to common event script folder
vb2007 Oct 20, 2024
b93f2ee
corrected event placement
vb2007 Oct 20, 2024
c4de320
added embed message helpers in all colors
vb2007 Oct 21, 2024
cee458a
added logging on join
vb2007 Oct 21, 2024
f470c41
fixed table creation sql script
vb2007 Oct 21, 2024
0c27b6d
renamed function
vb2007 Oct 21, 2024
d345733
added channel creation logging, fixed typos in variable and function …
vb2007 Oct 21, 2024
bff8a61
added more permission requirements to the bot in index.js, fixed chan…
vb2007 Oct 21, 2024
4af9db2
seperated the embed helper functions and refactored the references to…
vb2007 Oct 21, 2024
b04f7f8
updated logging table
vb2007 Oct 21, 2024
aa0345c
fixed embed replies
vb2007 Oct 21, 2024
5104d73
added channel delete event logging
vb2007 Oct 21, 2024
0952041
fixed column name, added emojiCreate event, added more intents to ind…
vb2007 Oct 21, 2024
eeead30
fixed emojiCreate
vb2007 Oct 21, 2024
45f7868
added channel pin update event logging
vb2007 Oct 23, 2024
94c34f1
added emojiDelete event logging
vb2007 Oct 23, 2024
b3b73ac
added emojiUpdate event logging
vb2007 Oct 23, 2024
8554008
added emojiUpdate event logging
vb2007 Oct 23, 2024
36b37b5
added scripts for remaining events
vb2007 Oct 23, 2024
c101bb0
added script imports for remaining events
vb2007 Oct 23, 2024
6541393
updated packages
vb2007 Oct 24, 2024
1770ead
added query helper
vb2007 Oct 25, 2024
8376166
fixed helper, fixed logging channel actions, fixed other things
vb2007 Oct 25, 2024
4f0097b
fixed channel nsfw status change logging
vb2007 Oct 25, 2024
e1684bb
fixed channelUpdate event logging
vb2007 Oct 27, 2024
dfe1bcf
replaced repetetive script with helpers in other event scripts
vb2007 Oct 27, 2024
fec3d50
added logging for remaining events (except voiceStateUpdate)
vb2007 Oct 27, 2024
6ab61fe
fixed typos, updated color
vb2007 Oct 27, 2024
97114c7
uncommented some intents and partials in index.js
vb2007 Oct 27, 2024
18c08d4
fixed & added new member join logging
vb2007 Oct 27, 2024
fb46768
added logging voiceStateUpdate events
vb2007 Oct 27, 2024
c0a4de0
updated event logging embed colors
vb2007 Oct 27, 2024
cf95ef2
added embed message helpers with fields
vb2007 Oct 27, 2024
8d0d4a9
added channel type helper, updated channel creation logging
vb2007 Oct 28, 2024
f7f1e99
updated channel delete logging
vb2007 Oct 28, 2024
5ad1557
updated channel pin logging & channel update logging
vb2007 Oct 28, 2024
9e1f6af
updated other logging functions
vb2007 Oct 28, 2024
b3d8a09
updated more logging functions
vb2007 Oct 28, 2024
f2d0639
updated voice logging function
vb2007 Oct 28, 2024
326b9b6
added content check to messageupdate logging
vb2007 Oct 28, 2024
91953ab
added logging commands to /help
vb2007 Oct 29, 2024
ac46543
Merge pull request #96 from vb2007/dev-logging
vb2007 Oct 29, 2024
c01896a
added missing word to security
vb2007 Oct 29, 2024
050418c
added /bridge-configure and /bridge-disable commands
vb2007 Oct 29, 2024
36e0e91
added slash command documentation for /bridge-configure
vb2007 Oct 29, 2024
32bed78
added slash command documentation for /bridge-disable
vb2007 Oct 29, 2024
89004c1
changed autorole table name
vb2007 Oct 29, 2024
86474db
updated welcome table name
vb2007 Oct 29, 2024
f579c6c
added some action handling to /bridge-configure
vb2007 Oct 30, 2024
cfe375e
added configBridge table
vb2007 Oct 30, 2024
088f34c
updated modifiedAt column defaults
vb2007 Oct 30, 2024
4db051b
added first insert query
vb2007 Oct 30, 2024
e10eb27
added successful config case to /bridge-configure
vb2007 Oct 30, 2024
1596fc0
added another column to the query
vb2007 Oct 30, 2024
df3ce40
updated /bridge-configure with relevant checks and db updates
vb2007 Oct 30, 2024
9a08f04
whitespace fix
vb2007 Oct 30, 2024
262e9c8
added base concept for /bridge-disable
vb2007 Oct 31, 2024
fc35940
fixed command desc length
vb2007 Oct 31, 2024
4e7dad1
fixed table name
vb2007 Oct 31, 2024
6405f1a
fixed other typos in configure / disable commands
vb2007 Oct 31, 2024
cc864ae
added bridge event script
vb2007 Oct 31, 2024
2c47e68
added script to messageCreate event
vb2007 Oct 31, 2024
7b9c958
added client instance for fetching channel id on messagecreate event
vb2007 Oct 31, 2024
1572b49
removed logging
vb2007 Oct 31, 2024
e612476
added normal embed message to the bridge event script
vb2007 Oct 31, 2024
450f4b6
fixed function name
vb2007 Nov 12, 2024
28908ad
tried fixing shit, it didn't worked
vb2007 Nov 12, 2024
7fda619
updated packages
vb2007 Nov 12, 2024
7013f2b
fixed shit somehow
vb2007 Dec 12, 2024
9df1cf7
updated packages
vb2007 Dec 12, 2024
4bc9b94
fixed messageUpdate event
vb2007 Dec 13, 2024
1068656
added empty message check to message logging
vb2007 Dec 13, 2024
2a5fe98
fixed typo
vb2007 Dec 13, 2024
2cfb007
fixed channelCreate event
vb2007 Dec 13, 2024
89586a7
fixed channelDelete event
vb2007 Dec 13, 2024
c1dc743
fixed channelPinsUpdate event
vb2007 Dec 13, 2024
19df2ae
partially fixed channelUpdate event
vb2007 Dec 14, 2024
d888543
fixed emojiCreate event
vb2007 Dec 14, 2024
46f1b20
fixed emojiDelete event
vb2007 Dec 14, 2024
309381e
fixed emojiUpdate event
vb2007 Dec 14, 2024
40b41a7
probably fixed guildBanAdd event
vb2007 Dec 14, 2024
c46de2e
fixed event parameters
vb2007 Dec 14, 2024
06b06b0
fixed the rest of the logging events
vb2007 Dec 15, 2024
41292ce
added trycatch to prevent fatal errors in runtime
vb2007 Dec 15, 2024
eddee24
removed duplicate data logging
vb2007 Dec 15, 2024
2f9efe8
fixed minor issues in events
vb2007 Dec 15, 2024
9ef62c5
changed embed looks of messageDelete event logging
vb2007 Dec 15, 2024
c91e4da
renamed sql query folder after the table
vb2007 Dec 15, 2024
a1a4d0b
added bridge commands to /help
vb2007 Dec 17, 2024
b69b5e7
Merge pull request #97 from vb2007/dev-bridge
vb2007 Dec 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading