|
3 | 3 | import re |
4 | 4 | import typing |
5 | 5 | from datetime import datetime, timedelta |
| 6 | +import time |
6 | 7 | from types import SimpleNamespace |
7 | 8 |
|
8 | 9 | import isodate |
@@ -191,13 +192,42 @@ async def send_recipient_genesis_message(): |
191 | 192 | await self.bot.add_reaction(msg, close_emoji) |
192 | 193 |
|
193 | 194 | async def send_persistent_notes(): |
194 | | - notes = await self.bot.api.find_notes() |
| 195 | + notes = await self.bot.api.find_notes(self.recipient) |
| 196 | + ids = {} |
| 197 | + |
| 198 | + class State: |
| 199 | + def store_user(self, user): |
| 200 | + return user |
| 201 | + |
195 | 202 | for note in notes: |
196 | | - message = discord.Message() |
197 | | - await self.note(note.message) |
198 | | - pass |
| 203 | + author = note["author"] |
| 204 | + |
| 205 | + class Author: |
| 206 | + name = author["name"] |
| 207 | + id = author["id"] |
| 208 | + discriminator = author["discriminator"] |
| 209 | + avatar_url = author["avatar_url"] |
| 210 | + |
| 211 | + data = { |
| 212 | + "id": round(time.time() * 1000 - discord.utils.DISCORD_EPOCH) << 22, |
| 213 | + "attachments": {}, |
| 214 | + "embeds": {}, |
| 215 | + "edited_timestamp": None, |
| 216 | + "type": None, |
| 217 | + "pinned": None, |
| 218 | + "mention_everyone": None, |
| 219 | + "tts": None, |
| 220 | + "content": note["message"], |
| 221 | + "author": Author(), |
| 222 | + } |
| 223 | + message = discord.Message(state=State(), channel=None, data=data) |
| 224 | + ids[note["_id"]] = str((await self.note(message, persistent=True, thread_creation=True)).id) |
| 225 | + |
| 226 | + await self.bot.api.update_note_ids(ids) |
199 | 227 |
|
200 | | - await asyncio.gather(send_genesis_message(), send_recipient_genesis_message()) |
| 228 | + await asyncio.gather( |
| 229 | + send_genesis_message(), send_recipient_genesis_message(), send_persistent_notes() |
| 230 | + ) |
201 | 231 | self.bot.dispatch("thread_ready", self) |
202 | 232 |
|
203 | 233 | def _format_info_embed(self, user, log_url, log_count, color): |
@@ -517,11 +547,14 @@ async def find_linked_messages( |
517 | 547 | ): |
518 | 548 | raise ValueError("Thread message not found.") |
519 | 549 |
|
520 | | - if message1.embeds[0].color.value == self.bot.main_color and message1.embeds[ |
521 | | - 0 |
522 | | - ].author.name.startswith("Note"): |
| 550 | + if message1.embeds[0].color.value == self.bot.main_color and ( |
| 551 | + message1.embeds[0].author.name.startswith("Note") |
| 552 | + or message1.embeds[0].author.name.startswith("Persistent Note") |
| 553 | + ): |
523 | 554 | if not note: |
524 | 555 | raise ValueError("Thread message not found.") |
| 556 | + elif message1.embeds[0].author.name.startswith("Persistent Note"): |
| 557 | + await self.bot.api.delete_note(message_id) |
525 | 558 | return message1, None |
526 | 559 |
|
527 | 560 | if message1.embeds[0].color.value != self.bot.mod_color and not ( |
@@ -636,11 +669,11 @@ async def edit_dm_message(self, message: discord.Message, content: str) -> None: |
636 | 669 | self.bot.api.edit_message(message.id, content), linked_message.edit(embed=embed) |
637 | 670 | ) |
638 | 671 |
|
639 | | - async def note(self, message: discord.Message, persistent=False) -> None: |
| 672 | + async def note(self, message: discord.Message, persistent=False, thread_creation=False) -> None: |
640 | 673 | if not message.content and not message.attachments: |
641 | 674 | raise MissingRequiredArgument(SimpleNamespace(name="msg")) |
642 | 675 |
|
643 | | - msg = await self.send(message, self.channel, note=True, persistent_note=persistent) |
| 676 | + msg = await self.send(message, self.channel, note=True, persistent_note=persistent, thread_creation=thread_creation) |
644 | 677 |
|
645 | 678 | self.bot.loop.create_task( |
646 | 679 | self.bot.api.append_log( |
@@ -727,6 +760,7 @@ async def send( |
727 | 760 | anonymous: bool = False, |
728 | 761 | plain: bool = False, |
729 | 762 | persistent_note: bool = False, |
| 763 | + thread_creation: bool = False, |
730 | 764 | ) -> None: |
731 | 765 |
|
732 | 766 | self.bot.loop.create_task( |
@@ -876,7 +910,7 @@ async def send( |
876 | 910 | embed.set_footer(text=f"Message ID: {message.id}") |
877 | 911 | embed.colour = self.bot.recipient_color |
878 | 912 |
|
879 | | - if from_mod or note: |
| 913 | + if (from_mod or note) and not thread_creation: |
880 | 914 | delete_message = not bool(message.attachments) |
881 | 915 | if delete_message and destination == self.channel: |
882 | 916 | try: |
|
0 commit comments