This commit is contained in:
Bingus_Violet 2023-11-22 11:46:09 -06:00
parent d6d3a100f3
commit 1996dafb6a
3 changed files with 206 additions and 0 deletions

73
index.js Normal file
View file

@ -0,0 +1,73 @@
var updateTime = (process.env.UPDATE_TIME || 30)
const clientId = process.env.CLIENT_ID
const steamID = process.env.STEAM_ID
if (clientId == undefined) {
console.error("No client ID was defined! Please check the documentation for how to add one.")
return
}
if (steamID == undefined) {
console.error("No Steam ID was defined! Please check the documentation for how to add one.")
return
}
var RPC = require("discord-rpc")
const client = new RPC.Client({ transport: 'websocket' })
client.login({ clientId })
var startTime = Date.now()
var prevGame = ""
function update() {
fetch(`https://steamcommunity.com/miniprofile/${steamID}?origin=https%3A%2F%2Fsteamcommunity.com`)
.then((data) => {
return data.text()
})
.then((html) => {
var json = {
"name": "nothing",
"presence": ""
}
if (html.includes("game_name")) {
var blah = html.substring(html.indexOf('game_name">') + 11, html.length)
json["name"] = blah.substring(0, blah.indexOf("</span>"))
}
if (html.includes("presence")) {
var blah = html.substring(html.indexOf('presence">') + 10, html.length)
json["presence"] = blah.substring(0, blah.indexOf("</span>"))
}
if (prevGame != json.name) {
prevGame = json.name
startTime = Date.now()
}
client.setActivity({
details: `Playing ${json.name}`,
state: json.presence,
startTimestamp: startTime,
largeImageKey: json.name.split(" ").join("").toLowerCase(),
largeImageText: json.name
});
if (json.gameName == "nothing") {
updateTime = (process.env.UPDATE_TIME || 30) * 2.5
} else {
updateTime = (process.env.UPDATE_TIME || 30)
}
})
setTimeout(() => {
update()
}, updateTime * 1000);
}
client.on('ready', () => {
update()
});

114
package-lock.json generated Normal file
View file

@ -0,0 +1,114 @@
{
"name": "discordUpdater",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"discord-rpc": "^4.0.1"
}
},
"node_modules/bindings": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz",
"integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==",
"optional": true,
"dependencies": {
"file-uri-to-path": "1.0.0"
}
},
"node_modules/discord-rpc": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/discord-rpc/-/discord-rpc-4.0.1.tgz",
"integrity": "sha512-HOvHpbq5STRZJjQIBzwoKnQ0jHplbEWFWlPDwXXKm/bILh4nzjcg7mNqll0UY7RsjFoaXA7e/oYb/4lvpda2zA==",
"dependencies": {
"node-fetch": "^2.6.1",
"ws": "^7.3.1"
},
"optionalDependencies": {
"register-scheme": "github:devsnek/node-register-scheme"
}
},
"node_modules/file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==",
"optional": true
},
"node_modules/node-addon-api": {
"version": "1.7.2",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.7.2.tgz",
"integrity": "sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg==",
"optional": true
},
"node_modules/node-fetch": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
"integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
"dependencies": {
"whatwg-url": "^5.0.0"
},
"engines": {
"node": "4.x || >=6.0.0"
},
"peerDependencies": {
"encoding": "^0.1.0"
},
"peerDependenciesMeta": {
"encoding": {
"optional": true
}
}
},
"node_modules/register-scheme": {
"version": "0.0.2",
"resolved": "git+ssh://git@github.com/devsnek/node-register-scheme.git#e7cc9a63a1f512565da44cb57316d9fb10750e17",
"hasInstallScript": true,
"license": "MIT",
"optional": true,
"dependencies": {
"bindings": "^1.3.0",
"node-addon-api": "^1.3.0"
}
},
"node_modules/tr46": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
"integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
},
"node_modules/webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
},
"node_modules/whatwg-url": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
"integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
"dependencies": {
"tr46": "~0.0.3",
"webidl-conversions": "^3.0.0"
}
},
"node_modules/ws": {
"version": "7.5.9",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.9.tgz",
"integrity": "sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==",
"engines": {
"node": ">=8.3.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": "^5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
}
}
}

19
package.json Normal file
View file

@ -0,0 +1,19 @@
{
"dependencies": {
"discord-rpc": "^4.0.1"
},
"name": "steamrpc",
"description": "SteamRPC pulls your game and presence from Steam and puts it onto discord.",
"version": "1.0.0",
"main": "index.js",
"devDependencies": {},
"scripts": {
"test": "node index.js"
},
"repository": {
"type": "git",
"url": "https://codeberg.org/Bingus_Violet/SteamRPC"
},
"author": "Violet",
"license": "GPL-3.0-or-later"
}