Skip to content

Commit

Permalink
fix note code
Browse files Browse the repository at this point in the history
upgrade signature of note code state store_user method to match expected discord.py method

use a typed checked dict for author instead of making a declaring a class in a for loop that replicates a different type. hopefully a type checker would raise warnings the next time one of these changes
  • Loading branch information
khakers committed Jul 21, 2023
1 parent c9a9d00 commit e7635f1
Showing 1 changed file with 13 additions and 8 deletions.
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

0 comments on commit e7635f1

Please sign in to comment.