mirror of
https://github.com/gamedig/node-gamedig.git
synced 2024-11-16 16:58:32 +01:00
3a17184862
* Added token paramter * Added Farming Simulator 2022 * Fixed order * Undo debug line * Update Farming Simulator 22 support (By @Vito0912 #531) * Added Farming Simulator 2019 support * Revert change * Update release year for Farming Simulator 2019 * Update mods array to raw.mods in farmingsimulator.js * Update Farming Simulator naming in GAMES_LIST.md * Missed some names * Add server version to state.raw and eslint
63 lines
1.4 KiB
JavaScript
63 lines
1.4 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
import * as process from 'node:process'
|
|
|
|
import Minimist from 'minimist'
|
|
import { GameDig } from './../lib/index.js'
|
|
|
|
const argv = Minimist(process.argv.slice(2), {
|
|
boolean: ['pretty', 'debug', 'givenPortOnly', 'requestRules', 'requestRulesRequired', 'requestPlayersRequired', 'stripColors', 'portCache', 'noBreadthOrder', 'checkOldIDs'],
|
|
string: ['guildId', 'listenUdpPort', 'ipFamily', 'token'],
|
|
default: {
|
|
stripColors: true,
|
|
portCache: true
|
|
}
|
|
})
|
|
|
|
const options = {}
|
|
for (const key of Object.keys(argv)) {
|
|
const value = argv[key]
|
|
|
|
if (key === '_' || key.charAt(0) === '$') { continue }
|
|
|
|
options[key] = value
|
|
}
|
|
|
|
// Separate host and port
|
|
if (argv._.length >= 1) {
|
|
const target = argv._[0]
|
|
const split = target.split(':')
|
|
options.host = split[0]
|
|
if (split.length > 1) {
|
|
options.port = split[1]
|
|
}
|
|
}
|
|
|
|
const { debug, pretty } = options
|
|
|
|
const printOnPretty = (object) => {
|
|
if (!!pretty || debug) {
|
|
console.log(JSON.stringify(object, null, ' '))
|
|
} else {
|
|
console.log(JSON.stringify(object))
|
|
}
|
|
}
|
|
|
|
const gamedig = new GameDig(options)
|
|
gamedig.query(options)
|
|
.then(printOnPretty)
|
|
.catch((error) => {
|
|
if (debug) {
|
|
if (error instanceof Error) {
|
|
console.log(error.stack)
|
|
} else {
|
|
console.log(error)
|
|
}
|
|
} else {
|
|
if (error instanceof Error) {
|
|
error = error.message
|
|
}
|
|
|
|
printOnPretty({ error })
|
|
}
|
|
})
|