Reformat and remove stale debugging
This commit is contained in:
@@ -155,15 +155,15 @@ class XMPPComponent(ComponentXMPP):
|
||||
|
||||
try:
|
||||
# Lookup user in Django
|
||||
self.log.info(f"User {sender_username}")
|
||||
self.log.debug("Resolving XMPP sender user=%s", sender_username)
|
||||
user = User.objects.get(username=sender_username)
|
||||
|
||||
# Find Person object with name=person_name.lower()
|
||||
self.log.info(f"Name {person_name.title()}")
|
||||
self.log.debug("Resolving XMPP recipient person=%s", person_name.title())
|
||||
person = Person.objects.get(user=user, name=person_name.title())
|
||||
|
||||
# Ensure a PersonIdentifier exists for this user, person, and service
|
||||
self.log.info(f"Identifier {service}")
|
||||
self.log.debug("Resolving XMPP identifier service=%s", service)
|
||||
identifier = PersonIdentifier.objects.get(
|
||||
user=user, person=person, service=service
|
||||
)
|
||||
@@ -580,13 +580,13 @@ class XMPPComponent(ComponentXMPP):
|
||||
iq["roster"]["items"] = {jid: {"name": name or jid}}
|
||||
|
||||
iq.send()
|
||||
self.log.info(f"Updated roster: Added {jid} ({name})")
|
||||
self.log.debug("Updated roster: added %s (%s)", jid, name)
|
||||
|
||||
def on_chatstate_active(self, msg):
|
||||
"""
|
||||
Handle when a user is actively engaged in the chat.
|
||||
"""
|
||||
self.log.info(f"Chat state: Active from {msg['from']}.")
|
||||
self.log.debug("Chat state active from %s", msg["from"])
|
||||
|
||||
self.get_identifier(msg)
|
||||
|
||||
@@ -594,7 +594,7 @@ class XMPPComponent(ComponentXMPP):
|
||||
"""
|
||||
Handle when a user is typing a message.
|
||||
"""
|
||||
self.log.info(f"Chat state: Composing from {msg['from']}.")
|
||||
self.log.debug("Chat state composing from %s", msg["from"])
|
||||
|
||||
identifier = self.get_identifier(msg)
|
||||
if identifier:
|
||||
@@ -609,7 +609,7 @@ class XMPPComponent(ComponentXMPP):
|
||||
"""
|
||||
Handle when a user has paused typing.
|
||||
"""
|
||||
self.log.info(f"Chat state: Paused from {msg['from']}.")
|
||||
self.log.debug("Chat state paused from %s", msg["from"])
|
||||
|
||||
identifier = self.get_identifier(msg)
|
||||
if identifier:
|
||||
@@ -624,7 +624,7 @@ class XMPPComponent(ComponentXMPP):
|
||||
"""
|
||||
Handle when a user is inactive in the chat.
|
||||
"""
|
||||
self.log.info(f"Chat state: Inactive from {msg['from']}.")
|
||||
self.log.debug("Chat state inactive from %s", msg["from"])
|
||||
|
||||
self.get_identifier(msg)
|
||||
|
||||
@@ -632,7 +632,7 @@ class XMPPComponent(ComponentXMPP):
|
||||
"""
|
||||
Handle when a user has left the chat.
|
||||
"""
|
||||
self.log.info(f"Chat state: Gone from {msg['from']}.")
|
||||
self.log.debug("Chat state gone from %s", msg["from"])
|
||||
|
||||
self.get_identifier(msg)
|
||||
|
||||
@@ -640,37 +640,37 @@ class XMPPComponent(ComponentXMPP):
|
||||
"""
|
||||
Handle when a user becomes available.
|
||||
"""
|
||||
self.log.info(f"Presence available from {pres['from']}")
|
||||
self.log.debug("Presence available from %s", pres["from"])
|
||||
|
||||
def on_presence_dnd(self, pres):
|
||||
"""
|
||||
Handle when a user sets 'Do Not Disturb' status.
|
||||
"""
|
||||
self.log.info(f"User {pres['from']} is now in 'Do Not Disturb' mode.")
|
||||
self.log.debug("Presence dnd from %s", pres["from"])
|
||||
|
||||
def on_presence_xa(self, pres):
|
||||
"""
|
||||
Handle when a user sets 'Extended Away' status.
|
||||
"""
|
||||
self.log.info(f"User {pres['from']} is now 'Extended Away'.")
|
||||
self.log.debug("Presence extended-away from %s", pres["from"])
|
||||
|
||||
def on_presence_chat(self, pres):
|
||||
"""
|
||||
Handle when a user is actively available for chat.
|
||||
"""
|
||||
self.log.info(f"User {pres['from']} is now available for chat.")
|
||||
self.log.debug("Presence chat-available from %s", pres["from"])
|
||||
|
||||
def on_presence_away(self, pres):
|
||||
"""
|
||||
Handle when a user sets 'Away' status.
|
||||
"""
|
||||
self.log.info(f"User {pres['from']} is now 'Away'.")
|
||||
self.log.debug("Presence away from %s", pres["from"])
|
||||
|
||||
def on_presence_unavailable(self, pres):
|
||||
"""
|
||||
Handle when a user goes offline or unavailable.
|
||||
"""
|
||||
self.log.info(f"User {pres['from']} is now unavailable.")
|
||||
self.log.debug("Presence unavailable from %s", pres["from"])
|
||||
|
||||
def on_presence_subscribe(self, pres):
|
||||
"""
|
||||
@@ -681,7 +681,7 @@ class XMPPComponent(ComponentXMPP):
|
||||
sender_jid = str(pres["from"]).split("/")[0] # Bare JID (user@domain)
|
||||
recipient_jid = str(pres["to"]).split("/")[0]
|
||||
|
||||
self.log.info(
|
||||
self.log.debug(
|
||||
f"Received subscription request from {sender_jid} to {recipient_jid}"
|
||||
)
|
||||
|
||||
@@ -699,36 +699,36 @@ class XMPPComponent(ComponentXMPP):
|
||||
service = None
|
||||
|
||||
# Lookup user in Django
|
||||
self.log.info(f"User {user_username}")
|
||||
self.log.debug("Resolving subscription user=%s", user_username)
|
||||
user = User.objects.get(username=user_username)
|
||||
|
||||
# Find Person object with name=person_name.lower()
|
||||
self.log.info(f"Name {person_name.title()}")
|
||||
self.log.debug("Resolving subscription person=%s", person_name.title())
|
||||
person = Person.objects.get(user=user, name=person_name.title())
|
||||
|
||||
# Ensure a PersonIdentifier exists for this user, person, and service
|
||||
self.log.info(f"Identifier {service}")
|
||||
self.log.debug("Resolving subscription identifier service=%s", service)
|
||||
PersonIdentifier.objects.get(user=user, person=person, service=service)
|
||||
|
||||
component_jid = f"{person_name.lower()}|{service}@{self.boundjid.bare}"
|
||||
|
||||
# Accept the subscription
|
||||
self.send_presence(ptype="subscribed", pto=sender_jid, pfrom=component_jid)
|
||||
self.log.info(
|
||||
self.log.debug(
|
||||
f"Accepted subscription from {sender_jid}, sent from {component_jid}"
|
||||
)
|
||||
|
||||
# Send a presence request **from the recipient to the sender** (ASKS THEM TO ACCEPT BACK)
|
||||
# self.send_presence(ptype="subscribe", pto=sender_jid, pfrom=component_jid)
|
||||
# self.log.info(f"Sent presence subscription request from {component_jid} to {sender_jid}")
|
||||
|
||||
# Add sender to roster
|
||||
# self.update_roster(sender_jid, name=sender_jid.split("@")[0])
|
||||
# self.log.info(f"Added {sender_jid} to roster.")
|
||||
|
||||
# Send presence update to sender **from the correct JID**
|
||||
self.send_presence(ptype="available", pto=sender_jid, pfrom=component_jid)
|
||||
self.log.info(f"Sent presence update from {component_jid} to {sender_jid}")
|
||||
self.log.debug(
|
||||
"Sent presence update from %s to %s", component_jid, sender_jid
|
||||
)
|
||||
|
||||
except (User.DoesNotExist, Person.DoesNotExist, PersonIdentifier.DoesNotExist):
|
||||
# If any lookup fails, reject the subscription
|
||||
@@ -744,25 +744,25 @@ class XMPPComponent(ComponentXMPP):
|
||||
"""
|
||||
Handle successful subscription confirmations.
|
||||
"""
|
||||
self.log.info(f"Subscription to {pres['from']} was accepted.")
|
||||
self.log.debug("Subscription to %s accepted", pres["from"])
|
||||
|
||||
def on_presence_unsubscribe(self, pres):
|
||||
"""
|
||||
Handle when a user unsubscribes from presence updates.
|
||||
"""
|
||||
self.log.info(f"User {pres['from']} has unsubscribed from presence updates.")
|
||||
self.log.debug("Presence unsubscribe from %s", pres["from"])
|
||||
|
||||
def on_presence_unsubscribed(self, pres):
|
||||
"""
|
||||
Handle when a user's unsubscription request is confirmed.
|
||||
"""
|
||||
self.log.info(f"Unsubscription from {pres['from']} confirmed.")
|
||||
self.log.debug("Presence unsubscribed confirmation from %s", pres["from"])
|
||||
|
||||
def on_roster_subscription_request(self, pres):
|
||||
"""
|
||||
Handle roster subscription requests.
|
||||
"""
|
||||
self.log.info(f"New roster subscription request from {pres['from']}.")
|
||||
self.log.debug("Roster subscription request from %s", pres["from"])
|
||||
|
||||
async def session_start(self, *args):
|
||||
self.log.info("XMPP session started")
|
||||
@@ -793,8 +793,6 @@ class XMPPComponent(ComponentXMPP):
|
||||
# self.log.error("No XEP-0363 upload service found.")
|
||||
# return None
|
||||
|
||||
# self.log.info(f"Upload service: {upload_service}")
|
||||
|
||||
upload_service_jid = str(
|
||||
getattr(settings, "XMPP_UPLOAD_SERVICE", "")
|
||||
or getattr(settings, "XMPP_UPLOAD_JID", "")
|
||||
@@ -851,8 +849,6 @@ class XMPPComponent(ComponentXMPP):
|
||||
def sym(value):
|
||||
msg.reply(f"[>] {value}").send()
|
||||
|
||||
# self.log.info(f"Received message: {msg}")
|
||||
|
||||
# Extract sender JID (full format: user@domain/resource)
|
||||
sender_jid = str(msg["from"])
|
||||
|
||||
@@ -878,7 +874,9 @@ class XMPPComponent(ComponentXMPP):
|
||||
body = msg["body"] if msg["body"] else ""
|
||||
|
||||
attachments = []
|
||||
self.log.info(f"Full XMPP Message: {ET.tostring(msg.xml, encoding='unicode')}")
|
||||
self.log.debug(
|
||||
"Received XMPP stanza: %s", ET.tostring(msg.xml, encoding="unicode")
|
||||
)
|
||||
|
||||
# Extract attachments from standard XMPP payloads.
|
||||
for att in msg.xml.findall(".//{urn:xmpp:attachments}attachment"):
|
||||
@@ -933,7 +931,7 @@ class XMPPComponent(ComponentXMPP):
|
||||
if attachment_urls:
|
||||
body = "\n".join(attachment_urls)
|
||||
|
||||
self.log.info(f"Extracted {len(attachments)} attachments from XMPP message.")
|
||||
self.log.debug("Extracted %s attachments from XMPP message", len(attachments))
|
||||
# Log extracted information with variable name annotations
|
||||
log_message = (
|
||||
f"Sender JID: {sender_jid}, Sender Username: {sender_username}, Sender Domain: {sender_domain}, "
|
||||
@@ -941,7 +939,7 @@ class XMPPComponent(ComponentXMPP):
|
||||
f"Recipient JID: {recipient_jid}, Recipient Username: {recipient_username}, Recipient Domain: {recipient_domain}, "
|
||||
f"Body: {body or '[No Body]'}"
|
||||
)
|
||||
self.log.info(log_message)
|
||||
self.log.debug(log_message)
|
||||
|
||||
# Ensure recipient domain matches our configured component
|
||||
expected_domain = settings.XMPP_JID # 'jews.zm.is' in your config
|
||||
@@ -959,14 +957,14 @@ class XMPPComponent(ComponentXMPP):
|
||||
return
|
||||
|
||||
if recipient_jid == settings.XMPP_JID:
|
||||
self.log.info("Message to JID")
|
||||
self.log.debug("Handling command message sent to gateway JID")
|
||||
if body.startswith("."):
|
||||
# Messaging the gateway directly
|
||||
if body == ".contacts":
|
||||
# Lookup Person objects linked to sender
|
||||
persons = Person.objects.filter(user=sender_user)
|
||||
if not persons.exists():
|
||||
self.log.info(f"No contacts found for {sender_username}")
|
||||
self.log.debug("No contacts found for %s", sender_username)
|
||||
sym("No contacts found.")
|
||||
return
|
||||
|
||||
@@ -989,7 +987,7 @@ class XMPPComponent(ComponentXMPP):
|
||||
else:
|
||||
sym("No such command")
|
||||
else:
|
||||
self.log.info("Other message")
|
||||
self.log.debug("Handling routed message to contact")
|
||||
if "|" in recipient_username:
|
||||
recipient_name, recipient_service = recipient_username.split("|")
|
||||
|
||||
@@ -1029,7 +1027,7 @@ class XMPPComponent(ComponentXMPP):
|
||||
identifier=identifier,
|
||||
user=identifier.user,
|
||||
)
|
||||
self.log.info(f"Component history store message {body}")
|
||||
self.log.debug("Storing outbound XMPP message in history")
|
||||
await history.store_message(
|
||||
session=session,
|
||||
sender="XMPP",
|
||||
@@ -1037,7 +1035,7 @@ class XMPPComponent(ComponentXMPP):
|
||||
ts=int(now().timestamp() * 1000),
|
||||
outgoing=True,
|
||||
)
|
||||
self.log.info("Stored a message sent from XMPP in the history.")
|
||||
self.log.debug("Stored outbound XMPP message in history")
|
||||
|
||||
manipulations = Manipulation.objects.filter(
|
||||
group__people=identifier.person,
|
||||
@@ -1045,7 +1043,7 @@ class XMPPComponent(ComponentXMPP):
|
||||
mode="mutate",
|
||||
enabled=True,
|
||||
)
|
||||
self.log.info(f"MANIP11 {manipulations}")
|
||||
self.log.debug("Found %s active manipulations", manipulations.count())
|
||||
if not manipulations:
|
||||
await self.ur.stopped_typing(
|
||||
"xmpp",
|
||||
@@ -1056,7 +1054,7 @@ class XMPPComponent(ComponentXMPP):
|
||||
body,
|
||||
attachments,
|
||||
)
|
||||
self.log.info("Message sent unaltered")
|
||||
self.log.debug("Message sent unaltered")
|
||||
return
|
||||
|
||||
manip = manipulations.first()
|
||||
@@ -1068,9 +1066,9 @@ class XMPPComponent(ComponentXMPP):
|
||||
manip,
|
||||
chat_history,
|
||||
)
|
||||
self.log.info("Running XMPP context prompt")
|
||||
self.log.debug("Running XMPP context prompt")
|
||||
result = await ai.run_prompt(prompt, manip.ai)
|
||||
self.log.info(f"RESULT {result}")
|
||||
self.log.debug("Generated mutated response for XMPP message")
|
||||
await history.store_own_message(
|
||||
session=session,
|
||||
text=result,
|
||||
@@ -1085,7 +1083,7 @@ class XMPPComponent(ComponentXMPP):
|
||||
result,
|
||||
attachments,
|
||||
)
|
||||
self.log.info("Message sent with modifications")
|
||||
self.log.debug("Message sent with modifications")
|
||||
|
||||
async def request_upload_slots(self, recipient_jid, attachments):
|
||||
"""Requests upload slots for multiple attachments concurrently."""
|
||||
@@ -1120,8 +1118,8 @@ class XMPPComponent(ComponentXMPP):
|
||||
f"Upload failed: {response.status} {await response.text()}"
|
||||
)
|
||||
return None
|
||||
self.log.info(
|
||||
f"Successfully uploaded {att['filename']} to {upload_url}"
|
||||
self.log.debug(
|
||||
"Successfully uploaded %s to %s", att["filename"], upload_url
|
||||
)
|
||||
|
||||
# Send XMPP message immediately after successful upload
|
||||
@@ -1148,7 +1146,7 @@ class XMPPComponent(ComponentXMPP):
|
||||
url_element.text = attachment_url
|
||||
msg.xml.append(oob_element)
|
||||
|
||||
self.log.info(f"Sending XMPP message: {msg.xml}")
|
||||
self.log.debug("Sending XMPP message: %s", msg.xml)
|
||||
msg.send()
|
||||
|
||||
async def send_chat_state(self, recipient_jid, sender_jid, started):
|
||||
@@ -1158,7 +1156,7 @@ class XMPPComponent(ComponentXMPP):
|
||||
msg.xml.append(
|
||||
ET.Element(f"{{http://jabber.org/protocol/chatstates}}{state_tag}")
|
||||
)
|
||||
self.log.info(
|
||||
self.log.debug(
|
||||
"Sending XMPP chat-state %s: %s -> %s",
|
||||
state_tag,
|
||||
sender_jid,
|
||||
@@ -1193,7 +1191,7 @@ class XMPPComponent(ComponentXMPP):
|
||||
|
||||
# Step 2: Request upload slots concurrently
|
||||
valid_uploads = await self.request_upload_slots(recipient_jid, attachments)
|
||||
self.log.info("Got upload slots")
|
||||
self.log.debug("Got upload slots")
|
||||
if not valid_uploads:
|
||||
self.log.warning("No valid upload slots obtained.")
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user