Skip to content

Commit

Permalink
Merge pull request #71 from floriegl/master
Browse files Browse the repository at this point in the history
added ASF_BOTS environment variable
  • Loading branch information
C4illin authored May 8, 2024
2 parents 7bd92f0 + 247e803 commit 9825e30
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
# ...
```
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 14 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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) {
Expand All @@ -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
}
Expand All @@ -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())
Expand Down

0 comments on commit 9825e30

Please sign in to comment.