Skip to content

Commit

Permalink
v4.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
JH220 committed Jul 22, 2024
1 parent 72c6461 commit 656fe2c
Show file tree
Hide file tree
Showing 18 changed files with 446 additions and 203 deletions.
17 changes: 13 additions & 4 deletions messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"COMMAND_CLEARALL_MISSING_CHANNEL_PERM": "The bot does not have the necessary permissions to clone this channel.\nMissing permission: **{PERMISSION}**\nPlease make sure this permission is set on **this channel**.\nIf you need help, please visit our [Discord support server](https://discord.gg/HW9tA4Mp3b).",
"COMMAND_CLEARALL_MISSING_CATEGORY_PERM": "The bot does not have the necessary permissions to clone this channel.\nMissing permission: **{PERMISSION}**\nPlease make sure this permission is set on **this category**.\nIf you need help, please visit our [Discord support server](https://discord.gg/HW9tA4Mp3b).",
"COMMAND_CLEARALL_MISSING_GUILD_PERM": "The bot does not have the necessary permissions to clone this channel.\nMissing permission: **{PERMISSION}**\nPlease make sure this permission is set on **this server**.\nAlternatively, you can put this channel in a category and give the bot the necessary permissions there.\nIf you need help, please visit our [Discord support server](https://discord.gg/HW9tA4Mp3b).",
"COMMAND_CLEARALL_CATEGORY_FULL": "The category already contains the maximum number of channels.\nBecause the bot needs to clone the channel, it is not possible to create a new channel in this category.\nPlease delete a channel in this category or create a new category in order to use this command.\nIf you need help, please visit our [Discord support server](https://discord.gg/HW9tA4Mp3b).",
"COMMAND_CLEARALL_ERROR": "There was an error while clearing this channel.\nPlease check if the bot has all the neccessary permissions!\nIf you need help, please visit our [Discord support server](https://discord.gg/HW9tA4Mp3b).",
"COMMAND_CLEARALL_DELETE_ERROR": "I can not delete this channel.\nPlease note that I can only delete channels not used for community server purposes (rules and public updates channel).\nIf you need help, please visit our [Discord support server](https://discord.gg/HW9tA4Mp3b).",
"COMMAND_CLEARALL_SUCCESS": "{USER} deleted all messages in this channel.",
Expand All @@ -22,17 +23,25 @@
"COMMAND_SETTINGS_BUTTON_RESET_ALL": "Reset all settings",
"INTERACTION_SETTINGS_RESET": "All settings have been reset to their default values.",
"INTERACTION_SETTINGS_TOGGLE_CONFIRMATION_MESSAGES": "Switched the setting for confirmation messages to {STATE}.",
"COMMAND_ADMIN_GET_USER_EMBED": "Information about the user.\n",
"COMMAND_ADMIN_GET_SERVER_EMBED_TITLE": "ClearChat-Bot Admin Server Information 📊",
"COMMAND_ADMIN_GET_SERVER_EMBED": "Information about the server.\n",
"COMMAND_ADMIN_STATS_STILL_STARTING": "The statistics are still being collected.\nPlease try again later.",
"COMMAND_ADMIN_STATS_EMBED_TITLE": "ClearChat-Bot Admin Stats 📊",
"INTERACTION_ADMIN_GET_USER_BAN_SUCCESS": "The user {BAN_USER} has been banned.",
"INTERACTION_ADMIN_GET_USER_PARDON_SUCCESS": "The User {BAN_USER} has been pardoned.",
"INTERACTION_ADMIN_GET_USER_BAN_CONFIRM_ERROR_ALREADY_BANNED": "The user {BAN_USER} is already banned.",
"INTERACTION_ADMIN_GET_USER_PARDON_CONFIRM_ERROR_ALREADY_PARDONED": "The user {BAN_USER} is already pardoned.",
"INTERACTION_ADMIN_GET_USER_BAN_HISTORY_EMBED_TITLE": "ClearChat-Bot Admin User Ban History 📜",
"INTERACTION_ADMIN_GET_OVERVIEW_EMBED_TITLE": "ClearChat-Bot Admin User Information 📊",
"INTERACTION_ADMIN_GET_USER_EMBED_TITLE": "ClearChat-Bot Admin User Information 📊",
"INTERACTION_ADMIN_GET_USER_EMBED": "Information about the user.\n",
"INTERACTION_ADMIN_GET_SERVER_BAN_SUCCESS": "The server {SERVER} has been banned.",
"INTERACTION_ADMIN_GET_SERVER_PARDON_SUCCESS": "The server {SERVER} has been pardoned.",
"INTERACTION_ADMIN_GET_SERVER_BAN_CONFIRM_ERROR_ALREADY_BANNED": "The server {SERVER} is already banned.",
"INTERACTION_ADMIN_GET_SERVER_PARDON_CONFIRM_ERROR_ALREADY_PARDONED": "The server {SERVER} is already pardoned.",
"INTERACTION_ADMIN_GET_SERVER_BAN_HISTORY_EMBED_TITLE": "ClearChat-Bot Admin Server Ban History 📜",
"INTERACTION_ADMIN_GET_SERVER_EMBED_TITLE": "ClearChat-Bot Admin Server Information 📊",
"INTERACTION_ADMIN_GET_SERVER_EMBED": "Information about the server.\n",
"INTERACTION_ADMIN_GET_INTERACTION_EMBED_TITLE": "ClearChat-Bot Admin Interaction Information 📊",
"INTERACTION_ADMIN_GET_INTERACTION_EMBED": "Information about the interaction.\n",
"ERROR_EXECUTE": "There was an error while executing this command!\nPlease report it to: https://github.com/JH220/discord-clearchatbot/issues/new?title=Interaction-ID%3A+{INTERACTION_ID}&template=command_error.md\nInteraction-ID: **{INTERACTION_ID}**\nFor more information, visit our [Discord support server](https://discord.gg/HW9tA4Mp3b).",
"ERROR_EXECUTE_DATABASE_NO_CONNECTION": "The bot is currently unable to connect to the database.\nPlease try again later.\nIf the problem persists, please visit our [Discord support server](https://discord.gg/HW9tA4Mp3b).\nInteraction-ID: **{INTERACTION_ID}**",
"SETTINGS_EMBED": "This is the server-side settings page of the ClearChat bot.\nYou can select a setting from the drop-down menu below this message and then enable or disable it.\nTo reset all settings to their default values, click \"Reset all settings\" there."
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clearchatbot",
"version": "4.1.0",
"version": "4.1.1",
"description": "A feature-rich moderation bot of your Discord server for channel management and structuring your chat.",
"main": "./dist/index.js",
"scripts": {
Expand Down
5 changes: 4 additions & 1 deletion src/commands/main/clearall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module.exports = {
if (interaction.channel.parent) {
if (!member.permissionsIn(interaction.channel.parent).has(PermissionsBitField.Flags.ManageChannels))
return await database.reply(interaction, 'COMMAND_CLEARALL_MISSING_CATEGORY_PERM', { 'PERMISSION': 'Manage Channels' });
if (interaction.channel.parent.children.cache.size >= 50)
return await database.reply(interaction, 'COMMAND_CLEARALL_CATEGORY_FULL');
}
else if (!member.permissions.has(PermissionsBitField.Flags.ManageChannels))
return await database.reply(interaction, 'COMMAND_CLEARALL_MISSING_GUILD_PERM', { 'PERMISSION': 'Manage Channels' });
Expand All @@ -49,7 +51,8 @@ module.exports = {
if (!(settings?.showreply ?? true)) return;

try {
channel.send(await database.getMessage('COMMAND_CLEARALL_SUCCESS', interaction));
const message = await database.getMessage('COMMAND_CLEARALL_SUCCESS', interaction);
if (message) channel.send(message);
}
catch (error) {
await (interaction.client as CustomClient).ierror(interaction, error, 'Error while sending message to new channel');
Expand Down
8 changes: 3 additions & 5 deletions src/commands/main/settings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { SlashCommandBuilder } from '@discordjs/builders';
import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, ChatInputCommandInteraction, EmbedBuilder, StringSelectMenuBuilder, StringSelectMenuInteraction, StringSelectMenuOptionBuilder } from 'discord.js';
import { CustomClient } from '../../bot';
import { Sequelize } from 'sequelize';

module.exports = {
Expand All @@ -23,18 +22,17 @@ module.exports = {
);
const resetButton = new ButtonBuilder()
.setCustomId('settings_reset')
.setLabel(await database.getMessage('COMMAND_SETTINGS_BUTTON_RESET_ALL', interaction))
.setLabel(await database.getMessage('COMMAND_SETTINGS_BUTTON_RESET_ALL', interaction) ?? 'COMMAND_SETTINGS_BUTTON_RESET_ALL')
.setStyle(ButtonStyle.Danger)
.setEmoji('🔄');

await interaction.reply({ embeds: [ new EmbedBuilder()
.setColor('#00FFFF')
.setTitle(await database.getMessage('COMMAND_SETTINGS_EMBED_TITLE', interaction))
.setDescription(await database.getMessage('COMMAND_SETTINGS_EMBED', interaction)),
.setTitle(await database.getMessage('COMMAND_SETTINGS_EMBED_TITLE', interaction) ?? 'COMMAND_SETTINGS_EMBED_TITLE')
.setDescription(await database.getMessage('COMMAND_SETTINGS_EMBED', interaction) ?? 'COMMAND_SETTINGS_EMBED'),
], components: [new ActionRowBuilder().addComponents(select) as any, new ActionRowBuilder().addComponents(resetButton)] });

await database.reply(interaction, 'COMMAND_SETTINGS_SUCCESS', {}, false);
await (interaction.client as CustomClient).idebug(interaction, 'Replied to settings command');
},
async executeButton(interaction : ButtonInteraction, database : any) {
const customId = interaction.customId.split(';')[0];
Expand Down
1 change: 0 additions & 1 deletion src/commands/utility/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ module.exports = {
return database.reply(interaction, 'COMMAND_ADMIN_INVALID_ID', { 'ID': id });
}
case 'stats': return require('./admin/stats').execute(interaction, database);
case 'ban': return require('./admin/ban').execute(interaction, database);
}
},
};
107 changes: 107 additions & 0 deletions src/commands/utility/admin/get/interaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, ChatInputCommandInteraction, EmbedBuilder, Interaction } from 'discord.js';
import { Sequelize } from 'sequelize';
import { CustomClient } from '../../../../bot';

