-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
48 lines (40 loc) · 1.3 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const utils = require.main.require('@screeps/backend/lib/utils.js')
const MOD_NAME = '[screepsmod-speedrun]'
module.exports = config => {
if (config.engine) {
config.engine.on('init', async type => {
if (type === 'main') {
await removeBots(config)
}
})
}
if (config.cronjobs) {
console.log(`${MOD_NAME} disabling strongholds and invaders`)
delete config.cronjobs.genInvaders
delete config.cronjobs.genStrongholds
delete config.cronjobs.expandStrongholds
}
}
async function removeBots(config) {
const { db, env } = config.common.storage
if (!db) {
console.log(`${MOD_NAME} no database found, skipping`)
return
}
if (!db.users) {
console.log(`${MOD_NAME} no users collection found, skipping`)
return
}
// Target NPC bots for removal
const bots = await db.users.find({ bot: { $exists: true } })
for (const { _id, username } of bots) {
console.log(`${MOD_NAME} removing bot "${username}"`)
// Respawn the bot user (removes creeps, structures, construction sites, etc.)
await utils.respawnUser(_id)
// Remove the bot user from the database
await db.users.removeWhere({ _id })
await db['users.code'].removeWhere({ user: _id })
await env.del(env.keys.MEMORY + _id)
await env.del(env.keys.MEMORY_SEGMENTS + _id)
}
}