51 lines
1.9 KiB
Python
51 lines
1.9 KiB
Python
import discord
|
|
from discord.ext import commands
|
|
from chorus_bot.modality_map import modality_for_channel, direction_for_modality
|
|
from chorus_bot.ping import build_ping_embed
|
|
|
|
|
|
class ManualShareCog(commands.Cog):
|
|
"""Watches per-modality channels; forwards any new message as a ping in #inbox."""
|
|
|
|
def __init__(self, bot: commands.Bot, config):
|
|
self.bot = bot
|
|
self.config = config
|
|
|
|
@commands.Cog.listener()
|
|
async def on_message(self, message: discord.Message):
|
|
if message.author.bot:
|
|
return
|
|
if message.channel.id == self.config.inbox_channel_id:
|
|
return # inbox itself is not a source channel
|
|
|
|
modality = modality_for_channel(message.channel.name)
|
|
if modality is None:
|
|
return
|
|
|
|
attachment_urls = [attachment.url for attachment in message.attachments]
|
|
|
|
raw_content = message.content
|
|
if attachment_urls:
|
|
attachments_block = "Attachments:\n" + "\n".join(attachment_urls)
|
|
raw_content = f"{raw_content}\n\n{attachments_block}" if raw_content else attachments_block
|
|
|
|
display_content = message.content or "(attachment only - see original message)"
|
|
snippet = display_content if len(display_content) <= 120 else display_content[:117] + "..."
|
|
|
|
embed = build_ping_embed(
|
|
modality=modality,
|
|
sender_id=None,
|
|
snippet=snippet,
|
|
raw_content=raw_content,
|
|
captured_at=message.created_at,
|
|
direction=direction_for_modality(modality),
|
|
image_url=attachment_urls[0] if attachment_urls else None,
|
|
)
|
|
|
|
inbox = self.bot.get_channel(self.config.inbox_channel_id)
|
|
role_mention = f"<@&{self.config.triage_role_id}>"
|
|
await inbox.send(content=role_mention, embed=embed)
|
|
|
|
|
|
async def setup(bot: commands.Bot, config):
|
|
await bot.add_cog(ManualShareCog(bot, config))
|