Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit 3169583

Browse files
committed
fix(network): fix connection cache and debug mode
1 parent 977c8db commit 3169583

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

.github/workflows/docker.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ jobs:
6161
docker cp $(docker ps -alq):/src/logs .
6262
cp -r logs/ ~/console-logs/interchat-logs-$(date +"%Y-%m-%d_%H-%M-%S")
6363
- name: Remove old containers and images
64-
run: sudo docker rm $(docker ps -a -q) && sudo docker rmi $(docker images -q)
64+
run: |
65+
docker stop $(docker ps -a -q)
66+
docker rm $(docker ps -a -q)
67+
docker rmi $(docker images -q)
6568
- name: Run latest image
66-
run: sudo docker run -d --env-file ~/important/interchat-env ghcr.io/discord-interchat/interchat
69+
run: docker run -d --env-file ~/important/interchat-env ghcr.io/discord-interchat/interchat

src/managers/NetworkManager.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const MAX_STORE = 3;
4444
export default class NetworkManager {
4545
private readonly scheduler: Scheduler;
4646
private readonly antiSpamMap: Collection<string, AntiSpamUserOpts>;
47-
private _connectionCache: Collection<string, Connection>;
47+
private _connectionCache: Collection<string, connectedList>;
4848
private cachePopulated = false;
4949

5050
constructor() {
@@ -61,10 +61,7 @@ export default class NetworkManager {
6161

6262
protected async populateConnectionCache() {
6363
Logger.debug('[InterChat]: Populating connection cache.');
64-
const connections = await db.connectedList.findMany({
65-
where: { connected: true },
66-
include: { hub: true },
67-
});
64+
const connections = await db.connectedList.findMany({ where: { connected: true } });
6865

6966
// populate all at once without time delay
7067
this._connectionCache = new Collection(connections.map((c) => [c.channelId, c]));
@@ -91,12 +88,15 @@ export default class NetworkManager {
9188
const locale = await message.client.getUserLocale(message.author.id);
9289
message.author.locale = locale;
9390

94-
const connection = this._connectionCache.get(message.channelId);
95-
9691
// check if the message was sent in a network channel
97-
if (!connection?.connected || !connection.hub) return;
92+
const connection = this.connectionCache.get(message.channel.id);
93+
if (!connection?.connected) return;
94+
95+
const hub = await db.hubs.findFirst({ where: { id: connection?.hubId } });
96+
if (!hub) return;
9897

99-
const settings = new HubSettingsBitField(connection.hub.settings);
98+
const settings = new HubSettingsBitField(hub.settings);
99+
const hubConnections = this.connectionCache.filter((con) => con.hubId === connection.hubId);
100100

101101
const attachment = message.attachments.first();
102102
const attachmentURL = attachment
@@ -108,7 +108,6 @@ export default class NetworkManager {
108108
return;
109109
}
110110

111-
const hubConnections = this._connectionCache.filter((con) => con.hubId === connection.hubId);
112111

113112
const censoredContent = censor(message.content);
114113

@@ -189,8 +188,8 @@ export default class NetworkManager {
189188
let messageFormat: WebhookMessageCreateOptions = {
190189
components: jumpButton ? [jumpButton] : undefined,
191190
embeds: [otherConnection.profFilter ? censoredEmbed : embed],
192-
username: `${connection.hub?.name}`,
193-
avatarURL: connection.hub?.iconUrl,
191+
username: `${hub.name}`,
192+
avatarURL: hub.iconUrl,
194193
threadId: otherConnection.parentId ? otherConnection.channelId : undefined,
195194
allowedMentions: { parse: [] },
196195
};
@@ -284,7 +283,7 @@ export default class NetworkManager {
284283
{ phrase: 'network.welcome', locale },
285284
{
286285
user: message.author.toString(),
287-
hub: connection.hub.name,
286+
hub: hub.name,
288287
channel: message.channel.toString(),
289288
totalServers: hubConnections.size.toString(),
290289
emoji: emojis.wave_anim,

src/utils/Logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default createLogger({
2222
transports: [
2323
new transports.Console({
2424
format: format.combine(format.colorize(), custom),
25-
level: isDevBuild ? 'debug' : 'info',
25+
level: isDevBuild || process.env.DEBUG ? 'debug' : 'info',
2626
}),
2727
new transports.File({ filename: 'logs/error.log', level: 'error' }),
2828
new transports.File({

0 commit comments

Comments
 (0)