const adminGetUser = require('./user');
const adminGetServer = require('./server');

module.exports = {
async execute(interaction : ChatInputCommandInteraction, database : any, entry : any) {
await interaction.reply(await getReply(interaction, entry, database) as any);
await database.reply(interaction, 'COMMAND_ADMIN_GET_INTERACTION_SUCCESS', {}, false);
},
async executeButton(interaction : ButtonInteraction, database : any) {
switch (interaction.customId.split(';')[0]) {
case 'admin_get_interaction_view_server': {
const serverId = interaction.customId.split(';')[1];
if (!serverId) return await database.reply(interaction, 'INTERACTION_ADMIN_GET_INTERACTION_VIEW_SERVER_ERROR', {}, false);

const models = (database.connection as Sequelize).models;
const server : any = await models.Server.findOne({ where: { serverId: serverId } });
if (!server) {
await (interaction.client as CustomClient).warn(`[Interaction ${interaction.id}] Server ID ${serverId} not found in database.`);
return await database.reply(interaction, 'INTERACTION_ADMIN_GET_INTERACTION_VIEW_SERVER_ERROR_SERVER_NOT_FOUND', {}, false);
}

await interaction.reply(await adminGetServer.getReply(interaction, server, database) as any);
await database.reply(interaction, 'INTERACTION_ADMIN_GET_INTERACTION_VIEW_SERVER_SUCCESS', {}, false);
break;
}
case 'admin_get_interaction_view_user': {
const userId = interaction.customId.split(';')[1];
if (!userId) return await database.reply(interaction, 'INTERACTION_ADMIN_GET_INTERACTION_VIEW_USER_ERROR', {}, false);

const models = (database.connection as Sequelize).models;
const user : any = await models.User.findOne({ where: { userId: userId } });
if (!user) {
await (interaction.client as CustomClient).warn(`[Interaction ${interaction.id}] User ID ${userId} not found in database.`);
return await database.reply(interaction, 'INTERACTION_ADMIN_GET_INTERACTION_VIEW_USER_ERROR_USER_NOT_FOUND', {}, false);
}

await interaction.reply(await adminGetUser.getReply(interaction, user, database) as any);
await database.reply(interaction, 'INTERACTION_ADMIN_GET_INTERACTION_VIEW_USER_SUCCESS', {}, false);
break;
}
}
},
};

