img-17: cache image-only posts; news pipeline notes
This commit is contained in:
+26
-17
@@ -401,35 +401,44 @@ class FjerkroaBot(commands.Bot):
|
||||
def get_ai_responder(self, channel_name):
|
||||
return self.aichannels[channel_name] if channel_name in self.aichannels else self.airesponder
|
||||
|
||||
async def _ingest_attachments(self, message, channel_name: str, airesponder) -> list:
|
||||
"""Cache-first attachment handling; CDN URLs never travel further (IMG-10/11)."""
|
||||
urls = []
|
||||
for attachment in message.attachments:
|
||||
if airesponder.image_cache is None:
|
||||
urls.append(attachment.url)
|
||||
continue
|
||||
sha = await airesponder.image_cache.ingest_url(attachment.url, channel_name, message.author.name, str(message.id))
|
||||
if sha is not None:
|
||||
recent = airesponder.image_cache.recent(channel_name, 8)
|
||||
ext = next((row["ext"] for row in recent if row["sha256"] == sha), "png")
|
||||
data_url = airesponder.image_cache.data_url(sha, ext)
|
||||
if data_url:
|
||||
urls.append(data_url)
|
||||
return urls
|
||||
|
||||
async def handle_message_through_responder(self, message):
|
||||
"""Handle a message through the AI responder"""
|
||||
message_content = str(message.content).strip()
|
||||
if message.reference and message.reference.resolved and isinstance(message.reference.resolved.content, str):
|
||||
reference_content = str(message.reference.resolved.content).replace("\n", "> \n")
|
||||
message_content = f"> {reference_content}\n\n{message_content}"
|
||||
channel_name = self.get_channel_name(message.channel)
|
||||
airesponder = self.get_ai_responder(channel_name)
|
||||
attachment_urls = []
|
||||
if message.attachments:
|
||||
attachment_urls = await self._ingest_attachments(message, channel_name, airesponder)
|
||||
if len(message_content) < 1:
|
||||
# image-only posts: cached + observed, no reply (IMG-17)
|
||||
if attachment_urls:
|
||||
await airesponder.observe_event(message.author.name, "image", f"posted {len(attachment_urls)} image(s)")
|
||||
return
|
||||
message_content = self._resolve_mentions(message_content)
|
||||
channel_name = self.get_channel_name(message.channel)
|
||||
msg = AIMessage(
|
||||
message.author.name, message_content, channel_name, self.user in message.mentions or isinstance(message.channel, DMChannel)
|
||||
)
|
||||
airesponder = self.get_ai_responder(channel_name)
|
||||
if message.attachments:
|
||||
for attachment in message.attachments:
|
||||
if not msg.urls:
|
||||
msg.urls = []
|
||||
if airesponder.image_cache is not None:
|
||||
# cache-first: CDN URLs never travel further (IMG-10/11)
|
||||
sha = await airesponder.image_cache.ingest_url(attachment.url, channel_name, message.author.name, str(message.id))
|
||||
if sha is not None:
|
||||
recent = airesponder.image_cache.recent(channel_name, 8)
|
||||
ext = next((row["ext"] for row in recent if row["sha256"] == sha), "png")
|
||||
data_url = airesponder.image_cache.data_url(sha, ext)
|
||||
if data_url:
|
||||
msg.urls.append(data_url)
|
||||
else:
|
||||
msg.urls.append(attachment.url)
|
||||
if attachment_urls:
|
||||
msg.urls = attachment_urls
|
||||
|
||||
# Reply/ignore classifier gate — direct messages bypass (BEH-01/02/03/07)
|
||||
handled, factual = await self._classifier_gate(message, msg, airesponder, channel_name)
|
||||
|
||||
Reference in New Issue
Block a user