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
1 change: 1 addition & 0 deletions scripts/deploy-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ if (process.argv) {

if (slicedArgs.length === 0) logHelp();
else await parseAndRun(allArgs);
process.exit(0);
}
36 changes: 22 additions & 14 deletions src/commands/prefix/connect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BasePrefixCommand, { CommandData } from '#main/core/BasePrefixCommand.js';
import { LobbyManager } from '#main/managers/LobbyManager.js';
import { MatchingService } from '#main/services/LobbyMatchingService.js';
import { emojis } from '#main/utils/Constants.js';
import Constants, { emojis } from '#main/utils/Constants.js';
import db from '#main/utils/Db.js';
import { t } from '#main/utils/Locale.js';
import { getOrCreateWebhook } from '#main/utils/Utils.js';
Expand All @@ -27,6 +27,10 @@ export default class BlacklistPrefixCommand extends BasePrefixCommand {

private readonly lobbyManager = new LobbyManager();
private readonly matching = new MatchingService();
private readonly tips = [
'You can change the minimum number of servers required to find a match: `c!call 2`. It can be faster sometimes!',
'Can\'t find a lobby? Try `/setup interchat` instead!',
];

protected async run(message: Message<true>, args: string[]) {
const minServers = parseInt(args[0], 10) || 2;
Expand All @@ -41,8 +45,7 @@ export default class BlacklistPrefixCommand extends BasePrefixCommand {
if (inWaitingPool) {
await message.reply(
stripIndents`
-# **💡 Did you know?** You can change the minimum number of servers required to find a match: \`c!call 2\`. It can be faster sometimes!
You are already in the waiting pool for a lobby.
${emojis.slash} You are already in the waiting pool for a lobby.
-# You will be notified once a lobby is found.
`,
);
Expand All @@ -51,7 +54,7 @@ export default class BlacklistPrefixCommand extends BasePrefixCommand {

const webhook = await getOrCreateWebhook(
message.channel,
'https://i.imgur.com/80nqtSg.png',
Constants.Links.EasterAvatar,
'InterChat Lobby',
);
if (!webhook) {
Expand Down Expand Up @@ -80,15 +83,6 @@ export default class BlacklistPrefixCommand extends BasePrefixCommand {
preferences,
);

// Set timeout for 5 minutes
setTimeout(
async () => {
await this.lobbyManager.removeChannelFromPool(channelId);
await message.reply('Please try again later. No lobbies were found for this server.');
},
5 * 60 * 1000, // 5 minutes
);

const match = await this.matching.findMatch(serverId, preferences);
if (match) {
const lobbyId = await this.lobbyManager.createLobby([
Expand All @@ -99,15 +93,29 @@ export default class BlacklistPrefixCommand extends BasePrefixCommand {
// Update server histories
await this.updateServerHistory(serverId, lobbyId);
await this.updateServerHistory(match.serverId, lobbyId);
await this.lobbyManager.removeChannelFromPool(channelId);
}
else {
await message.reply(
stripIndents`
-# **💡 Did you know?** You can change the minimum number of servers required to find a match: \`c!call 2\`. It can be faster sometimes!
Finding a lobby for this server... Hang tight!
-# You will be notified once a lobby is found.
`,
);

// Set timeout for 5 minutes
setTimeout(
async () => {
const stillInWaitingPool = await this.lobbyManager.getChannelFromWaitingPool(
message.guildId,
);
if (stillInWaitingPool && stillInWaitingPool?.timestamp < Date.now() - 5 * 60 * 1000) {
await this.lobbyManager.removeChannelFromPool(channelId);
await message.reply('No lobbies were found for this server. Please try again.');
}
},
5 * 60 * 1000, // 5 minutes
);
}
}
private async updateServerHistory(serverId: string, lobbyId: string): Promise<void> {
Expand Down
4 changes: 3 additions & 1 deletion src/commands/prefix/modpanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export default class BlacklistPrefixCommand extends BasePrefixCommand {

protected async run(message: Message<true>, args: string[]) {
const msgId = message.reference?.messageId ?? getMessageIdFromStr(args[0]);
const originalMessage = msgId ? await this.getOriginalMessage(msgId) : null;
const originalMessage = msgId
? ((await this.getOriginalMessage(msgId)) ?? (await findOriginalMessage(msgId)))
: null;

if (!originalMessage) {
await message.channel.send('Please provide a valid message ID or link.');
Expand Down
10 changes: 5 additions & 5 deletions src/managers/LobbyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ export class LobbyManager {
// Update the lobby with remaining servers
lobby.servers = remainingServers;
await this.redis.set(`lobby:${lobbyId}`, JSON.stringify(lobby));

// Notify other servers in the lobby
remainingServers.forEach((server) => {
this.notifier.notifyChannelDisconnect(lobby, server.channelId);
});
}

// Notify other servers in the lobby
remainingServers.forEach((server) => {
this.notifier.notifyChannelDisconnect(lobby, server.channelId);
});
}
}
6 changes: 0 additions & 6 deletions src/services/LobbyMatchingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ export class MatchingService {
);

if (!hasRecentInteraction) {
// Check premium status and preferences
if (preferences.premiumStatus || data.preferences.premium) {
// Premium users get priority matching
return data;
}

// Regular matching
if (preferences.maxServersInLobby === data.preferences.maxServersInLobby) {
// TODO: make it possible for servers to join already created lobbies later if they don't match immediately
Expand Down
11 changes: 8 additions & 3 deletions src/utils/hub/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Constants from '#main/utils/Constants.js';
import {
deleteConnection,
deleteConnections,
Expand All @@ -15,7 +16,11 @@ import { type WebhookMessageCreateOptions, WebhookClient } from 'discord.js';
* @param message The message to send. Can be a string or a MessageCreateOptions object.
* @returns A array of the responses from each connection's webhook.
*/
export const sendToHub = async (hubId: string, message: string | WebhookMessageCreateOptions) => {
export const sendToHub = async (
hubId: string,
message: string | WebhookMessageCreateOptions,
avatarURL = Constants.Links.EasterAvatar,
) => {
const connections = await getHubConnections(hubId);
if (!connections?.length) return;

Expand All @@ -28,7 +33,7 @@ export const sendToHub = async (hubId: string, message: string | WebhookMessageC

try {
const webhook = new WebhookClient({ url: webhookURL });
await webhook.send({ ...payload, allowedMentions: { parse: [] } });
await webhook.send({ ...payload, avatarURL, allowedMentions: { parse: [] } });
}
catch (e) {
const validErrors = [
Expand All @@ -42,7 +47,7 @@ export const sendToHub = async (hubId: string, message: string | WebhookMessageC
e.message = `For Connection: ${channelId} ${e.message}`;
Logger.error(e);
}
};
}
};

export const deleteHubs = async (ids: string[]) => {
Expand Down