opt-natter / discord-mybb-sync

A MyBB Plugin to syncronise MyBB Groups with Discord Roles
MIT License
11 stars 3 forks source link

Plugin not compatible with new discord username convention #30

Open TK-3375 opened 1 year ago

TK-3375 commented 1 year ago

Discord has started rolling out it's new username policy, and it's not compatible with what the script expects... usernames are expected to have the UserName#1234 form, except that's not the case anymore.

Not sure how much more changes are involved by discord new username policy, but at least one cannot edit it's profile on the forum, the plugin gets mad if the string submitted doesn't have the #1234 part.

TK-3375 commented 1 year ago

Proposal (untested) : change DRS_DISCORD_ID_FORMAT regex to :

$plugins->add_hook("usercp_do_profile_end", "discord_right_sync_user_profile"); //provide a check for die right discord id format define("DRS_DISCORD_ID_FORMAT", '.[a-z0-9_.]{2,32}');

That should account for discord new username policy : 2 to 32 characters long, plus underscores and periods.

https://support.discord.com/hc/en-us/articles/12620128861463-New-Usernames-Display-Names#:~:text=Over%20the%20coming%20weeks%2C%20every,unique%20username%20to%20use%20Discord.

Granted usernames are supposed to be lowercase now, so when saving them we should lowercase them too.

serax75 commented 1 year ago

This prevents the plugin from deleting the supposedly invalid DiscordID in myBB, but when the task runs, the username doesn't match Discord somehow so the Discord account isn't updated at all.

TK-3375 commented 1 year ago

This prevents the plugin from deleting the supposedly invalid DiscordID in myBB, but when the task runs, the username doesn't match Discord somehow so the Discord account isn't updated at all.

After checking some more the code does a lot more than what I expected, so I guess more refactoring than just updating the regex might be needed. That's beyond my abilities though. Hopefully natter and marc still read this github and can come up with an update. It's a great addon for myBB, would be sad losing it.

opt-natter commented 1 year ago

can you check with the new version? old user names and the global discord ID should work now.

serax75 commented 1 year ago

Well, that just updated a bunch of folks incorrectly.

discord_right_sync.php line 620 DEBUG: Unirest\Response Object ( [code] => 200 [raw_body] => {"avatar": null, "communication_disabled_until": null, "flags": 0, "joined_at": "2023-01-15T19:44:37.288000+00:00", "nick": null, "pending": false, "premium_since": null, "roles": [], "user": {"id": "455744229075845121", "username": "corona (Dallas)", "avatar": "812afd971ea16fac3ee061b6b6744487", "discriminator": "8648", "public_flags": 0, "flags": 0, "banner": null, "accent_color": null, "global_name": null, "avatar_decoration": null, "display_name": null, "banner_color": null}, "mute": false, "deaf": false} [body] => stdClass Object ( [avatar] => [communication_disabled_until] => [flags] => 0 [joined_at] => 2023-01-15T19:44:37.288000+00:00 [nick] => [pending] => [premium_since] => [roles] => Array ( ) [user] => stdClass Object ( [id] => 455744229075845121 [username] => corona (Dallas) [avatar] => 812afd971ea16fac3ee061b6b6744487 [discriminator] => 8648 [public_flags] => 0 [flags] => 0 [banner] => [accent_color] => [global_name] => [avatar_decoration] => [display_name] => [banner_color] => ) [mute] => [deaf] => ) [headers] => Array ( [0] => HTTP/2 200 [date] => Fri, 16 Jun 2023 20:15:17 GMT [content-type] => application/json [set-cookie] => Array ( [0] => dcfduid=82c70f5a0c8211eea3b7c61daf323f7c; Expires=Wed, 14-Jun-2028 20:15:17 GMT; Max-Age=157680000; Secure; HttpOnly; Path=/ [1] => sdcfduid=82c70f5a0c8211eea3b7c61daf323f7c1adfffeb202b1671ab5691987b71cad79408881082fdc6758b9efb3b467deba1; Expires=Wed, 14-Jun-2028 20:15:17 GMT; Max-Age=157680000; Secure; HttpOnly; Path=/ [2] => __cfruid=ba2ac324bf659b9c06de32af51c4531ea009e98b-1686946517; path=/; domain=.discord.com; HttpOnly; Secure; SameSite=None ) [strict-transport-security] => max-age=31536000; includeSubDomains; preload [x-ratelimit-bucket] => c7f060a5d9790cb6f53000110a7b7edf [x-ratelimit-limit] => 10 [x-ratelimit-remaining] => 0 [x-ratelimit-reset] => 1686946523.024 [x-ratelimit-reset-after] => 6.111 [content-encoding] => gzip [via] => 1.1 google [alt-svc] => h3=":443"; ma=86400 [cf-cache-status] => DYNAMIC [report-to] => {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=mz6kGcVgGTHa6BOe8tK3PiF3Wtx5c6ZF60dpijo8Oa4Da6StxR99ImY9py5b6W2T%2FKjgpZJjOVj9Y8hYCzSZDU9ngR%2Fsst8Q%2FitCPFTo%2Bq2x0ukpt3tVVA19oqz7"}],"group":"cf-nel","max_age":604800} [nel] => {"success_fraction":0,"report_to":"cf-nel","max_age":604800} [x-content-type-options] => nosniff [content-security-policy] => frame-ancestors 'none'; default-src 'none' [server] => cloudflare [cf-ray] => 7d85b951e8b44196-AMS ) )

discord_right_sync.php line 630 INFO: Discord RateLimit was reached

discord_right_sync returned false

serax75 commented 1 year ago

Also seeing this which may be an issue :

discord_right_sync.php line 620 DEBUG: Unirest\Response Object ( [code] => 403 [raw_body] => {"message": "Missing Permissions", "code": 50013} [body] => stdClass Object ( [message] => Missing Permissions [code] => 50013 ) [headers] => Array ( [0] => HTTP/2 403 [date] => Fri, 16 Jun 2023 20:22:59 GMT [content-type] => application/json [set-cookie] => Array ( [0] => dcfduid=96398fbc0c8311eebac3a6e7d6557c24; Expires=Wed, 14-Jun-2028 20:22:59 GMT; Max-Age=157680000; Secure; HttpOnly; Path=/ [1] => sdcfduid=96398fbc0c8311eebac3a6e7d6557c24a24bdb0979c4699f21df7eed92a382b4240a60e881992a3e16f32eaf456cdb31; Expires=Wed, 14-Jun-2028 20:22:59 GMT; Max-Age=157680000; Secure; HttpOnly; Path=/ [2] => __cfruid=2dda07263e0d7826f0bb79a75c54e8641bcf65d0-1686946979; path=/; domain=.discord.com; HttpOnly; Secure; SameSite=None ) [strict-transport-security] => max-age=31536000; includeSubDomains; preload [x-ratelimit-bucket] => c7f060a5d9790cb6f53000110a7b7edf [x-ratelimit-limit] => 10 [x-ratelimit-remaining] => 9 [x-ratelimit-reset] => 1686946989.520 [x-ratelimit-reset-after] => 10.000 [via] => 1.1 google [alt-svc] => h3=":443"; ma=86400 [cf-cache-status] => DYNAMIC [report-to] => {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=X2JOMxbYIpu84FNOn3lSKWjeR8V9bT2pB%2Fx35QuX7JeG26m8Cuzcad4PpTmw0sPfAWDR7syJDm1CqOnbzqa8rUfW3%2FopuTPmkAkBpEc%2BZaih0%2B3biGRD1Cj6J1mK"}],"group":"cf-nel","max_age":604800} [nel] => {"success_fraction":0,"report_to":"cf-nel","max_age":604800} [x-content-type-options] => nosniff [content-security-policy] => frame-ancestors 'none'; default-src 'none' [server] => cloudflare [cf-ray] => 7d85c49d7eb50bbf-AMS [content-encoding] => gzip ) )

discord_right_sync.php line 603 DEBUG: Update guilds/1020557030399950910/members/308716325759352833 HTTP-Response:403

opt-natter commented 1 year ago

Are the wrong assigned roles from users with username#1234 or the discord id? For the 403 you could check: https://github.com/opt-natter/discord-mybb-sync/issues/27#issuecomment-1596123339

serax75 commented 1 year ago

Are the wrong assigned roles from users with username#1234 or the discord id?

They are users with username#1234.

serax75 commented 1 year ago

I converted all my users over to the 18-digit ID, and the plugin tool works correctly now.

TK-3375 commented 1 year ago

I converted all my users over to the 18-digit ID, and the plugin tool works correctly now.

We can't use regular username now ? That ID thing is supposed to only be available in dev mode in discord I believe. Users aren't going to figure that out easily I reckon :/

TK-3375 commented 1 year ago

I tried to upgrade to the newest version, but it doesn't seem like it's working, I get a "discord_right_sync returned false" in the log...

halp !

rmtninja commented 1 year ago

I converted all my users over to the 18-digit ID, and the plugin tool works correctly now.

What you with 19-digit ID users? im trying fix it for days if you can help me please add discord: rmtninja

TK-3375 commented 1 year ago

OK 0.8 doesn't seem to work for me : when updating my userprofile I get the "Your Discord ID does is probably wrong. Please check it again." error. I tried with both my username and discord ID, both fail :(

TK-3375 commented 1 year ago

After double checking the code (at least the little I can understand from it) :

define("DRS_DISCORD_ID_FORMAT_old", '.{1,32}#\d{4}'); //discord ID Format check NAME#0000 define("DRS_DISCORD_ID_FORMAT_new", '\d{18}'); //discord ID check

It seems we are either checking for old format : username#1245 or for digits, not regular usernames that most people will use.

Also : regardless previous message stands : neither old format nor digits work, I get a discord id is wrong error when updating my profile.

TK-3375 commented 1 year ago

Are the wrong assigned roles from users with username#1234 or the discord id? For the 403 you could check: #27 (comment)

Sorry to bother you, but do you know if that can be fixed ? I sadly lack the technical skills to help further, but that plugin is awesome and it's sad to see it being broken by discord new username policy.

TK-3375 commented 1 month ago

Are the wrong assigned roles from users with username#1234 or the discord id? For the 403 you could check: #27 (comment)

upping that issue : that bot was awesome, any hopes you can look up the issue someday ?