Add filter
This commit is contained in:
@@ -170,8 +170,39 @@ class HandleMessage(Command):
|
||||
#recipient_jid = f"{identifier.user.username}@{settings.XMPP_ADDRESS}"
|
||||
user = identifier.user
|
||||
|
||||
log.info(f"Sending {len(xmpp_attachments)} attachments from Signal to XMPP.")
|
||||
await self.ur.xmpp.client.send_from_external(user, identifier, text, is_outgoing_message, attachments=xmpp_attachments)
|
||||
manipulations = Manipulation.objects.filter(
|
||||
group__people=identifier.person,
|
||||
user=identifier.user,
|
||||
#mode="mutate",
|
||||
filter_enabled=True,
|
||||
enabled=True,
|
||||
)
|
||||
# chat_history = await history.get_chat_history(session)
|
||||
# await utils.update_last_interaction(session)
|
||||
if manipulations:
|
||||
manip = manipulations.first()
|
||||
prompt = replies.generate_mutate_reply_prompt(
|
||||
text,
|
||||
None,
|
||||
manip,
|
||||
None,
|
||||
)
|
||||
|
||||
|
||||
log.info("Running Signal context prompt")
|
||||
result = await ai.run_prompt(prompt, manip.ai)
|
||||
log.info(f"RESULT {result}")
|
||||
# await history.store_own_message(
|
||||
# session=session,
|
||||
# text=result,
|
||||
# ts=int(now().timestamp() * 1000),
|
||||
# )
|
||||
log.info(f"Sending {len(xmpp_attachments)} attachments from Signal to XMPP.")
|
||||
await self.ur.xmpp.client.send_from_external(user, identifier, result, is_outgoing_message, attachments=xmpp_attachments)
|
||||
|
||||
if not manipulations.exists():
|
||||
log.info(f"Sending {len(xmpp_attachments)} attachments from Signal to XMPP.")
|
||||
await self.ur.xmpp.client.send_from_external(user, identifier, text, is_outgoing_message, attachments=xmpp_attachments)
|
||||
|
||||
####
|
||||
|
||||
@@ -222,7 +253,7 @@ class HandleMessage(Command):
|
||||
reply_to_others,
|
||||
is_outgoing_message,
|
||||
):
|
||||
if manip.mode != "silent":
|
||||
if manip.mode not in ["silent", "mutate"]:
|
||||
await utils.update_last_interaction(chat_session)
|
||||
prompt = replies.generate_reply_prompt(
|
||||
msg,
|
||||
@@ -240,6 +271,7 @@ class HandleMessage(Command):
|
||||
ts=ts + 1,
|
||||
)
|
||||
# await natural.natural_send_message(c, result)
|
||||
await self.ur.xmpp.client.send_from_external(manip.user, person_identifier, result, is_outgoing_message=True)
|
||||
tss = await natural.natural_send_message(
|
||||
result,
|
||||
c.send,
|
||||
|
||||
@@ -2,7 +2,7 @@ from core.clients import ClientBase
|
||||
from django.conf import settings
|
||||
from slixmpp.componentxmpp import ComponentXMPP
|
||||
from django.conf import settings
|
||||
from core.models import User, Person, PersonIdentifier, ChatSession
|
||||
from core.models import User, Person, PersonIdentifier, ChatSession, Manipulation
|
||||
from asgiref.sync import sync_to_async
|
||||
from django.utils.timezone import now
|
||||
import asyncio
|
||||
@@ -14,6 +14,7 @@ from slixmpp.xmlstream.stanzabase import ET
|
||||
import aiohttp
|
||||
from core.messaging import history
|
||||
from core.util import logs
|
||||
from core.messaging import replies, utils, ai
|
||||
|
||||
|
||||
class XMPPComponent(ComponentXMPP):
|
||||
@@ -503,17 +504,52 @@ class XMPPComponent(ComponentXMPP):
|
||||
session=session,
|
||||
sender="XMPP",
|
||||
text=body,
|
||||
ts=now().timestamp(),
|
||||
ts=int(now().timestamp() * 1000),
|
||||
#outgoing=detail.is_outgoing_message, ????????? TODO:
|
||||
)
|
||||
self.log.info("Stored a message sent from XMPP in the history.")
|
||||
|
||||
manipulations = Manipulation.objects.filter(
|
||||
group__people=identifier.person,
|
||||
user=identifier.user,
|
||||
mode="mutate",
|
||||
enabled=True,
|
||||
)
|
||||
self.log.info(f"MANIP11 {manipulations}")
|
||||
if not manipulations:
|
||||
tss = await signalapi.send_message_raw(
|
||||
identifier.identifier,
|
||||
body,
|
||||
attachments,
|
||||
)
|
||||
self.log.info(f"Message sent unaltered")
|
||||
return
|
||||
|
||||
manip = manipulations.first()
|
||||
chat_history = await history.get_chat_history(session)
|
||||
await utils.update_last_interaction(session)
|
||||
prompt = replies.generate_mutate_reply_prompt(
|
||||
body,
|
||||
identifier.person,
|
||||
manip,
|
||||
chat_history,
|
||||
)
|
||||
self.log.info("Running XMPP context prompt")
|
||||
result = await ai.run_prompt(prompt, manip.ai)
|
||||
self.log.info(f"RESULT {result}")
|
||||
await history.store_own_message(
|
||||
session=session,
|
||||
text=result,
|
||||
ts=int(now().timestamp() * 1000),
|
||||
)
|
||||
tss = await signalapi.send_message_raw(
|
||||
identifier.identifier,
|
||||
body,
|
||||
result,
|
||||
attachments,
|
||||
)
|
||||
self.log.info(f"Message sent")
|
||||
self.log.info(f"Message sent with modifications")
|
||||
|
||||
|
||||
|
||||
async def request_upload_slots(self, recipient_jid, attachments):
|
||||
"""Requests upload slots for multiple attachments concurrently."""
|
||||
@@ -567,30 +603,10 @@ class XMPPComponent(ComponentXMPP):
|
||||
sender_jid = f"{person_identifier.person.name.lower()}|{person_identifier.service}@{settings.XMPP_JID}"
|
||||
recipient_jid = f"{person_identifier.user.username}@{settings.XMPP_ADDRESS}"
|
||||
if is_outgoing_message:
|
||||
self.log.info(f"Forwarding outgoing message as {recipient_jid}")
|
||||
|
||||
# Create the message as if it were sent by the user
|
||||
msg = self.make_message(mto=recipient_jid, mfrom=sender_jid, mtype="chat")
|
||||
msg["body"] = text # Original message content
|
||||
|
||||
# Create the forwarded <message> inside the <forwarded> element
|
||||
forwarded_elem = ET.Element("{urn:xmpp:forward:0}forwarded")
|
||||
|
||||
# Create a <message> element inside the forwarded stanza
|
||||
message_elem = ET.Element("message", attrib={"from": recipient_jid, "to": recipient_jid, "type": "chat"})
|
||||
body_elem = ET.SubElement(message_elem, "body")
|
||||
body_elem.text = text
|
||||
|
||||
# Attach the forwarded message
|
||||
forwarded_elem.append(message_elem)
|
||||
msg.xml.append(forwarded_elem)
|
||||
|
||||
# Send the forwarded message
|
||||
msg.send()
|
||||
|
||||
await self.send_xmpp_message(recipient_jid, sender_jid, f"YOU: {text}")
|
||||
|
||||
# Step 1: Send text message separately
|
||||
if text:
|
||||
elif text:
|
||||
await self.send_xmpp_message(recipient_jid, sender_jid, text)
|
||||
|
||||
if not attachments:
|
||||
|
||||
Reference in New Issue
Block a user