From 247e803fa215f86dc1db7ee7cbb70464460f434c Mon Sep 17 00:00:00 2001 From: floriegl <22279483+floriegl@users.noreply.github.com> Date: Wed, 8 May 2024 02:48:24 +0200 Subject: [PATCH] added ASF_BOTS environment variable --- .env.template | 1 + README.md | 3 ++- docker-compose.yml | 1 + index.js | 27 ++++++++++++++------------- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.env.template b/.env.template index d0fd424..e64fede 100644 --- a/.env.template +++ b/.env.template @@ -3,3 +3,4 @@ ASF_HOST=localhost ASF_PASSWORD=hunter2 ASF_COMMAND_PREFIX=! ASF_HTTPS=false +ASF_BOTS=asf #https://github.com/JustArchiNET/ArchiSteamFarm/wiki/Commands#bots-argument diff --git a/README.md b/README.md index b134810..2d169fc 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Latest games claimed: https://gist.github.com/C4illin/77a4bcb9a9a7a95e5f291badc9 ### Docker ```bash -docker run --name asfclaim -e ASF_PORT=1242 -e ASF_HOST=localhost -e ASF_HTTPS=false -e ASF_PASSWORD=hunter2 -e ASF_COMMAND_PREFIX=! ghcr.io/c4illin/asfclaim:master +docker run --name asfclaim -e ASF_PORT=1242 -e ASF_HOST=localhost -e ASF_HTTPS=false -e ASF_PASSWORD=hunter2 -e ASF_COMMAND_PREFIX=! -e ASF_BOTS=asf ghcr.io/c4illin/asfclaim:master ``` #### Docker-compose: ```yml @@ -36,6 +36,7 @@ services: - ASF_PASSWORD= - ASF_COMMAND_PREFIX=! - ASF_HTTPS=false + - ASF_BOTS=asf #https://github.com/JustArchiNET/ArchiSteamFarm/wiki/Commands#bots-argument asf: # ... ``` diff --git a/docker-compose.yml b/docker-compose.yml index 1ee8b3e..4937fc2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,3 +9,4 @@ services: # - ASF_PASSWORD=hunter2 # - ASF_COMMAND_PREFIX=! # - ASF_HTTPS=false + # - ASF_BOTS=asf #https://github.com/JustArchiNET/ArchiSteamFarm/wiki/Commands#bots-argument diff --git a/index.js b/index.js index 36f9b6d..0d35da9 100644 --- a/index.js +++ b/index.js @@ -1,22 +1,23 @@ import fetch from "node-fetch" import { readFile, writeFileSync } from "fs" import { Octokit } from "@octokit/rest" -const octokit = new Octokit() import * as dotenv from "dotenv" +const octokit = new Octokit() dotenv.config() -let asfport = process.env.ASF_PORT || "1242" -let asfhost = process.env.ASF_HOST || "localhost" -let password = process.env.ASF_PASSWORD || "" -let commandprefix = process.env.ASF_COMMAND_PREFIX || "!" -let asfhttps = (process.env.ASF_HTTPS && process.env.ASF_HTTPS == 'true') ? true : false; +const asfport = process.env.ASF_PORT || "1242"; +const asfhost = process.env.ASF_HOST || "localhost" +const password = process.env.ASF_PASSWORD || "" +const commandprefix = process.env.ASF_COMMAND_PREFIX || "!" +const asfhttps = process.env.ASF_HTTPS && (process.env.ASF_HTTPS === true || process.env.ASF_HTTPS === 'true') +const asfbots = process.env.ASF_BOTS || "asf" let lastLength readFile("lastlength", function read(err, data) { if (!err && data) { lastLength = data - } else if (err.code == "ENOENT") { + } else if (err.code === "ENOENT") { writeFileSync("lastlength", "0") lastLength = 0 } else { @@ -29,7 +30,7 @@ setInterval(checkGame, 6 * 60 * 60 * 1000) //Runs every six hours function checkGame() { octokit.gists.get({ gist_id: "e8c5cf365d816f2640242bf01d8d3675" }).then(gist => { - let codes = gist.data.files['Steam Codes'].content.split("\n") + const codes = gist.data.files['Steam Codes'].content.split("\n"); //THIS IS BAD, and definitely not scalable. if (lastLength < codes.length) { @@ -38,15 +39,15 @@ function checkGame() { console.log("Only runs on the last 40 games") lastLength = codes.length - 40 } - let asfcommand = commandprefix + "addlicense asf " + let asfcommand = `${commandprefix}addlicense ${asfbots} ` for (lastLength; lastLength < codes.length; lastLength++) { asfcommand += codes[lastLength] + "," } asfcommand = asfcommand.slice(0, -1) - let command = { Command: asfcommand } - let url = asfhttps ? 'https' : 'http'; url += "://" + asfhost + ":" + asfport + "/Api/Command" - let headers = { "Content-Type": "application/json" } + const command = { Command: asfcommand } + const url = `http${asfhttps ? 's' : ''}://${asfhost}:${asfport}/Api/Command` + const headers = { "Content-Type": "application/json" } if (password && password.length > 0) { headers["Authentication"] = password } @@ -58,7 +59,7 @@ function checkGame() { }) .then(res => res.json()) .then(body => { - if (body.Success) { + if (body['Success']) { console.log("Success: " + asfcommand) console.debug(body) writeFileSync("lastlength", lastLength.toString())