Compare commits
No commits in common. "9afaaf9a2e7e421a887e8bea8de3610bbdb9e064" and "d9f3e160aae266e4dc6a91cf868a8b32c2a1435a" have entirely different histories.
9afaaf9a2e
...
d9f3e160aa
|
|
@ -148,7 +148,7 @@ export class FishingService {
|
|||
}
|
||||
|
||||
const userKey = this.getUserKey(interaction.guildId, interaction.user.id);
|
||||
const existing = await this.getActiveSession(userKey);
|
||||
const existing = this.sessionsByUser.get(userKey);
|
||||
if (existing) {
|
||||
return { thread: existing.thread, existed: true };
|
||||
}
|
||||
|
|
@ -170,7 +170,7 @@ export class FishingService {
|
|||
return false;
|
||||
}
|
||||
|
||||
const session = await this.getActiveSession(this.getUserKey(interaction.guildId, interaction.user.id));
|
||||
const session = this.sessionsByUser.get(this.getUserKey(interaction.guildId, interaction.user.id));
|
||||
if (!session) {
|
||||
const thread = await this.findOwnedFishingThread(interaction);
|
||||
if (!thread) {
|
||||
|
|
@ -394,39 +394,6 @@ export class FishingService {
|
|||
}
|
||||
}
|
||||
|
||||
private static async getActiveSession(userKey: string) {
|
||||
const session = this.sessionsByUser.get(userKey);
|
||||
if (!session) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (await this.isSessionStale(session)) {
|
||||
this.clearStaleSession(session);
|
||||
return null;
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
private static async isSessionStale(session: FishingSession) {
|
||||
try {
|
||||
await session.thread.fetch();
|
||||
await session.controlMessage.fetch();
|
||||
return false;
|
||||
} catch (error) {
|
||||
logger.info(
|
||||
`[Fishing] Clearing stale session for ${session.userId} in thread ${session.threadId}: ${error instanceof Error ? error.message : String(error)}`,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static clearStaleSession(session: FishingSession) {
|
||||
this.clearTick(session);
|
||||
this.sessionsByUser.delete(this.getUserKey(session.guildId, session.userId));
|
||||
this.sessionsByThread.delete(session.threadId);
|
||||
}
|
||||
|
||||
private static async deleteThread(thread: ThreadChannel) {
|
||||
try {
|
||||
await thread.delete();
|
||||
|
|
|
|||
Loading…
Reference in New Issue