[feature] disable and enable command

This commit is contained in:
方而静 2021-03-26 18:41:54 +08:00
parent 98aa32db54
commit ba89b0c216
No known key found for this signature in database
GPG Key ID: C4F2853BC3103681

View File

@ -33,6 +33,8 @@ export function send_message({ msg, sender }: { msg: string; sender: string; },
});
}
let disabled_commands: Map<string, boolean> = new Map();
export function run_command(cmd_raw: string, uid: string, users: Map<string, User>, io: SocketServer, silent: boolean = false) {
const cmd = cmd_raw.replace(/(^\s*)|(\s*$)/, '');
@ -173,6 +175,18 @@ export function run_command(cmd_raw: string, uid: string, users: Map<string, Use
command_reply(JSON.stringify(checked_user));
});
admin_command_map.set('enable', () => {
const target_command = cmd_set[1];
disabled_commands.delete(target_command);
command_reply('Enabled.');
});
admin_command_map.set('disable', () => {
const target_command = cmd_set[1];
disabled_commands.set(target_command, true);
command_reply('Disabled.');
});
command_map.set('anon', () => {
send_message({ msg: msg, sender: 'Anonymous User'}, io, socket);
});
@ -206,6 +220,11 @@ export function run_command(cmd_raw: string, uid: string, users: Map<string, Use
const [prefix, executor] = val;
const command_prefix = '/' + prefix;
if (cmd.startsWith(command_prefix)) {
if (!user.is_administrator && disabled_commands.get(prefix)) {
command_reply(`Command "${command_prefix}" has been disabled.`);
return;
}
executor(command_prefix);
return;
}