-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Support for linking plain messages. #3012
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
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
By the way, this still can be improved. So the example of code for async def find_linked_messages(
self,
message_id: Optional[int] = None,
either_direction: bool = False,
message1: discord.Message = None,
note: bool = True,
) -> Tuple[discord.Message, Optional[discord.Message], str]:
if message1 is not None:
if not (message1.author == self.bot.user and message1.embeds):
raise ValueError("Malformed thread message.")
elif message_id is not None:
try:
message1 = await self.channel.fetch_message(message_id)
except discord.NotFound:
raise ValueError("Thread message not found.")
if not (message1.author == self.bot.user and message1.embeds):
raise ValueError("Malformed thread message.")
thread_logs = await self.bot.api.logs.find_one({"channel_id": str(self.channel.id)})
if thread_logs is None:
raise ValueError("Thread logs not found.")
messages_logs = thread_logs["messages"]
def unpack_data(msg_id):
# internal function since this will be used twice
linked_ids, type_, from_mod = next(
(
(
data.get("linked_ids"),
data.get("type"),
data.get("author", {}).get("mod", False),
)
for data in messages_logs
if str(msg_id) in data.get("linked_ids", [])
or str(msg_id) == data.get("message_id", str())
),
(None, str(), False),
)
return linked_ids, type_, from_mod
if message1 is None:
# still None, this is usually when using `delete` or `edit` command without providing ID
# so in this case, we only search for thread message
# Note or persistent note will not be returned if ID is not provided
async for message1 in self.channel.history():
linked_ids, type_, from_mod = unpack_data(message1.id)
if from_mod and type_ not in ("system", "internal"):
break
else:
raise ValueError("Thread message not found.")
else:
linked_ids, type_, from_mod = unpack_data(message1.id)
if linked_ids:
if not from_mod and not either_direction:
raise ValueError("Thread message not found.")
async for msg in self.recipient.history():
if str(msg.id) in linked_ids:
return message1, msg, type_
raise ValueError("DM message not found.")
if type_ == "system" and note:
return message1, None, type_
raise ValueError("Thread message not found.") |
…read. Also remove error response saying 'Plain messages are not supported' in `?delete` command.
Closing this since this is now outdated and there would be merge conflicts. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Regarding issue #2876
About this PR:
linked_ids
(type: list) for methodappend_log
inclients.py
. The linked IDs will be stored when the thread message is sent whether from thread or DM.find_linked_messages
inthread.py
, which would be the type of the thread message. Expected "thread_message", "anonymous", or "system".author
(type: discord.Member) for methodedit_message
inthread.py
.Note: