Skip to content

Commit 4350213

Browse files
committed
im scared to lose my work :|
1 parent 058b315 commit 4350213

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

cogs/modmail.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ async def pareply(self, ctx, *, msg: str = ""):
873873
async with ctx.typing():
874874
await ctx.thread.reply(ctx.message, anonymous=True, plain=True)
875875

876-
@commands.command()
876+
@commands.group(invoke_without_command=True)
877877
@checks.has_permissions(PermissionLevel.SUPPORTER)
878878
@checks.thread_only()
879879
async def note(self, ctx, *, msg: str = ""):
@@ -887,6 +887,19 @@ async def note(self, ctx, *, msg: str = ""):
887887
msg = await ctx.thread.note(ctx.message)
888888
await msg.pin()
889889

890+
@note.command(name="persistent", aliases=["persist"])
891+
@checks.has_permissions(PermissionLevel.SUPPORTER)
892+
@checks.thread_only()
893+
async def note_persistent(self, ctx, *, msg: str = ""):
894+
"""
895+
Take a persistent note about the current user.
896+
"""
897+
ctx.message.content = msg
898+
async with ctx.typing():
899+
msg = await ctx.thread.note(ctx.message, persistent=True)
900+
await msg.pin()
901+
await self.bot.api.create_note(recipient=ctx.thread.recipient, message=ctx.message)
902+
890903
@commands.command()
891904
@checks.has_permissions(PermissionLevel.SUPPORTER)
892905
@checks.thread_only()

core/clients.py

+19
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,25 @@ async def search_by_text(self, text: str, limit: Optional[int]):
401401
{"messages": {"$slice": 5}},
402402
).to_list(limit)
403403

404+
async def create_note(self, recipient: Member, message: Message):
405+
await self.db.notes.insert_one(
406+
{
407+
"recipient": str(recipient.id),
408+
"author": {
409+
"id": str(message.author.id),
410+
"name": message.author.name,
411+
"discriminator": message.author.discriminator,
412+
"avatar_url": str(message.author.avatar_url),
413+
},
414+
}
415+
)
416+
417+
async def delete_note(self):
418+
pass
419+
420+
async def find_notes(self, recipient: Member):
421+
return await self.db.notes.find({"recipient": str(recipient.id)}).to_list(None)
422+
404423
def get_plugin_partition(self, cog):
405424
cls_name = cog.__class__.__name__
406425
return self.db.plugins[cls_name]

core/thread.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ async def send_recipient_genesis_message():
190190
close_emoji = await self.bot.convert_emoji(close_emoji)
191191
await self.bot.add_reaction(msg, close_emoji)
192192

193+
async def send_persistent_notes():
194+
notes = await self.bot.api.find_notes()
195+
for note in notes:
196+
message = discord.Message()
197+
await self.note(note.message)
198+
pass
199+
193200
await asyncio.gather(send_genesis_message(), send_recipient_genesis_message())
194201
self.bot.dispatch("thread_ready", self)
195202

@@ -629,11 +636,11 @@ async def edit_dm_message(self, message: discord.Message, content: str) -> None:
629636
self.bot.api.edit_message(message.id, content), linked_message.edit(embed=embed)
630637
)
631638

632-
async def note(self, message: discord.Message) -> None:
639+
async def note(self, message: discord.Message, persistent=False) -> None:
633640
if not message.content and not message.attachments:
634641
raise MissingRequiredArgument(SimpleNamespace(name="msg"))
635642

636-
msg = await self.send(message, self.channel, note=True)
643+
msg = await self.send(message, self.channel, note=True, persistent_note=persistent)
637644

638645
self.bot.loop.create_task(
639646
self.bot.api.append_log(
@@ -719,6 +726,7 @@ async def send(
719726
note: bool = False,
720727
anonymous: bool = False,
721728
plain: bool = False,
729+
persistent_note: bool = False,
722730
) -> None:
723731

724732
self.bot.loop.create_task(
@@ -780,7 +788,7 @@ async def send(
780788
else:
781789
# Special note messages
782790
embed.set_author(
783-
name=f"Note ({author.name})",
791+
name=f"{'Persistent' if persistent_note else ''} Note ({author.name})",
784792
icon_url=system_avatar_url,
785793
url=f"https://discordapp.com/users/{author.id}#{message.id}",
786794
)

0 commit comments

Comments
 (0)