command to manually scan user list
This commit is contained in:
parent
b32b3fb4b5
commit
591ee34705
2 changed files with 59 additions and 0 deletions
57
src/bot/commands/botctl.ts
Normal file
57
src/bot/commands/botctl.ts
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
import { FindOneResult } from "monk";
|
||||||
|
import { client } from "../..";
|
||||||
|
import Command from "../../struct/Command";
|
||||||
|
import MessageCommandContext from "../../struct/MessageCommandContext";
|
||||||
|
import ServerConfig from "../../struct/ServerConfig";
|
||||||
|
import { scanServer } from "../modules/user_scan";
|
||||||
|
import { isBotManager, NO_MANAGER_MSG } from "../util";
|
||||||
|
|
||||||
|
let userscans: string[] = [];
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'botctl',
|
||||||
|
aliases: null,
|
||||||
|
description: 'Perform administrative actions',
|
||||||
|
run: async (message: MessageCommandContext, args: string[]) => {
|
||||||
|
if (!isBotManager(message.member!, message.serverContext)) return message.reply(NO_MANAGER_MSG);
|
||||||
|
|
||||||
|
let action = args.shift();
|
||||||
|
switch(action) {
|
||||||
|
case 'scan_userlist':
|
||||||
|
try {
|
||||||
|
let serverConf: FindOneResult<ServerConfig> = await client.db.get('servers').findOne({ id: message.serverContext._id });
|
||||||
|
|
||||||
|
if (!serverConf?.userScan?.enable) return message.reply(`User scanning is not enabled for this server.`);
|
||||||
|
if (userscans.includes(message.serverContext._id)) return message.reply(`There is already a scan running for this server.`);
|
||||||
|
userscans.push(message.serverContext._id);
|
||||||
|
|
||||||
|
let msg = await message.reply(`Fetching users...`);
|
||||||
|
|
||||||
|
let counter = 0;
|
||||||
|
|
||||||
|
let onUserScan = async () => {
|
||||||
|
counter++;
|
||||||
|
if (counter % 10 == 0) await msg?.edit({ content: `Fetching users... ${counter}` });
|
||||||
|
}
|
||||||
|
|
||||||
|
let onDone = async () => {
|
||||||
|
msg?.edit({ content: `All done! (${counter} users fetched)` });
|
||||||
|
userscans = userscans.filter(s => s != message.serverContext._id);
|
||||||
|
}
|
||||||
|
|
||||||
|
await scanServer(message.serverContext._id, onUserScan, onDone);
|
||||||
|
} catch(e) {
|
||||||
|
message.reply(`An error occurred: ${e}`);
|
||||||
|
userscans = userscans.filter(s => s != message.serverContext._id);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case undefined:
|
||||||
|
case '':
|
||||||
|
message.reply(`### Available subcommands\n`
|
||||||
|
+ `- \`scan_userlist\` - If user scanning is enabled, this will scan the entire user list.`);
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
message.reply(`Unknown option`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} as Command;
|
|
@ -200,3 +200,5 @@ new Promise((res: (value: void) => void) => client.user ? res() : client.once('r
|
||||||
} catch(e) { console.error(e) }
|
} catch(e) { console.error(e) }
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export { scanServer };
|
||||||
|
|
Loading…
Reference in a new issue