|
13 | 13 | import os |
14 | 14 | import re |
15 | 15 | from contextvars import ContextVar |
16 | | -from datetime import datetime, timezone |
| 16 | +from datetime import UTC, datetime |
17 | 17 | from typing import Any |
18 | 18 | from urllib.parse import quote |
19 | 19 |
|
@@ -275,7 +275,9 @@ async def _verify_signature( |
275 | 275 | verify_key.verify(message, bytes.fromhex(signature)) |
276 | 276 | return True |
277 | 277 | except ImportError: |
278 | | - self._logger.error("PyNaCl is required for Discord signature verification. Install with: pip install PyNaCl") |
| 278 | + self._logger.error( |
| 279 | + "PyNaCl is required for Discord signature verification. Install with: pip install PyNaCl" |
| 280 | + ) |
279 | 281 | return False |
280 | 282 | except Exception as exc: |
281 | 283 | self._logger.warn("Discord signature verification failed", {"error": str(exc)}) |
@@ -320,7 +322,9 @@ def _handle_component_interaction( |
320 | 322 | channel_type = channel.get("type", 0) |
321 | 323 | is_thread = channel_type in (CHANNEL_TYPE_PUBLIC_THREAD, CHANNEL_TYPE_PRIVATE_THREAD) |
322 | 324 | parent_channel_id = ( |
323 | | - channel.get("parent_id", interaction_channel_id) if is_thread and channel.get("parent_id") else interaction_channel_id |
| 325 | + channel.get("parent_id", interaction_channel_id) |
| 326 | + if is_thread and channel.get("parent_id") |
| 327 | + else interaction_channel_id |
324 | 328 | ) |
325 | 329 |
|
326 | 330 | thread_id = self.encode_thread_id( |
@@ -391,7 +395,9 @@ def _handle_application_command_interaction( |
391 | 395 | channel_type = channel.get("type", 0) |
392 | 396 | is_thread = channel_type in (CHANNEL_TYPE_PUBLIC_THREAD, CHANNEL_TYPE_PRIVATE_THREAD) |
393 | 397 | parent_channel_id = ( |
394 | | - channel.get("parent_id", interaction_channel_id) if is_thread and channel.get("parent_id") else interaction_channel_id |
| 398 | + channel.get("parent_id", interaction_channel_id) |
| 399 | + if is_thread and channel.get("parent_id") |
| 400 | + else interaction_channel_id |
395 | 401 | ) |
396 | 402 |
|
397 | 403 | channel_id = self.encode_thread_id( |
@@ -534,7 +540,9 @@ async def _handle_forwarded_message( |
534 | 540 | mentions = data.get("mentions", []) |
535 | 541 | is_user_mentioned = data.get("is_mention", False) or any(m.get("id") == self._application_id for m in mentions) |
536 | 542 | mention_roles = data.get("mention_roles", []) |
537 | | - is_role_mentioned = bool(self._mention_role_ids) and any(role_id in self._mention_role_ids for role_id in mention_roles) |
| 543 | + is_role_mentioned = bool(self._mention_role_ids) and any( |
| 544 | + role_id in self._mention_role_ids for role_id in mention_roles |
| 545 | + ) |
538 | 546 | is_mentioned = is_user_mentioned or is_role_mentioned |
539 | 547 |
|
540 | 548 | # If mentioned and not in a thread, create one |
@@ -578,7 +586,7 @@ async def _handle_forwarded_message( |
578 | 586 | metadata=MessageMetadata( |
579 | 587 | date_sent=datetime.fromisoformat(data.get("timestamp", "")) |
580 | 588 | if data.get("timestamp") |
581 | | - else datetime.now(timezone.utc), |
| 589 | + else datetime.now(UTC), |
582 | 590 | edited=False, |
583 | 591 | ), |
584 | 592 | attachments=[ |
@@ -1158,7 +1166,7 @@ def _parse_discord_message(self, raw: dict[str, Any], thread_id: str) -> Message |
1158 | 1166 | is_me=is_me, |
1159 | 1167 | ), |
1160 | 1168 | metadata=MessageMetadata( |
1161 | | - date_sent=datetime.fromisoformat(msg["timestamp"]) if msg.get("timestamp") else datetime.now(timezone.utc), |
| 1169 | + date_sent=datetime.fromisoformat(msg["timestamp"]) if msg.get("timestamp") else datetime.now(UTC), |
1162 | 1170 | edited=msg.get("edited_timestamp") is not None, |
1163 | 1171 | edited_at=datetime.fromisoformat(msg["edited_timestamp"]) if msg.get("edited_timestamp") else None, |
1164 | 1172 | ), |
@@ -1203,7 +1211,7 @@ async def _create_discord_thread( |
1203 | 1211 | message_id: str, |
1204 | 1212 | ) -> dict[str, str]: |
1205 | 1213 | """Create a Discord thread from a message.""" |
1206 | | - thread_name = f"Thread {datetime.now(timezone.utc).isoformat()}" |
| 1214 | + thread_name = f"Thread {datetime.now(UTC).isoformat()}" |
1207 | 1215 |
|
1208 | 1216 | self._logger.debug( |
1209 | 1217 | "Discord API: POST thread", |
|
0 commit comments