Handle a message in an existing thread.
(message: discord.Message, session: ConversationSession)
| 1169 | |
| 1170 | |
| 1171 | async def handle_thread_message(message: discord.Message, session: ConversationSession): |
| 1172 | """Handle a message in an existing thread.""" |
| 1173 | # Type guard: this function is only called for thread messages |
| 1174 | if not isinstance(message.channel, discord.Thread): |
| 1175 | logger.warning(f"handle_thread_message called with non-thread channel: {type(message.channel)}") |
| 1176 | return |
| 1177 | |
| 1178 | channel = message.channel # Now typed as discord.Thread |
| 1179 | image_urls, video_urls, file_urls = extract_media_urls(message) |
| 1180 | |
| 1181 | # Add to session |
| 1182 | session_manager.add_to_session( |
| 1183 | session=session, |
| 1184 | role="user", |
| 1185 | content=message.content, |
| 1186 | author=str(message.author), |
| 1187 | author_id=message.author.id, |
| 1188 | image_urls=image_urls + video_urls, # Combined for session storage (not files) |
| 1189 | ) |
| 1190 | |
| 1191 | async with channel.typing(): |
| 1192 | # Fetch thread history for context |
| 1193 | thread_history = await fetch_thread_history(channel) |
| 1194 | |
| 1195 | await process_message( |
| 1196 | channel=channel, |
| 1197 | user=message.author, |
| 1198 | text=message.content, |
| 1199 | image_urls=image_urls, |
| 1200 | session=session, |
| 1201 | thread_history=thread_history, |
| 1202 | reply_to=message, # Reply to user's message so they get pinged |
| 1203 | source_message=message, |
| 1204 | video_urls=video_urls, |
| 1205 | file_urls=file_urls, |
| 1206 | ) |
| 1207 | |
| 1208 | |
| 1209 | async def process_message( |
no test coverage detected