This commit is contained in:
tursom 2024-10-17 11:27:40 +08:00
parent afa8551a03
commit 3004cb47fd
4 changed files with 51 additions and 26 deletions

View File

@ -1,8 +1,11 @@
const client = require("./client")
const axios = require('axios');
const http = require('http');
const fs = require('fs');
const { once } = require("node:events");
const logger = client.logger
fs.mkdir("./logs", { recursive: true }, (err) => {
if (err) {
logger.error("an error occurred while creating the logs directory: " + err);

View File

@ -2,10 +2,10 @@ const SteamID = require('steamid');
const SteamUser = require('steam-user');
const SteamTotp = require('steam-totp');
const SteamCommunity = require('steamcommunity');
fs = require('fs');
winston = require("winston");
const fs = require('fs');
const winston = require("winston");
logger = winston.createLogger({
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
defaultMeta: { service: 'steam-logger' },
@ -25,7 +25,7 @@ steamUser.on("refreshToken", (refreshToken) => {
fs.writeFileSync('refresh.token', refreshToken);
});
config = require("./config.js");
const config = require("./config.js");
try {
refreshToken = fs.readFileSync('refresh.token', 'utf8');
@ -56,18 +56,24 @@ try {
});
}
let webLogOn = false;
steamUser.on('loggedOn', async () => {
logger.info(`login to Steam as ${steamUser.steamID}`);
steamLoginPromise = new Promise((resolve, reject) => {
steamUser.on('loggedOn', async () => {
logger.info(`login to Steam as ${steamUser.steamID}`);
if (!webLogOn) {
steamUser.webLogOn();
}
resolve();
});
});
steamUser.on('webSession', async (sessionID, cookies) => {
webLogOn = true;
steamCommunity.setCookies(cookies);
steamCommunity.startConfirmationChecker(10000, config.identitySecret);
steamWebLoginPromise = new Promise((resolve, reject) => {
steamUser.on('webSession', async (sessionID, cookies) => {
logger.info(`web session received: ${sessionID}`);
webLogOn = true;
steamCommunity.setCookies(cookies);
steamCommunity.startConfirmationChecker(10000, config.identitySecret);
resolve()
});
});
async function getUserInfo(steamID, onUserInfoReceived) {
@ -97,8 +103,11 @@ async function getUserInfo(steamID, onUserInfoReceived) {
}
module.exports = {
logger: logger,
steamUser: steamUser,
steamCommunity: steamCommunity,
getUserInfo: getUserInfo,
steamLoginPromise: steamLoginPromise,
steamWebLoginPromise: steamWebLoginPromise,
}

View File

@ -1,5 +1,13 @@
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
module.exports = {
accountName: 'accountName',
password: 'password',
logonID: 5252596,
logonID: getRandomInt(1000000, 999999999),
steamID: "xxxxxxxxxx",
chat: false,
};

View File

@ -1,11 +1,14 @@
const fs = require('fs');
const config = require('./config.js');
dateformat = require('@matteo.collina/dateformat');
const logger = client.logger
client = require("./client.js")
steamUser = client.steamUser
const dateformat = require('@matteo.collina/dateformat');
fs.mkdir("./logs", {recursive: true}, (err) => {
const client = require("./client.js")
const steamUser = client.steamUser
fs.mkdir("./logs", { recursive: true }, (err) => {
if (err) {
logger.error("an error occurred while creating the logs directory: " + err);
}
@ -45,14 +48,16 @@ async function logMessage(date, steamID, message, echo, ordinal) {
});
}
steamUser.chat.on("friendMessage", (message) => {
// noinspection JSIgnoredPromiseFromCall
logMessage(dateToString(message.server_timestamp), message.steamid_friend, message.message, false, message.ordinal);
});
client.steamLoginPromise.then(() => {
steamUser.chat.on("friendMessage", (message) => {
// noinspection JSIgnoredPromiseFromCall
logMessage(dateToString(message.server_timestamp), message.steamid_friend, message.message, false, message.ordinal);
});
steamUser.chat.on("friendMessageEcho", (message) => {
// noinspection JSIgnoredPromiseFromCall
logMessage(dateToString(message.server_timestamp), message.steamid_friend, message.message, true, message.ordinal);
steamUser.chat.on("friendMessageEcho", (message) => {
// noinspection JSIgnoredPromiseFromCall
logMessage(dateToString(message.server_timestamp), message.steamid_friend, message.message, true, message.ordinal);
});
});
/**