Skip to content

Commit

Permalink
feat: add config to set scanner cooldown by role
Browse files Browse the repository at this point in the history
example config setup (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
     "discordRoleCooldown":[["Supporter",30],["Mod",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.
  • Loading branch information
sherlocksometimes committed May 17, 2024
1 parent 8be85b6 commit 89e952e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
4 changes: 3 additions & 1 deletion server/src/configs/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
"pokemon": false,
"gmf": true,
"scanNextInstance": "scanNext",
"discordRoleCooldown": [],
"scanNextDevice": "Device01",
"scanNextSleeptime": 5,
"userCooldownSeconds": 0,
Expand All @@ -634,6 +635,7 @@
"gmf": false,
"scanZoneMaxSize": 10,
"userCooldownSeconds": 0,
"discordRoleCooldown": [],
"advancedScanZoneOptions": false,
"scanZoneRadius": {
"pokemon": 70,
Expand Down Expand Up @@ -1025,4 +1027,4 @@
"tracesSampleRate": 0.1
}
}
}
}
9 changes: 7 additions & 2 deletions server/src/graphql/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ const resolvers = {
const scanner = config.getSafe('scanner')

if (perms.scanner?.includes(mode) && scanner[mode].enabled) {
const cooldownMap = new Map(perms.cooldownOverride)
return mode === 'scanZone'
? {
scannerType: scanner.backendConfig.platform,
Expand All @@ -384,15 +385,19 @@ const resolvers = {
gymRadius: scanner.scanZone.scanZoneRadius.gym,
spacing: scanner.scanZone.scanZoneSpacing,
maxSize: scanner.scanZone.scanZoneMaxSize,
cooldown: scanner.scanZone.userCooldownSeconds,
cooldown: cooldownMap.has(mode)
? cooldownMap.get(mode)
: scanner.scanZone.userCooldownSeconds,
refreshQueue: scanner.backendConfig.queueRefreshInterval,
enabled: scanner[mode].enabled,
}
: {
scannerType: scanner.backendConfig.platform,
showScanCount: scanner.scanNext.showScanCount,
showScanQueue: scanner.scanNext.showScanQueue,
cooldown: scanner.scanNext.userCooldownSeconds,
cooldown: cooldownMap.has(mode)
? cooldownMap.get(mode)
: scanner.scanZone.userCooldownSeconds,
refreshQueue: scanner.backendConfig.queueRefreshInterval,
enabled: scanner[mode].enabled,
}
Expand Down
19 changes: 19 additions & 0 deletions server/src/services/DiscordClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class DiscordClient {
webhooks: new Set(),
scanner: new Set(),
blockedGuildNames: new Set(),
cooldownOverride: new Map(),
}
const scanner = config.getSafe('scanner')
try {
Expand Down Expand Up @@ -190,6 +191,24 @@ class DiscordClient {
scannerPerms(userRoles, 'discordRoles', trialActive).forEach(
(x) => permSets.scanner.add(x),
)

Object.keys(scanner).forEach((mode) => {
if (
scanner[mode]?.enabled &&
scanner[mode].discordRoleCooldown.length
) {
const roleMap = scanner[mode].discordRoleCooldown.sort(
(a, b) => a[1] - b[1],
)

for (let i = 0; i < roleMap.length; i += 1) {
if (userRoles.includes(roleMap[i][0])) {
permSets.cooldownOverride.set(mode, roleMap[i][1])
break
}
}
}
})
}
}),
)
Expand Down
6 changes: 6 additions & 0 deletions server/src/services/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,12 @@ if (Array.isArray(config.webhooks)) {
}
Object.keys(config.scanner || {}).forEach((key) => {
config.scanner[key] = replaceBothAliases(config.scanner[key] || {})
const roleMap = config.scanner[key].discordRoleCooldown
if (roleMap) {
roleMap.forEach((pair) => {
pair[0] = replaceAliases(pair[0])
})
}
})

if (
Expand Down

0 comments on commit 89e952e

Please sign in to comment.