-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
44 lines (38 loc) · 1.55 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const core = require("@actions/core");
const github = require( "@actions/github");
const rcon = require( "./node-rcon/RCON.js" );
run()
async function run() {
console.log("💚 thank you for using RCON-Action ( https://github.com/Plagiatus/RCON-Action ).");
console.log("⭐ if you find this helpful, why not drop a star on the repo? Much appreciated!");
console.log("❓ if you have any questions or issues, please let us know by writing an issue");
try {
const inputs = {
server: core.getInput("server"),
port: core.getInput("port"),
password: core.getInput("password"),
commands: JSON.parse(core.getInput("commands")),
sendPushInfo: core.getInput("send-push-info"),
pushInfoRecipient: core.getInput("push-info-recipient"),
}
const payload = JSON.stringify(github.context.payload, undefined, 2);
// console.log(inputs);
// console.log(payload);
const srvr = new rcon();
console.log("Connecting to server via RCON...");
await srvr.connect(inputs.server, inputs.port, inputs.password)
console.log("🟢 Connected and authenticated.");
if (inputs.sendPushInfo) {
await srvr.send(`tellraw ${inputs.pushInfoRecipient} [{"text":"[GitHub] New push from ","color":"gold"},{"text":"${github.context.payload.sender.login}","color":"yellow"},{"text":" detected."}]`)
}
if (inputs.commands.length > 0) {
for (let command of inputs.commands) {
await srvr.send(command);
}
console.log(`📬 Sent all ${inputs.commands.length} additional commands to the server.`)
}
srvr.end();
} catch (error) {
core.setFailed(error.message)
}
}