Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix persistent notes #12

Merged
merged 1 commit into from
Jul 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions core/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import discord
import isodate
from discord.ext.commands import CommandError, MissingRequiredArgument
from discord.types.user import User as UserPayload, PartialUser as PartialUserPayload
from lottie.exporters import exporters as l_exporters
from lottie.importers import importers as l_importers

Expand Down Expand Up @@ -259,18 +260,22 @@ async def send_persistent_notes():
notes = await self.bot.api.find_notes(self.recipient)
ids = {}

# This is incredibly cursed and will break every time discord.py changes their internal API method
class State:
def store_user(self, user):
return user
# discord.state.ConnectionState.store_user_no_intents
def store_user(self, data: typing.Union[UserPayload, PartialUserPayload], *, cache: bool = True) -> discord.user.User:
return discord.user.User(state=self, data=data)

for note in notes:
author = note["author"]

class Author:
name = author["name"]
id = author["id"]
discriminator = author["discriminator"]
display_avatar = SimpleNamespace(url=author["avatar_url"])
author_dict: discord.types.user.PartialUser = {
"username": author["name"],
"id": author["id"],
"discriminator": author["discriminator"],
"avatar": author["avatar_url"],
"global_name": "dontlookatme",
}

data = {
"id": round(time.time() * 1000 - discord.utils.DISCORD_EPOCH) << 22,
Expand All @@ -282,7 +287,7 @@ class Author:
"mention_everyone": None,
"tts": None,
"content": note["message"],
"author": Author(),
"author": author_dict,
}
message = discord.Message(state=State(), channel=self.channel, data=data)
ids[note["_id"]] = str((await self.note(message, persistent=True, thread_creation=True)).id)
Expand Down
Loading