mirror of
https://github.com/sune-org/chatroom.git
synced 2026-01-13 16:17:59 +00:00
Refactor: Remove AI moderation logic
This commit is contained in:
4
index.js
4
index.js
@@ -59,10 +59,6 @@ export class ChatsuneDurableObject {
|
|||||||
if (timestamps.length >= 3) return server.send(JSON.stringify({ type: 'ERROR', payload: 'Rate limit exceeded.' }));
|
if (timestamps.length >= 3) return server.send(JSON.stringify({ type: 'ERROR', payload: 'Rate limit exceeded.' }));
|
||||||
this.rateLimiter.set(server.ip, [...timestamps, now]);
|
this.rateLimiter.set(server.ip, [...timestamps, now]);
|
||||||
|
|
||||||
const modRes = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:generateContent?key=${this.env.GOOGLE_KEY}`, { method: 'POST', body: JSON.stringify({ contents: [{ parts: [{ text: `if this message is appropiate respond only with yes, if its not respond with anything but yes. message: ${data.payload.text}` }] }] }) });
|
|
||||||
const modData = await modRes.json();
|
|
||||||
if (modData.candidates?.[0]?.content?.parts?.[0]?.text.trim().toLowerCase() !== 'yes') return server.send(JSON.stringify({ type: 'ERROR', payload: 'Message rejected by moderator.' }));
|
|
||||||
|
|
||||||
const messagePayload = { author: { name: server.username }, text: data.payload.text, timestamp: new Date().toISOString() };
|
const messagePayload = { author: { name: server.username }, text: data.payload.text, timestamp: new Date().toISOString() };
|
||||||
this.messages.push(messagePayload);
|
this.messages.push(messagePayload);
|
||||||
this.messages = this.messages.slice(-4);
|
this.messages = this.messages.slice(-4);
|
||||||
|
|||||||
Reference in New Issue
Block a user