-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
feat: add config to set scanner cooldown by role #1014
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution, I'm sure many are interested in this! I've been contemplating since you posted in the Discord for how we want to approach this in a scalable way that makes sense, but I keep ending up with solutions that add a lot of complications to this PR. So I'm going to try and keep this simple-ish for now and I may revise it in the future.
- Let's change the new config keys to just
rules
, as it will be used for Discord and Telegram. And I will use this more in the future as well... - For the values themselves, we should switch to objects instead of a tuple, to be more consistent with the rest of the config / easier to read. Something like:
{
"rules": [
{ "role": "12415", "cooldown": 5 },
{ "role": "mod", "cooldown": 1 }
]
}
- In
server/src/services/config.js
, after replacing the alias roles with their ID counterparts, lets create a new map in each of the scanner modes. Something like:
config.scanner.scanNext.rulesObj = Object.fromEntries(config.scanner.scanNext.rules.map((rule) => [rule.role, rule.cooldown]))
- Same for ScanZone
- In
server/src/services/DiscordClient.js
, remove the code you have now. Add:
// put this below the scanner declaration
perms.scannerCooldowns = {}
// Replace the code where the `scannerPerms` function is being called with
scannerPerms(userRoles, 'discordRoles', trialActive).forEach(
(x) => {
permSets.scanner.add(x)
perms.scannerCooldowns[x] = scanner[x].rules.reduce(
(acc, rule) => {
if (rule.cooldown < acc) {
return rule.cooldown
}
return acc
},
scanner[x].userCooldownSeconds,
)
},
)
- Add this above code to
server/src/services/TelegramClient.js
as well, with the appropriate adjustments for TG - In
server/src/graphql/resolves.js
:- For the scannerConfig resolver, change these:
cooldown: perms?.scannerCooldowns?.[mode] || scanner.scanZone.userCooldownSeconds
cooldown: perms?.scannerCooldowns?.[mode] || scanner.scanNext.userCooldownSeconds
- You also need to adjust the
scanner
resolver, this one seems to have somehow escaped my attempt to have them in alphabetical order, so it's last in theQuery
object... Add something like:
const cooldownSeconds = perms?.scannerCooldowns?.[category] || config.getSafe(`scanner.${category}.userCooldownSeconds`)
- Then adjust the cooldown variable calculation to use this new value
- I would also like if you could adjust the
Permissions
type found inpackages/types/lib
so it has the new property.
I know you mentioned on Discord that JS isn't your preferred language so let me know if you want me to jump in and help. I also didn't test these suggested changes so if something seems off, feel free to reach out. Thanks!
e4e8445
to
47cbbdb
Compare
Didn't add the telegram part, I could add it but it would be untested as I don't use telegram, I can look at it tommorow if so, but figured id post the tested code and do that seperatly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the adjustments, left some suggested changes on a few small things.
As far as TG, if you just translate the code over to the TelegramClient then I will make an attempt to test it later this week. TG is quite a pain in the ass to test if you don't have already have it set up so I wouldn't ask anyone to go through that 😂
Allow users to set specific cooldown by roles
Switched to nullish ?? operator as 0 == false and would set default value when a 0 cooldown role was set. |
Hey, I tried to use this PR by updating files manually but after all I could manage cooldown to disappear but in fact when I try to request a new scan within original cooldown timerange I have an error untill that 'virtual' (or actually hidden) original cooldown ends. Any chance this could be updated to latest version? Thanks |
Did a merge with latest, don't have time to test it today, if you want you
can try it out, I'll try to get around to testing it tomorrow.
…On Sat, Oct 26, 2024, 2:43 PM kamieniarz ***@***.***> wrote:
Hey, I tried to use this PR by updating files manually but after all I
could manage cooldown to disappear but in fact when I try to request a new
scan within original cooldown timerange I have an error untill that
'virtual' (or actually hidden) original cooldown ends. Any chance this
could be updated to latest version? Thanks
—
Reply to this email directly, view it on GitHub
<#1014 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACJIJPWLF3PWVGTZEELXXH3Z5PWF7AVCNFSM6AAAAABH5BDGEWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMZZG4YTKOJVHA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
That's the same what I manually did in my code so the effect is the same as what I explained above |
what does your config look like? seems to be working for me. a rule needs
to be added to scanZone/scanNext
"scanZone": {
"userCooldownSeconds": 30, // default cooldown
"rules": [{ "role": "Supporter", "cooldown": 20 },
{ "role": "SuperRole", "cooldown": 10 }],
…On Sun, Oct 27, 2024 at 3:29 AM kamieniarz ***@***.***> wrote:
That's the same what I manually did in my code so the effect is the same
as what I explained above
—
Reply to this email directly, view it on GitHub
<#1014 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACJIJPV4OARBSGGOTGWMTC3Z5SI6JAVCNFSM6AAAAABH5BDGEWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMZZHEYDMMZZGM>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
just realized I never updated the original comment with the format change,
updated. Guess i need to work on adding telegram support and hopefully get
this merged in.
…On Sun, Oct 27, 2024 at 12:52 PM Robb Pell ***@***.***> wrote:
what does your config look like? seems to be working for me. a rule needs
to be added to scanZone/scanNext
"scanZone": {
"userCooldownSeconds": 30, // default cooldown
"rules": [{ "role": "Supporter", "cooldown": 20 },
{ "role": "SuperRole", "cooldown": 10 }],
On Sun, Oct 27, 2024 at 3:29 AM kamieniarz ***@***.***>
wrote:
> That's the same what I manually did in my code so the effect is the same
> as what I explained above
>
> —
> Reply to this email directly, view it on GitHub
> <#1014 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ACJIJPV4OARBSGGOTGWMTC3Z5SI6JAVCNFSM6AAAAABH5BDGEWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMZZHEYDMMZZGM>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
|
Here's examply
My map shows no cooldown but when I scan and try another scan (right after first one) I get an error |
I see, I am also seeing the generic "scan_error": "There has been an
error while processing the scan request...",
but I'm not seeing scan_error called in the code anywhere, no error is
printed to reactMap log, the chrome console, or dragonight.
So not even sure what the error is, I'll try to look around and see if I
can narrow down the error to find what is causing it.
…On Sun, Oct 27, 2024 at 1:36 PM kamieniarz ***@***.***> wrote:
Here's examply
"userCooldownSeconds": 20,
"rules": [{ "role": "ADMIN", "cooldown": 1 }],
My map shows no cooldown but when I scan and try another scan (right after
first one) I get an error
—
Reply to this email directly, view it on GitHub
<#1014 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACJIJPWHOBBMXUQNWGXSPNLZ5UQCRAVCNFSM6AAAAABH5BDGEWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINBQGEZTANZVG4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Add discordRoleCooldown to scanNext and scanZone config to set cooldown per user role
example config (scanZone accepts the same format)
"scanNext": {
...
// Discord roles that will be allowed to use scanNext
"discordRoles": ["Supporter","Scanner", "Mod"],
// Default cooldown if no role specific cooldown
"userCooldownSeconds": 60,
//List of role/cooldown pair shortest matching time will apply
"rules": [{ "role": "Supporter", "cooldown": 30 },
{ "role": "Mod", "cooldown": 0 }],
...
}
Expected outcome:
Supporter: 30 second cooldown
Mod: 0 second cooldown
Scanner: will get the default 60 second cooldown.
Supporter & Mod role: the lower 0 second cooldown would apply.