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

better setstatus for selfbots #1428

Merged
merged 4 commits into from
Apr 29, 2017
Merged

Conversation

Ratismal
Copy link
Contributor

@Ratismal Ratismal commented Apr 28, 2017

This PR makes minor modifications to the ClientUser#setStatus function to make it function properly for user accounts (selfbots).

Previously using the generic endpoint, setting a status programmatically on a user account would not work most of the time, and it would never adjust it on the client settings.

By modifying the ClientUserSettings object, we can circumvent this issue.

  1. Modifying statuses on a user account will work 100% of the time
  2. Modifying statuses on a user account selfbot will reflect on the actual client

This PR accomplishes this by

  1. Checking if the ClientUser is a bot
  2. If it is a user, then use the ClientUser#settings.update('status', value) function to properly update the user status
  3. If it is a bot, perform the presence update as per usual

I have made a GIF demonstrating this behavior
Hooray for status changes

Semantic versioning classification:

  • This PR changes the library's interface (methods or parameters added)
    • This PR includes breaking changes (methods removed or renamed, parameters moved or removed)
  • This PR only includes non-code changes, like changes to documentation, README, etc.

@devsnek
Copy link
Member

devsnek commented Apr 28, 2017

it should be

if (!this.bot) this.settings.update(Constants.UserSettingsMap.status, status);
return this.setPresence({ status });

@Ratismal
Copy link
Contributor Author

Doing that is redundant. I have done testing, and the status is globally set by just updating the settings object. This has been tested by viewing a client change from other accounts.

Considering that regular presence status sets don't work for user accounts, I see no point in making multiple calls for this.

@devsnek
Copy link
Member

devsnek commented Apr 28, 2017

that is quite interesting, and possibly a bug :3, but if it works /shrug

@Ratismal
Copy link
Contributor Author

I don't think it's necessarily a bug, I just think that's how it is set up for user accounts.

Bot accounts function differently, as each presence is per-shard. However, since user accounts don't shard their statuses are stored in a different place; namely, the ClientUserSettings.

I think that it works on a priority basis. For example from my experimentation:

  1. If you set yourself as invisible on your client, and then modify your status using presences, you will get the modified presence. This works for online, idle, and dnd
  2. If you set yourself as dnd on your client, and then modify your status using presences, you will get the modified presence only for online and idle. If you set to invisible, you become dnd
  3. If you set yourself as idle, and then modify your presence, you will only get the modified presence for online. dnd and invisible will become idle
  4. If you set yourself as online, nothing you do will change that

Thus, changing via presences can only make it equal or higher to your ClientUserSettings status.

@devsnek
Copy link
Member

devsnek commented Apr 28, 2017

i only say it could be a bug because the official client dispatches a presence update when you use the ui, in addition to posting the change to user settings

@Ratismal
Copy link
Contributor Author

Actually, upon further testing and in consideration with my writeup, I have discovered that the priority thing is indeed valid, so your suggestion was correct. If you set the presence to online and the settings to dnd, it will be online. My apologies.

@Ratismal
Copy link
Contributor Author

After some thought and some practical experimentation, I have come to another conclusion regarding setting the presence and the user settings. Yes, both must be set, but consider how discord displays the highest status they should not be set to the same thing. The next commit will do the following:

  1. Move the status code to the setPresence function rather than the setStatus. It just makes far more sense.
  2. If it is a user account and status is provided in data, set the presence status to invisible.

The second change is to allow the user to be able to freely change their own status. Say, for instance, they use the setStatus function to set both their presence and user settings to online. The next time they try to manually adjust their presence using the status indicators, they will be stuck on online. Considering that for user accounts the user settings is the most likely thing to change, it makes far more sense to force the presence to be invisible and only adjust the user settings.

With this, a user will be able to set their status using either the ClientUser#setPresence or ClientUser#setStatus functions, and then freely change it manually as if nothing happened.

@amishshah amishshah merged commit d6b7d31 into discordjs:master Apr 29, 2017
@amishshah
Copy link
Member

👍

devsnek pushed a commit to devsnek/discord.js that referenced this pull request May 14, 2017
* better setstatus for selfbots

* make both calls

* must return

* use setpresence, set invisible
devsnek pushed a commit to devsnek/discord.js that referenced this pull request May 14, 2017
* better setstatus for selfbots

* make both calls

* must return

* use setpresence, set invisible
Ratismal added a commit to Ratismal/discord.js that referenced this pull request Jul 5, 2017
* better setstatus for selfbots

* make both calls

* must return

* use setpresence, set invisible
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.

None yet

4 participants