mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-26 23:49:33 +01:00
fix(discord): claim refused replies before rate limiting (#218)
This commit is contained in:
1 parent
7343274d5f
commit
44459a12dd
6 files changed
+54
-23
No files matched your search
@@ -1307,6 +1307,7 @@ export class DiscordBridge {
|
||||
if (!this.cfg.allowedUserIds.includes(m.author?.id)) return;
|
||||
const sessionId = Object.keys(this.threads).find((k) => this.threads[k] === m.channel_id);
|
||||
if (!sessionId) return;
|
||||
if (!(await this.replies.claim(m.guild_id, m.channel_id, m.id))) return;
|
||||
const t = this.now();
|
||||
const prev = this.lastReply.get(sessionId);
|
||||
if (prev !== undefined && t - prev < REPLY_MIN_INTERVAL_MS) {
|
||||
@@ -1318,7 +1319,6 @@ export class DiscordBridge {
|
||||
await this.say(m.channel_id, 'The agent in that tab has exited, so nothing was typed.');
|
||||
return;
|
||||
}
|
||||
if (!(await this.replies.claim(m.guild_id, m.channel_id, m.id))) return;
|
||||
this.lastReply.set(sessionId, t);
|
||||
const saved = await this.saveAttachments(sessionId, m);
|
||||
const text = sanitiseReply(m.content ?? '', saved.paths);
|
||||
|
||||
@@ -31,8 +31,11 @@ export class DiscordReplyDedupe {
|
||||
let contentRead = false;
|
||||
try {
|
||||
const st = await fs.lstat(path);
|
||||
if (!st.isFile() || st.isSymbolicLink() || st.size > 512 * 1024)
|
||||
throw Object.assign(new Error('Unsafe metadata'), { code: 'EINVAL' });
|
||||
if (!st.isFile() || st.isSymbolicLink()) throw Object.assign(new Error('Unsafe metadata'), { code: 'EINVAL' });
|
||||
if (st.size > 512 * 1024) {
|
||||
contentRead = true; // A known oversized regular file is invalid metadata, not an IO failure.
|
||||
throw new Error('Oversized metadata');
|
||||
}
|
||||
const text = await fs.readFile(path, 'utf8');
|
||||
contentRead = true;
|
||||
const rows: unknown = JSON.parse(text);
|
||||
|
||||
Reference in new issue
Block a user