Brayzure / lessis-moe

Personal Website
0 stars 0 forks source link

"purge <number> [user]" does not work properly #1

Open DManstrator opened 7 years ago

DManstrator commented 7 years ago

Hello,

a friend of mine is using your Discord-Bot "Utilibot" and I found a little bug in the purge command.

Your description:

!?purge <number of messages> <user mention (optional)>
    Deletes the most recent number messages.
    If a user is mentioned, it will only delete their messages.

It will always delete the given number of messages, but if a User was mentioned, it will still try just to delete the given number of messages, not depending on the author of the message. It should delete the number of messages of a given user instead in my opinion.

For example this History to clarify my point: Person A: dsdas Person A: sdasd Person A: dasdas Person B: dsadsad Person B: adsdasdsa

-> !?purge 2 @ PersonA -> No messages will be deleted because the last 2 messages were not from Person A.

To solve that, you could create a variable to count the deletions and continue until the given amount was reached. It could be something like that in Java (e. g. JDA) (not tested).

int i = 0;  // variable to access list
int p = 0;  // successful deletions
while(p < purge_number)  {
    try  {
        Message msg = list.get(i++);  // I guess you save all Messages in a List of Messages
        if(msg.getAuthor().getAsMention().equals(purge_user)  {
            msg.delete().queue();
            p++;
        }
    }  catch(ListIndexOutOfBouceException e)  {
        // not all of the messages could be deleted
    }
}

Yours sincerely,

DMan

Brayzure commented 7 years ago

Hey, thanks for posting about this.

While I would like to first point out that this is not the proper repository to post the issue on, I'll give a full response anyway.

This behavior is, for the moment, intentional. It has been brought to my attention before, and I need to figure out a good way to implement it before I can change it. The main problem is addressing the case where the user mentioned does not have enough valid messages to delete. Where should it decide to stop looking? After 100 messages? 1,000? Should it stop searching after it reaches messages that are an hour old? A day? Two weeks? I've not yet figured out a good way to tackle that case, but it's something I've been thinking about.

DManstrator commented 7 years ago

Sorry, I did not know where to create the issue instead.

I don't know how you organize the whole thing but you could go through all messages and when you reached the last one, just stop it. Or is this way too much to iterate through?

Like in my example, try always to access another message and when you are not able too, catch that with an exception and break out of the loop. That would be my way but as I mentioned, I don't know how you organize the messages.

Good luck anyways. ;)

Yours sincerely,

DMan