Découpage en module

This commit is contained in:
2020-10-17 19:32:32 +02:00
parent 14fdcc39c2
commit 47ea30b234
12 changed files with 3197 additions and 200 deletions

32
utils/utils.js Normal file
View File

@@ -0,0 +1,32 @@
import { TimeoutError } from 'working-rcon';
export default {
parseCvar(value) {
const cvar = this.getLine(value);
const cvarRegex = RegExp('^\\"(.*)\\" = \\"([^\\"]*)\\"(.*)$');
const res = cvarRegex.exec(cvar);
return {
name: res[1],
value: res[2],
extra: res[3],
};
},
getLine(value, line = 1) {
return value.split('\n', line)[line - 1];
},
async rconCommand(client, command) {
try {
return client.command(command);
} catch (err) {
if (err instanceof TimeoutError) {
console.error('request timed out');
} else {
throw err;
}
}
return null;
},
isValidResponse(response) {
return !response.includes('Unknown');
},
};