Compare commits
2 Commits
d9f3e160aa
...
9afaaf9a2e
| Author | SHA1 | Date |
|---|---|---|
|
|
9afaaf9a2e | |
|
|
b9d509a9e8 |
|
|
@ -148,7 +148,7 @@ export class FishingService {
|
||||||
}
|
}
|
||||||
|
|
||||||
const userKey = this.getUserKey(interaction.guildId, interaction.user.id);
|
const userKey = this.getUserKey(interaction.guildId, interaction.user.id);
|
||||||
const existing = this.sessionsByUser.get(userKey);
|
const existing = await this.getActiveSession(userKey);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
return { thread: existing.thread, existed: true };
|
return { thread: existing.thread, existed: true };
|
||||||
}
|
}
|
||||||
|
|
@ -170,7 +170,7 @@ export class FishingService {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const session = this.sessionsByUser.get(this.getUserKey(interaction.guildId, interaction.user.id));
|
const session = await this.getActiveSession(this.getUserKey(interaction.guildId, interaction.user.id));
|
||||||
if (!session) {
|
if (!session) {
|
||||||
const thread = await this.findOwnedFishingThread(interaction);
|
const thread = await this.findOwnedFishingThread(interaction);
|
||||||
if (!thread) {
|
if (!thread) {
|
||||||
|
|
@ -394,6 +394,39 @@ 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) {
|
private static async deleteThread(thread: ThreadChannel) {
|
||||||
try {
|
try {
|
||||||
await thread.delete();
|
await thread.delete();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue