Skip to content

Conversation

@codeofandrin
Copy link
Contributor

Summary

This PR adds support for the message call object.

Related PR:

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

Copy link
Owner

@Rapptz Rapptz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly okay, I'd prefer consistency with the previous version.

The previous name was CallMessage and not MessageCall. I still think that name makes more sense than the current one because Call is the adjective for Message, similar to PartialMessage rather than MessagePartial.

@codeofandrin codeofandrin requested a review from Rapptz August 29, 2024 19:55
@MCausc78
Copy link
Contributor

I think Message.system_content needs update to handle MessageType.call.

@codeofandrin
Copy link
Contributor Author

I think Message.system_content needs update to handle MessageType.call.

yes you're right, it currently returns an empty string.

@codeofandrin
Copy link
Contributor Author

The problem about this is: I don't know e.g. when Discord uses the next hour. When is it an hour and when is it 2 hours. I would assume that 91min is 2 hours and 89min is an hour but it could also be that 60..115min is an hour and the rest is 2 hours.

@Rapptz
Copy link
Owner

Rapptz commented Aug 29, 2024

You can see the previous implementation:

if self.type is MessageType.call:
# we're at the call message type now, which is a bit more complicated.
# we can make the assumption that Message.channel is a PrivateChannel
# with the type ChannelType.group or ChannelType.private
call_ended = self.call.ended_timestamp is not None
if self.channel.me in self.call.participants:
return '{0.author.name} started a call.'.format(self)
elif call_ended:
return 'You missed a call from {0.author.name}'.format(self)
else:
return '{0.author.name} started a call \N{EM DASH} Join the call.'.format(self)

However it's pretty out-of-date. From the client, the strings are as follows:

SYSTEM_MESSAGE_CALL_STARTED_HOOK: $[!!{username}!!](usernameHook) started a call.,
SYSTEM_MESSAGE_CALL_STARTED: [!!{username}!!](usernameOnClick) started a call.,
SYSTEM_MESSAGE_CALL_STARTED_WITH_DURATION_HOOK: $[!!{username}!!](usernameHook) started a call that lasted !!{callDuration}!!.,
SYSTEM_MESSAGE_CALL_MISSED_HOOK: You missed a call from $[!!{username}!!](usernameHook).,
SYSTEM_MESSAGE_CALL_MISSED_WITH_DURATION_HOOK: You missed a call from $[!!{username}!!](usernameHook) that lasted !!{callDuration}!!.,
SYSTEM_MESSAGE_JOIN_CALL: Join the call

The client formats the duration string like this...

m = function(e) {
    let t = null != e.call ? e.call.duration : null;
    return null != t ? t.humanize() : null
}(t);

Which isn't very helpful. We can just take your liberty here and just round, so 2.5 hours => 3 hours but 2.3 hours => 2 hours. Less than 1 hour would be in minutes (so 59 minutes is possible instead of rounding to an hour).

The skeleton should be something like this:

if self.type is MessageType.call:
    call_ended = self.call.ended_timestamp is not None
    missed = self._state.user not in self.call.participants

    if call_ended:
        duration = ...
        if missed:
            return 'You missed a call from {0.author.name} that lasted {1}'.format(self, duration)
        else:
            return '{0.author.name} started a call that lasted {1}.'.format(self, duration)
    else:
        if missed:
            return '{0.author.name} started a call \N{EM DASH} Join the call.'.format(self)
        else:
            return '{0.author.name} started a call.'.format(self)

@codeofandrin
Copy link
Contributor Author

I've just noted that mentions doesn't contain the users anymore:

self._message.mentions=[]

So we have to retrieve the users directly from the cache.

@codeofandrin
Copy link
Contributor Author

I've added the system call message. The "calculation" is based on how Discord determines it (approx.). I've manipulated the message object in the client to see what the output is. I also made some unit tests, which can be found here:

https://github.com/Puncher1/discord.py/blob/message-call-unittest/tests/test_call_system_content.py

@codeofandrin codeofandrin requested a review from Rapptz October 10, 2024 09:20
@Rapptz Rapptz merged commit 20c543f into Rapptz:master Oct 10, 2024
8 checks passed
@codeofandrin codeofandrin deleted the message-call branch October 10, 2024 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants