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

undiscord tries to delete app commands #526

Open
2 of 4 tasks
RainerZufall187 opened this issue Jul 9, 2023 · 7 comments
Open
2 of 4 tasks

undiscord tries to delete app commands #526

RainerZufall187 opened this issue Jul 9, 2023 · 7 comments

Comments

@RainerZufall187
Copy link

Undiscord Version

v5.2.3

Browser

firefox 115.0.1 (64-bit)

Extension

tampermonkey

Reproduction steps

....

Actual results

Error deleting message, API responded with status 403! {"message":"Missing Permissions","code":50013}

Expected results

dont delete app commands when you have no permissions to

Bug affects

  • DMs
  • DMs (group)
  • Channels
  • Channel (NSFW)

Additional information & file uploads

ssfsa df

@CactusHamster
Copy link

It looks like this bug is caused as the result of Discord's search API including messages that were sent as replies to a user's slash commands. The issue is fixed by ensuring that the to-be-deleted messages' author ids matches the author id given in the GUI's options.

An extra check could be added in undiscord-core.js at around line 314. The check would ensure that the message author ID matches the value of the AUTHOR ID setting in the GUI.

if (this.options.authorId) messagesToDelete = messagesToDelete.filter(msg => msg.author.id === this.options.authorId);

I included an extra conditional statement to avoid needlessly filtering the list if the option was not utilized, rather than using an unperformant nullish coalescing operator as the other filters do.

@JayBoom
Copy link

JayBoom commented Aug 1, 2023

I think this is the same as #535 , with it trying to delete MEE6 messages.

@CactusHamster I will try your solution, but my bug report also includes archived threads, do you have a fix on that?

Edit: Cactus, how do we edit the tampermonkey script to implement your code as line 314 I don't think is the same as the one you are referencing.

Edit 2: Found it at line 731

@CactusHamster
Copy link

CactusHamster commented Aug 1, 2023

@JayBoom line 314 seems to be the correct place? I'm not the author- you definitely could know better than me but github displays it as line 314 for me.
Somewhere around here:
https://github.com/victornpb/undiscord/blob/9ce4d7bdd3342b34c316981b0024e9f06c654846/src/undiscord-core.js#L310C1-L314C1

edit: Sorry for the URL rather than a snippet- according to a quick google, GitHub seems to be having problems with them right now?

another edit: oh!! I see what you meant. I expected the author to have a tool to build the tampermonkey script rather than manually updating both sources.

@JayBoom
Copy link

JayBoom commented Aug 1, 2023

@JayBoom line 314 seems to be the correct place? I'm not the author- you definitely could know better than me but github displays it as line 314 for me. Somewhere around here: https://github.com/victornpb/undiscord/blob/9ce4d7bdd3342b34c316981b0024e9f06c654846/src/undiscord-core.js#L310C1-L314C1

edit: Sorry for the URL rather than a snippet- according to a quick google, GitHub seems to be having problems with them right now?

All good! I Did make two edits after mentioning you and it is line 314. I have also implemented the extra code from #520 to try and remove the thread messages and it appears to be working with both of your codes so far. So potentially this is something that @victornpb can implement in the next update for both.

What I would love is an option to "skip" thread messages, so far @ckcr4lyf 's code unarchives the threads if possible then removes the messages, but if it was possible to just have a clause that says "if the message is in a thread, skip it" rather than unarchiving it to delete the messages. Just having both options would be great :)

@CactusHamster
Copy link

CactusHamster commented Aug 1, 2023

@JayBoom the fix you describe is certainly possible. Discord's search API returns, along with the list of messages, threads that are referenced by them. I wrote a quick implementation of this fix.

// Don't do all this calculation for nothing! Only check for threads if threads are referenced.
if ("threads" in data && data.threads.length > 0) {
  // Find ID's of private threads.
  let privateThreads = data.threads.filter(thread => thread.thread_metadata.archived === true).map(thread => thread.id);
  // Filter messages in private threads out of the list of deletable messages.
  // If a message's channel id is in the list of archived threads, leave it alone!
  if (privateThreads.length > 0) messagesToDelete = messagesToDelete.filter(msg => !privateThreads.includes(msg.channel_id));
}

This code is untested; however I am quite confident it will work. My only worry is avoiding archived messages could be unexpected behavior from a script expected to delete everything.

edit: I did not implement a menu option. I could prolly do that quickly tho ^^

@theSoberSobber
Copy link

hey so I made a fork for anyone intersted
https://github.com/theSoberSobber/slash-command-fixed-undiscord/blob/master/fixed-total.js

it's not perfect and works by checking username, the changes are low quality otherwise i'd make a pr.

@false-fox
Copy link

Fixed in #629 :)

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

No branches or pull requests

5 participants