Role command #26

Closed
Hector wants to merge 0 commits from master into master
Hector commented 2020-07-06 06:27:49 -04:00 (Migrated from gitlab.libraryofcode.org)

MERGE REQUEST

Description:

New command: role as requested in #6. For some reasons the command isn't loading on ready, and the pipeline failed but the command itself should work.

Status:

  • This MR introduces new features
  • This MR fixes a bug/patches something very minor
  • This MR implies a major API change
  • This MR improves code performance/style/usage without any API changes
  • This MR is ready to be merged
# MERGE REQUEST ## Description: New command: role as requested in #6. For some reasons the command isn't loading on ready, and the pipeline failed but the command itself should work. ## Status: * [x] This MR introduces new features * [ ] This MR fixes a bug/patches something very minor * [ ] This MR implies a major API change * [ ] This MR improves code performance/style/usage without any API changes * [ ] This MR is ready to be merged
matthew commented 2020-07-07 04:48:22 -04:00 (Migrated from gitlab.libraryofcode.org)

You need to add the command to index.ts for it to be properly loaded.

You need to add the command to index.ts for it to be properly loaded.
matthew commented 2020-07-07 04:48:50 -04:00 (Migrated from gitlab.libraryofcode.org)

assigned to @matthew

assigned to @matthew
Hector commented 2020-07-07 07:40:37 -04:00 (Migrated from gitlab.libraryofcode.org)
added 1 commit <ul><li>a475df22 - fix</li></ul> [Compare with previous version](/engineering/communityrelations/-/merge_requests/13/diffs?diff_id=378&start_sha=c31c99f54e470a8306179c138addb47ad3c33896)
matthew commented 2020-07-08 18:01:20 -04:00 (Migrated from gitlab.libraryofcode.org)

@Khaazz Requesting review.

@Khaazz Requesting review.
matthew commented 2020-07-08 18:01:32 -04:00 (Migrated from gitlab.libraryofcode.org)

changed milestone to %1

changed milestone to %1
Khaazz commented 2020-07-09 06:01:15 -04:00 (Migrated from gitlab.libraryofcode.org)

That implies that if stop is true at ANY point, you'll end the function there.
However since you used a forEach, you have to use a boolean. You end up iterating over all elements and do the logic for each element.
This is heavy and very much waste of ressource.

Using for of loop would solve this problem easily. Using early return in the for loop would do the job.
However make sure you correctly use return or break, in order to not make the code less readable. I usually have returns at the beginning of the loop (early return). The only important thing is just that you should see very clearly what is going on when reading the function, not having to wonder why there is a random return somewhere.

That implies that if stop is true at ANY point, you'll end the function there. However since you used a forEach, you have to use a boolean. You end up iterating over all elements and do the logic for each element. This is heavy and very much waste of ressource. Using for of loop would solve this problem easily. Using early return in the for loop would do the job. However make sure you correctly use `return` or `break`, in order to not make the code less readable. I usually have returns at the beginning of the loop (early return). The only important thing is just that you should see very clearly what is going on when reading the function, not having to wonder why there is a random return somewhere.
Khaazz commented 2020-07-09 06:05:17 -04:00 (Migrated from gitlab.libraryofcode.org)

you can't await a forEach. although it's literally useless in this case since the cb function is not async.

For that matters I would also not use forEach when you have a big chunk of code to run inside the callback function for readability. I would only use forEach when you have a very simple action to perform on each element.
forEach is also slower in general, especially in big arrays.

you can't await a forEach. although it's literally useless in this case since the cb function is not async. For that matters I would also not use forEach when you have a big chunk of code to run inside the callback function for readability. I would only use forEach when you have a very simple action to perform on each element. forEach is also slower in general, especially in big arrays.
Khaazz commented 2020-07-09 06:05:17 -04:00 (Migrated from gitlab.libraryofcode.org)

I already commented in the global try / catch but it should be wrapping the run function in the command class instead.
Logic for general things like argument check (that happens in every commands) that sends back the help command should also probably be moved in the Command class logic.

