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

refactor: make readonly props readonly #213

Merged
merged 1 commit into from
Nov 15, 2024
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 src/commands/prefix/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class BlacklistPrefixCommand extends BasePrefixCommand {
// Set timeout for 5 minutes
setTimeout(
async () => {
await this.lobbyManager.removeFromWaitingPool(serverId);
await this.lobbyManager.removeChannelFromPool(channelId);
await message.reply('Please try again later. No lobbies were found for this server.');
},
5 * 60 * 1000, // 5 minutes
Expand Down
2 changes: 1 addition & 1 deletion src/commands/prefix/disconnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class BlacklistPrefixCommand extends BasePrefixCommand {
await this.lobbyManager.removeServerFromLobby(alreadyConnected.id, message.guildId);
}
else {
await this.lobbyManager.removeFromWaitingPool(message.guildId);
await this.lobbyManager.removeChannelFromPool(message.channelId);
await message.reply(`${emojis.disconnect} Not connected to any lobby. Removed from waiting pool if exists.`);
return;
}
Expand Down
7 changes: 5 additions & 2 deletions src/managers/LobbyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export class LobbyManager {
return null;
}

async removeFromWaitingPool(serverId: string): Promise<void> {
async removeChannelFromPool(channelId: string): Promise<void> {
const members = await this.redis.zrange('waiting_pool', 0, -1);
for (const member of members) {
const data: QueuedChannel = JSON.parse(member);
if (data.serverId === serverId) {
if (data.channelId === channelId) {
await this.redis.zrem('waiting_pool', member);
break;
}
Expand Down Expand Up @@ -85,6 +85,9 @@ export class LobbyManager {

// Create channel to lobby mapping for each channel
for (const server of servers) {
// remove from pool
await this.removeChannelFromPool(server.channelId);

await this.redis.set(`channel:${server.channelId}:lobby`, lobbyId);
this.notifier.notifyLobbyCreate(server.channelId, lobbyData);
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/BitFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type HubSettingsString = keyof typeof HubSettingsBits;
export type SerializedHubSettings = Record<HubSettingsString, boolean>;

export class HubSettingsBitField extends BitField<HubSettingsString> {
public static Flags = HubSettingsBits;
public static readonly Flags = HubSettingsBits;

/**
* Toggles the specified hub settings.
Expand Down
65 changes: 0 additions & 65 deletions src/modules/LobbyNotifier.ts

This file was deleted.

14 changes: 3 additions & 11 deletions src/scheduled/tasks/pauseIdleConnections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,13 @@ import { InfoEmbed } from '#utils/EmbedUtils.js';
import Logger from '#utils/Logger.js';
import { connectedList } from '@prisma/client';
import { stripIndents } from 'common-tags';
import { ActionRowBuilder, ButtonBuilder, Collection, WebhookClient } from 'discord.js';
import { WebhookClient } from 'discord.js';
import 'dotenv/config';

export default async () => {
const connections = await findInactiveConnections();
if (!connections.length) return;

const reconnectButtonMap = new Collection<string, ActionRowBuilder<ButtonBuilder>>(
connections.map((c) => [
c.channelId,
buildConnectionButtons(false, c.channelId, { customCustomId: 'inactiveConnect' }),
]),
);

// disconnect the channel
await updateConnections(
{ channelId: { in: connections.map((c) => c.channelId) } },
Expand All @@ -35,16 +28,15 @@ export default async () => {

-# Click the **button** below or use **\`/connection unpause\`** to resume chatting.
`,
)
.toJSON();
);

connections.forEach(async (connection) => {
Logger.debug(
`[InterChat]: Paused connection ${connection.channelId}. Last message at: ${connection.lastActive.toLocaleString()}.`,
);

const webhook = new WebhookClient({ url: connection.webhookURL });
const button = reconnectButtonMap.get(connection.channelId);
const button = buildConnectionButtons(false, connection.channelId, { customCustomId: 'inactiveConnect' });
const components = button ? [button] : [];

await webhook.send({ embeds: [embed], components }).catch(() => null);
Expand Down
2 changes: 1 addition & 1 deletion src/services/CooldownService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { RedisKeys } from '#utils/Constants.js';

/** Manage and store individual cooldowns */
export default class CooldownService {
private redisClient = getRedis();
private readonly redisClient = getRedis();
private readonly prefix = RedisKeys.cooldown;

private getKey(id: string) {
Expand Down
1 change: 1 addition & 0 deletions src/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const enum RedisKeys {
ChannelMap = 'channelMap',
ChannelPrefs = 'channelPrefs',
MatchingPool = 'matchingPool',
LobbyMessages = 'lobbyMessages',
}

export const enum ConnectionMode {
Expand Down