Skip to content

Commit e4e8445

Browse files
author
sherlocksometimes
committed
feat: add config to set scanner cooldown by role
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.
1 parent 8be85b6 commit e4e8445

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

packages/types/lib/server.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export interface Permissions {
174174
scanner: string[]
175175
areaRestrictions: string[]
176176
webhooks: string[]
177+
scannerCooldowns: string[]
177178
}
178179

179180
export interface Waypoint {

server/src/configs/default.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@
615615
"pokemon": false,
616616
"gmf": true,
617617
"scanNextInstance": "scanNext",
618+
"discordRoleCooldown": [],
618619
"scanNextDevice": "Device01",
619620
"scanNextSleeptime": 5,
620621
"userCooldownSeconds": 0,
@@ -634,6 +635,7 @@
634635
"gmf": false,
635636
"scanZoneMaxSize": 10,
636637
"userCooldownSeconds": 0,
638+
"discordRoleCooldown": [],
637639
"advancedScanZoneOptions": false,
638640
"scanZoneRadius": {
639641
"pokemon": 70,
@@ -1025,4 +1027,4 @@
10251027
"tracesSampleRate": 0.1
10261028
}
10271029
}
1028-
}
1030+
}

server/src/graphql/resolvers.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ const resolvers = {
374374
const scanner = config.getSafe('scanner')
375375

376376
if (perms.scanner?.includes(mode) && scanner[mode].enabled) {
377+
const cooldownMap = new Map(perms.cooldownOverride)
377378
return mode === 'scanZone'
378379
? {
379380
scannerType: scanner.backendConfig.platform,
@@ -384,15 +385,19 @@ const resolvers = {
384385
gymRadius: scanner.scanZone.scanZoneRadius.gym,
385386
spacing: scanner.scanZone.scanZoneSpacing,
386387
maxSize: scanner.scanZone.scanZoneMaxSize,
387-
cooldown: scanner.scanZone.userCooldownSeconds,
388+
cooldown: cooldownMap.has(mode)
389+
? cooldownMap.get(mode)
390+
: scanner.scanZone.userCooldownSeconds,
388391
refreshQueue: scanner.backendConfig.queueRefreshInterval,
389392
enabled: scanner[mode].enabled,
390393
}
391394
: {
392395
scannerType: scanner.backendConfig.platform,
393396
showScanCount: scanner.scanNext.showScanCount,
394397
showScanQueue: scanner.scanNext.showScanQueue,
395-
cooldown: scanner.scanNext.userCooldownSeconds,
398+
cooldown: cooldownMap.has(mode)
399+
? cooldownMap.get(mode)
400+
: scanner.scanZone.userCooldownSeconds,
396401
refreshQueue: scanner.backendConfig.queueRefreshInterval,
397402
enabled: scanner[mode].enabled,
398403
}

server/src/services/DiscordClient.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class DiscordClient {
129129
webhooks: new Set(),
130130
scanner: new Set(),
131131
blockedGuildNames: new Set(),
132+
cooldownOverride: new Map(),
132133
}
133134
const scanner = config.getSafe('scanner')
134135
try {
@@ -190,6 +191,24 @@ class DiscordClient {
190191
scannerPerms(userRoles, 'discordRoles', trialActive).forEach(
191192
(x) => permSets.scanner.add(x),
192193
)
194+
195+
Object.keys(scanner).forEach((mode) => {
196+
if (
197+
scanner[mode]?.enabled &&
198+
scanner[mode].discordRoleCooldown.length
199+
) {
200+
const roleMap = scanner[mode].discordRoleCooldown.sort(
201+
(a, b) => a[1] - b[1],
202+
)
203+
204+
for (let i = 0; i < roleMap.length; i += 1) {
205+
if (userRoles.includes(roleMap[i][0])) {
206+
permSets.cooldownOverride.set(mode, roleMap[i][1])
207+
break
208+
}
209+
}
210+
}
211+
})
193212
}
194213
}),
195214
)

server/src/services/config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,12 @@ if (Array.isArray(config.webhooks)) {
340340
}
341341
Object.keys(config.scanner || {}).forEach((key) => {
342342
config.scanner[key] = replaceBothAliases(config.scanner[key] || {})
343+
const roleMap = config.scanner[key].discordRoleCooldown
344+
if (roleMap) {
345+
roleMap.forEach((pair) => {
346+
pair[0] = replaceAliases(pair[0])
347+
})
348+
}
343349
})
344350

345351
if (

0 commit comments

Comments
 (0)