I already commented in the global try / catch but it should be wrapping the run function in the command class instead. Logic for general things like argument check (that happens in every commands) that sends back the help command should also probably be moved in the Command class logic.
Khaazz commented 2020-07-09 06:05:18 -04:00 (Migrated from gitlab.libraryofcode.org)

Although, if you actually want to send a message for each error, then stop, it will behave as expected. But this is imho not such a good idea as it can quickly become spammy.
Additionally, if you really want this behaviour, you should still add / remove the roles that went through in this case.

I still think it's best to go with what I said above. If you want an error message, you can just send one for the case that went wrong. If there are any more errors, they will be detected on the next iteration of the command and a message will be sent accordingly to the user

On a side note, I would personally just do nothing (not try to add / remove) but not errors if the user already has the role that it tries to add / has not the role it tries to remove.
I would only error in case of bad role

Although, if you actually want to send a message for each error, then stop, it will behave as expected. But this is imho not such a good idea as it can quickly become spammy. Additionally, if you really want this behaviour, you should still add / remove the roles that went through in this case. I still think it's best to go with what I said above. If you want an error message, you can just send one for the case that went wrong. If there are any more errors, they will be detected on the next iteration of the command and a message will be sent accordingly to the user On a side note, I would personally just do nothing (not try to add / remove) but not errors if the user already has the role that it tries to add / has not the role it tries to remove. I would only error in case of bad role
Khaazz commented 2020-07-09 06:05:18 -04:00 (Migrated from gitlab.libraryofcode.org)

I'd prefer a way to have the action and the actual string separated directly.
So you don't have to slice again after. I think it would be more clear.
https://stackoverflow.com/questions/20817618/is-there-a-splice-method-for-strings

I'd prefer a way to have the action and the actual string separated directly. So you don't have to slice again after. I think it would be more clear. <https://stackoverflow.com/questions/20817618/is-there-a-splice-method-for-strings>
Khaazz commented 2020-07-09 06:05:18 -04:00 (Migrated from gitlab.libraryofcode.org)

same as above regarding forEach. Unless this has changed and i'm not aware of, this won't await nothing.

same as above regarding forEach. Unless this has changed and i'm not aware of, this won't await nothing.
Hector commented 2020-08-25 09:29:19 -04:00 (Migrated from gitlab.libraryofcode.org)

changed this line in version 3 of the diff

changed this line in [version 3 of the diff](/engineering/communityrelations/-/merge_requests/13/diffs?diff_id=386&start_sha=a475df226fd676592e763b9e6e59aeb10e49aac5#947ac3dcebdaa407677127c9e76bacf4827405f1_24_24)
Hector commented 2020-08-25 09:29:21 -04:00 (Migrated from gitlab.libraryofcode.org)

changed this line in version 3 of the diff

changed this line in [version 3 of the diff](/engineering/communityrelations/-/merge_requests/13/diffs?diff_id=386&start_sha=a475df226fd676592e763b9e6e59aeb10e49aac5#947ac3dcebdaa407677127c9e76bacf4827405f1_62_62)
Hector commented 2020-08-25 09:29:24 -04:00 (Migrated from gitlab.libraryofcode.org)

added 1 commit

Compare with previous version

added 1 commit <ul><li>dee8243a - use for of and remove awaits</li></ul> [Compare with previous version](/engineering/communityrelations/-/merge_requests/13/diffs?diff_id=386&start_sha=a475df226fd676592e763b9e6e59aeb10e49aac5)
matthew commented 2020-09-20 14:01:52 -04:00 (Migrated from gitlab.libraryofcode.org)

@Hector Was this resolved?

@Hector Was this resolved?
matthew commented 2020-09-20 14:02:07 -04:00 (Migrated from gitlab.libraryofcode.org)

@Hector Was this resolved?

@Hector Was this resolved?
matthew commented 2021-03-06 18:34:18 -05:00 (Migrated from gitlab.libraryofcode.org)

Merged in 6d0499d4

Merged in 6d0499d4

Pull request closed

Sign in to join this conversation.
No reviewers
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: engineering/community-relations#26
There is no content yet.