async function getReply(interaction : Interaction, entry: any, database : any) : Promise<{ embeds: [EmbedBuilder], components: [ActionRowBuilder] }> {
const models = (database.connection as Sequelize).models;
const server : any = await models.Server.findOne({ where: { serverId: entry.serverId } });
const user : any = await models.User.findOne({ where: { userId: entry.userId } });
const args = JSON.parse(entry.args) ?? {};

// Manually adding interaction args to the response
args['INTERACTION_ID'] = entry.interactionId;
args['CHANNEL_ID'] = entry.channelId;
args['CHANNEL_NAME'] = entry.channelName ?? 'N/A';
args['USER_ID'] = entry.userId;
args['USER_NAME'] = '@' + user?.userName ?? 'N/A';
args['USER'] = `<@${entry.userId}>`;
args['SHARD_ID'] = server?.shardId ?? 'N/A';
args['GUILD_ID'] = args['SERVER_ID'] = entry.serverId;
args['SERVER_NAME'] = server?.serverName ?? 'N/A';
args['COMMAND_NAME'] = entry.command.split(' ')[0].substring(1);
args['COMMAND_ID'] = 'N/A';

var message : string = await database.getMessage(entry.result, null, args) ?? 'N/A';

const lines = message.split('\n');
message = lines[0].substring(0, 50);
if (lines.length > 1) message += ' ...';
else if (lines[0].length > 50) message += ' ...';

const embed = new EmbedBuilder()
.setColor('#00FFFF')
.setTitle(await database.getMessage('INTERACTION_ADMIN_GET_INTERACTION_EMBED_TITLE', interaction) ?? 'INTERACTION_ADMIN_GET_INTERACTION_EMBED_TITLE')
.setDescription(await database.getMessage('INTERACTION_ADMIN_GET_INTERACTION_EMBED', interaction) ?? 'INTERACTION_ADMIN_GET_INTERACTION_EMBED')
.addFields(
{ name: 'Interaction ID', value: entry.interactionId, inline: true },
{ name: 'Shard ID', value: (server?.shardId as number)?.toString() ?? 'N/A', inline: true },
{ name: 'Server', value: `"${server?.serverName ?? 'N/A'}" (${entry.serverId})`, inline: false },
{ name: 'Channel', value: `#${entry.channelName ?? 'N/A'} (${entry.channelId})`, inline: true },
{ name: 'User', value: `"@${user?.userName ?? 'N/A'}" (<@${entry.userId}>)`, inline: true },
{ name: 'Command', value: entry.command, inline: false },
{ name: 'Result', value: entry.result, inline: false },
{ name: 'Response', value: '\n\n' + (message ?? 'N/A'), inline: false },
);


const viewServerButton = new ButtonBuilder()
.setCustomId(`admin_get_interaction_view_server;${entry.serverId}`)
.setLabel('View Server')
.setStyle(ButtonStyle.Primary);
const viewUserButton = new ButtonBuilder()
.setCustomId(`admin_get_interaction_view_user;${entry.userId}`)
.setLabel('View User')
.setStyle(ButtonStyle.Primary);

const row = new ActionRowBuilder().addComponents(
viewServerButton,
viewUserButton,
await adminGetUser.getBanButton(interaction, entry.userId, database),
);

return { embeds: [embed], components: [row] };
}
Loading

0 comments on commit 656fe2c

Please sign in to comment.