Skip to content

Commit cb45bca

Browse files
authored
Merge pull request #156 from oof2win2/feature/better-rcon
2 parents e8fe07b + 73fdcb3 commit cb45bca

File tree

11 files changed

+395
-414
lines changed

11 files changed

+395
-414
lines changed

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"chalk": "^4.1.0",
3131
"colors-generator": "^0.3.4",
3232
"common-tags": "^1.8.0",
33+
"dayjs": "^1.11.6",
3334
"discord-giveaways": "^4.4.3",
3435
"discord.js": "^13.7.0",
3536
"ejs": "^3.1.6",

src/base/Comfy.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,19 @@ class Comfy extends Client {
173173
);
174174
}
175175
}
176+
177+
async sendToErrorChannel(message: ArgumentTypes<TextChannel["send"]>) {
178+
if (this.config.errorchannel) {
179+
const guild = this.guilds.cache.forEach((guild) =>
180+
guild.channels.cache.forEach(
181+
(channel) =>
182+
channel.id === this.config.errorchannel &&
183+
channel.isText() &&
184+
channel.send(message)
185+
)
186+
);
187+
}
188+
}
176189
}
177190

178191
export default Comfy;

src/base/GrafanaHandler.ts

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,16 @@ class GrafanaHandler {
183183
* @param {*} server
184184
*/
185185
handleStatistics(statistics, server) {
186-
if (!statistics || typeof statistics !== "string") return
186+
if (!statistics || typeof statistics !== "string") return;
187187
const json = JSON.parse(statistics.split("\n")[0]);
188188
const otherStats = json[Object.keys(json)[0]].other;
189-
190-
playercountGauge.set(
191-
{ server: server.name },
192-
Array.isArray(otherStats.online_players) ? otherStats.online_players.length : 0
193-
)
189+
190+
playercountGauge.set(
191+
{ server: server.name },
192+
Array.isArray(otherStats.online_players)
193+
? otherStats.online_players.length
194+
: 0
195+
);
194196
Object.keys(otherStats.mods).forEach((modname) =>
195197
modGauge.set(
196198
{
@@ -248,53 +250,53 @@ class GrafanaHandler {
248250

249251
if (production) {
250252
Object.keys(production.item_input).forEach((key) =>
251-
itemProductionInput.set(
252-
{ server: server.name, force: forcename, name: key },
253-
production.item_input[key].count
254-
)
255-
);
256-
Object.keys(production.item_output).forEach((key) =>
257-
itemProductionOutput.set(
258-
{ server: server.name, force: forcename, name: key },
259-
production.item_output[key].count
260-
)
261-
);
262-
Object.keys(production.fluid_input).forEach((key) =>
263-
fluidProductionInput.set(
264-
{ server: server.name, force: forcename, name: key },
265-
production.fluid_input[key].count
266-
)
267-
);
268-
Object.keys(production.fluid_output).forEach((key) =>
269-
fluidProductionOutput.set(
270-
{ server: server.name, force: forcename, name: key },
271-
production.fluid_output[key].count
272-
)
273-
);
274-
Object.keys(production.kill_input).forEach((key) =>
275-
killProductionInput.set(
276-
{ server: server.name, force: forcename, name: key },
277-
production.kill_input[key].count
278-
)
279-
);
280-
Object.keys(production.kill_output).forEach((key) =>
281-
killProductionOutput.set(
282-
{ server: server.name, force: forcename, name: key },
283-
production.kill_output[key].count
284-
)
285-
);
286-
Object.keys(production.build_input).forEach((key) =>
287-
buildProductionInput.set(
288-
{ server: server.name, force: forcename, name: key },
289-
production.build_input[key].count
290-
)
291-
);
292-
Object.keys(production.build_output).forEach((key) =>
293-
buildProductionOutput.set(
294-
{ server: server.name, force: forcename, name: key },
295-
production.build_output[key].count
296-
)
297-
);
253+
itemProductionInput.set(
254+
{ server: server.name, force: forcename, name: key },
255+
production.item_input[key].count
256+
)
257+
);
258+
Object.keys(production.item_output).forEach((key) =>
259+
itemProductionOutput.set(
260+
{ server: server.name, force: forcename, name: key },
261+
production.item_output[key].count
262+
)
263+
);
264+
Object.keys(production.fluid_input).forEach((key) =>
265+
fluidProductionInput.set(
266+
{ server: server.name, force: forcename, name: key },
267+
production.fluid_input[key].count
268+
)
269+
);
270+
Object.keys(production.fluid_output).forEach((key) =>
271+
fluidProductionOutput.set(
272+
{ server: server.name, force: forcename, name: key },
273+
production.fluid_output[key].count
274+
)
275+
);
276+
Object.keys(production.kill_input).forEach((key) =>
277+
killProductionInput.set(
278+
{ server: server.name, force: forcename, name: key },
279+
production.kill_input[key].count
280+
)
281+
);
282+
Object.keys(production.kill_output).forEach((key) =>
283+
killProductionOutput.set(
284+
{ server: server.name, force: forcename, name: key },
285+
production.kill_output[key].count
286+
)
287+
);
288+
Object.keys(production.build_input).forEach((key) =>
289+
buildProductionInput.set(
290+
{ server: server.name, force: forcename, name: key },
291+
production.build_input[key].count
292+
)
293+
);
294+
Object.keys(production.build_output).forEach((key) =>
295+
buildProductionOutput.set(
296+
{ server: server.name, force: forcename, name: key },
297+
production.build_output[key].count
298+
)
299+
);
298300
}
299301

300302
if (robots) {
@@ -360,7 +362,7 @@ class GrafanaHandler {
360362
"/collectdata rcon",
361363
server.discordid
362364
);
363-
this.handleStatistics(data.resp, server);
365+
if (data) this.handleStatistics(data.resp, server);
364366
});
365367
}
366368
destroy() {

src/commands/Factorio/onlineplayers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const OnlinePlayers: Command<Message> = {
4343
const withoutScenarioOutput = await Promise.all(withoutScenarioOutputProm);
4444

4545
scenarioOutput.forEach((response) => {
46-
if (!response.resp || typeof response.resp !== "string")
46+
if (!response.resp)
4747
return embed.addField(
4848
response.server.discordname,
4949
"Server is unreachable"

src/commands/Factorio/statss.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ const StatsS: Command<Message> = {
5555
// );
5656
let evolution = await rcon
5757
.rconCommand("/evolution", serverid)
58-
.then((r) => r.resp);
59-
let time = await rcon.rconCommand("/time", serverid).then((r) => r.resp);
58+
.then((r) => r.resp || "Unknown");
59+
let time = await rcon
60+
.rconCommand("/time", serverid)
61+
.then((r) => r.resp || "Unknown");
6062
statsembed.addFields(
6163
{ name: "Evolution", value: evolution },
6264
{ name: "Time", value: time }

src/commands/Moderation/rconcmd.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const Rconcmd: Command<Message> = {
3737
const cmdArr = args.slice(1);
3838
const command = cmdArr.join(" ");
3939
let res = await rcon.rconCommand(command, toSendServer);
40+
if (!res) return message.channel.send("Server not found!");
4041
if (typeof res.resp == "object")
4142
return message.channel.send(
4243
`Error. Command may have worked, but didn't give a response: ${res.resp}`

src/commands/Moderation/rconcmdall.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ const RconcmdAll: Command<Message> = {
4040
try {
4141
if (out.resp && out.resp.length > 1024)
4242
throw Error("Response too long!");
43-
else outEmbed.addField(`${out.server.discordname}`, out.resp);
43+
else
44+
outEmbed.addField(`${out.server.discordname}`, out.resp.toString());
4445
} catch (error) {
4546
outEmbed.addField(`${out.server.discordname}`, error);
4647
console.error(error);

0 commit comments

Comments
 (0)