Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 locales
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"type": "module",
"dependencies": {
"@prisma/client": "^5.14.0",
"@sentry/node": "^8.4.0",
"@sentry/node": "^8.7.0",
"@tensorflow/tfjs-node": "^4.19.0",
"@top-gg/sdk": "^3.1.6",
"common-tags": "^1.8.2",
Expand All @@ -45,7 +45,7 @@
"@types/express": "^4.17.21",
"@types/js-yaml": "^4.0.9",
"@types/lodash": "^4.17.4",
"@types/node": "^20.12.12",
"@types/node": "^20.12.13",
"@types/source-map-support": "^0.5.10",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^9.3.0",
Expand All @@ -55,7 +55,7 @@
"standard-version": "^9.5.0",
"tsc-watch": "^6.2.0",
"typescript": "^5.4.5",
"typescript-eslint": "^7.10.0"
"typescript-eslint": "^7.11.0"
},
"config": {
"commitizen": {
Expand Down
12 changes: 5 additions & 7 deletions src/commands/context-menu/blacklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,14 @@ export default class Blacklist extends BaseCommand {
async handleModals(interaction: ModalSubmitInteraction): Promise<void> {
await interaction.deferUpdate();

const { locale } = interaction.user;
const customId = CustomID.parseCustomId(interaction.customId);
const messageId = customId.args[0];
const originalMsg = await db.originalMessages.findFirst({ where: { messageId } });

if (!originalMsg?.hubId) {
await interaction.editReply(
t(
{ phrase: 'errors.networkMessageExpired', locale: interaction.user.locale },
{ emoji: emojis.no },
),
t({ phrase: 'errors.networkMessageExpired', locale }, { emoji: emojis.no }),
);
return;
}
Expand All @@ -181,7 +179,7 @@ export default class Blacklist extends BaseCommand {
const successEmbed = new EmbedBuilder().setColor('Green').addFields(
{
name: 'Reason',
value: reason ? reason : t({ phrase: 'misc.noReason', locale: interaction.user.locale }),
value: reason ? reason : t({ phrase: 'misc.noReason', locale }),
inline: true,
},
{
Expand All @@ -198,7 +196,7 @@ export default class Blacklist extends BaseCommand {
const user = await interaction.client.users.fetch(originalMsg.authorId).catch(() => null);
successEmbed.setDescription(
t(
{ phrase: 'blacklist.user.success', locale: interaction.user.locale },
{ phrase: 'blacklist.user.success', locale },
{ username: user?.username ?? 'Unknown User', emoji: emojis.tick },
),
);
Expand Down Expand Up @@ -240,7 +238,7 @@ export default class Blacklist extends BaseCommand {

successEmbed.setDescription(
t(
{ phrase: 'blacklist.server.success', locale: interaction.user.locale },
{ phrase: 'blacklist.server.success', locale },
{ server: server?.name ?? 'Unknown Server', emoji: emojis.tick },
),
);
Expand Down
24 changes: 21 additions & 3 deletions src/commands/slash/Main/connection/pause.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { ChatInputCommandInteraction, channelMention } from 'discord.js';
import {
ChatInputCommandInteraction,
channelMention,
chatInputApplicationCommandMention as slashCmdMention,
} from 'discord.js';
import Connection from './index.js';
import { simpleEmbed } from '../../../../utils/Utils.js';
import { fetchCommands, findCommand, simpleEmbed } from '../../../../utils/Utils.js';
import { emojis } from '../../../../utils/Constants.js';
import { t } from '../../../../utils/Locale.js';
import { modifyConnection } from '../../../../utils/ConnectedList.js';
Expand All @@ -10,6 +14,7 @@ export default class Pause extends Connection {
override async execute(interaction: ChatInputCommandInteraction): Promise<void> {
const channelId = interaction.options.getString('channel', true);
const connected = await db.connectedList.findFirst({ where: { channelId } });
const { locale } = interaction.user;

if (!connected) {
await interaction.reply({
Expand All @@ -34,11 +39,24 @@ export default class Pause extends Connection {
// disconnect the channel
await modifyConnection({ channelId }, { connected: false });

const commands = await fetchCommands(interaction.client);
const connectionCmd = findCommand('connection', commands);
const hubCmd = findCommand('hub', commands);

const unpause_cmd = connectionCmd
? slashCmdMention('connection', 'unpause', connectionCmd.id)
: '`/connection pause`';
const leave_cmd = hubCmd ? slashCmdMention('hub', 'leave', hubCmd.id) : '`/hub leave`';

await interaction.reply({
content: t(
{ phrase: 'connection.paused.tips', locale },
{ emoji: emojis.dotBlue, unpause_cmd, leave_cmd },
),
embeds: [
simpleEmbed(
t(
{ phrase: 'connection.paused', locale: interaction.user.locale },
{ phrase: 'connection.paused.desc', locale },
{
clock_emoji: emojis.timeout,
channel: channelMention(channelId),
Expand Down
67 changes: 60 additions & 7 deletions src/commands/slash/Main/connection/unpause.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { ChatInputCommandInteraction, channelMention } from 'discord.js';
import {
ChannelType,
ChatInputCommandInteraction,
channelMention,
chatInputApplicationCommandMention as slashCmdMention,
} from 'discord.js';
import Connection from './index.js';
import { simpleEmbed } from '../../../../utils/Utils.js';
import {
fetchCommands,
findCommand,
getOrCreateWebhook,
simpleEmbed,
} from '../../../../utils/Utils.js';
import { emojis } from '../../../../utils/Constants.js';
import { t } from '../../../../utils/Locale.js';
import { modifyConnection } from '../../../../utils/ConnectedList.js';
Expand All @@ -10,6 +20,7 @@ export default class Unpause extends Connection {
override async execute(interaction: ChatInputCommandInteraction): Promise<void> {
const channelId = interaction.options.getString('channel', true);
const connected = await db.connectedList.findFirst({ where: { channelId } });
const { locale } = interaction.user;

if (!connected) {
await interaction.reply({
Expand All @@ -19,27 +30,69 @@ export default class Unpause extends Connection {
return;
}


if (connected.connected) {
await interaction.reply({
embeds: [
simpleEmbed(
`${emojis.no} You are already connected to this hub. Use \`/connection pause\` to pause your connection.`,
`${emojis.no} This connection is not paused! Use \`/connection pause\` to pause your connection.`,
),
],
ephemeral: true,
});
return;
}

// reconnect the channel
await modifyConnection({ channelId }, { connected: true });
const channel = await interaction.guild?.channels.fetch(channelId).catch(() => null);

if (!channel?.isThread() && channel?.type !== ChannelType.GuildText) {
await interaction.reply({
embeds: [
simpleEmbed(t({ phrase: 'connection.channelNotFound', locale }, { emoji: emojis.no })),
],
});
return;
}

await interaction.reply({
content: `${emojis.loading} Checking webhook status... May take a few seconds if it needs to be re-created.`,
});

const webhook = await getOrCreateWebhook(channel).catch(() => null);
if (!webhook) {
await interaction.editReply({
embeds: [
simpleEmbed(
t(
{ phrase: 'errors.botMissingPermissions', locale },
{ emoji: emojis.no, permissions: 'Manage Webhooks' },
),
),
],
});
return;
}

// reconnect the channel
await modifyConnection({ channelId }, { connected: true, webhookURL: webhook.url });

let pause_cmd = '`/connection pause`';
let customize_cmd = '`/connection customize`';

const command = findCommand('connection', await fetchCommands(interaction.client));
if (command) {
pause_cmd = slashCmdMention('connection', 'pause', command.id);
customize_cmd = slashCmdMention('connection', 'customize', command.id);
}

await interaction.editReply({
content: t(
{ phrase: 'connection.unpaused.tips', locale },
{ emoji: emojis.dotBlue, pause_cmd, customize_cmd },
),
embeds: [
simpleEmbed(
t(
{ phrase: 'connection.unpaused', locale: interaction.user.locale },
{ phrase: 'connection.unpaused.desc', locale },
{
tick_emoji: emojis.tick,
channel: channelMention(channelId),
Expand Down
4 changes: 3 additions & 1 deletion src/core/BaseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export const commandsMap = new Collection<string, BaseCommand>();
export const interactionsMap = new Collection<string, InteractionFunction | undefined>();

export default abstract class BaseCommand {
readonly abstract data: RESTPostAPIChatInputApplicationCommandsJSONBody | RESTPostAPIContextMenuApplicationCommandsJSONBody;
abstract readonly data:
| RESTPostAPIChatInputApplicationCommandsJSONBody
| RESTPostAPIContextMenuApplicationCommandsJSONBody;
readonly staffOnly?: boolean;
readonly cooldown?: number;
readonly description?: string;
Expand Down
4 changes: 2 additions & 2 deletions src/managers/EventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,6 @@ export default abstract class EventManager {
const hub = await db.hubs.findFirst({ where: { id: connection?.hubId } });
if (!hub) return;

message.channel.sendTyping().catch(() => null);

const settings = new HubSettingsBitField(hub.settings);
const hubConnections = connectionCache.filter(
(con) =>
Expand All @@ -267,6 +265,8 @@ export default abstract class EventManager {
// run checks on the message to determine if it can be sent in the network
if (!(await runChecks(message, settings, connection.hubId, { attachmentURL }))) return;

message.channel.sendTyping().catch(() => null);

// fetch the referred message (message being replied to) from discord
const referredMessage = message.reference
? await message.fetchReference().catch(() => null)
Expand Down
34 changes: 34 additions & 0 deletions src/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import startCase from 'lodash/startCase.js';
import SuperClient from '../core/Client.js';
import {
ActionRow,
ApplicationCommand,
ApplicationCommandOptionType,
ButtonStyle,
ChannelType,
Client,
Collection,
ColorResolvable,
ComponentType,
EmbedBuilder,
ForumChannel,
GuildResolvable,
Interaction,
MediaChannel,
Message,
Expand Down Expand Up @@ -500,3 +505,32 @@ export const containsInviteLinks = (str: string) => {
const inviteLinks = ['discord.gg', 'discord.com/invite', 'dsc.gg'];
return inviteLinks.some((link) => str.includes(link));
};

export const fetchCommands = async (client: Client) => {
return await client.application?.commands.fetch();
};

export const findCommand = (name: string, commands: Collection<
string,
ApplicationCommand<{
guild: GuildResolvable;
}>
> | undefined) => {
return commands?.find(command => command.name === name);
};

export const findSubcommand = (
cmdName: string,
subName: string,
commands: Collection<
string,
ApplicationCommand<{
guild: GuildResolvable;
}>
>,
) => {
const command = commands.find(({ name }) => name === cmdName);
return command?.options.find(
({ type, name }) => type === ApplicationCommandOptionType.Subcommand && name === subName,
);
};
Loading