update
This commit is contained in:
parent
afa8551a03
commit
3004cb47fd
3
chat.js
3
chat.js
@ -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);
|
||||
|
25
client.js
25
client.js
@ -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;
|
||||
steamLoginPromise = new Promise((resolve, reject) => {
|
||||
steamUser.on('loggedOn', async () => {
|
||||
logger.info(`login to Steam as ${steamUser.steamID}`);
|
||||
|
||||
if (!webLogOn) {
|
||||
steamUser.webLogOn();
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
};
|
||||
|
11
logger.js
11
logger.js
@ -1,9 +1,12 @@
|
||||
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');
|
||||
|
||||
const client = require("./client.js")
|
||||
const steamUser = client.steamUser
|
||||
|
||||
fs.mkdir("./logs", { recursive: true }, (err) => {
|
||||
if (err) {
|
||||
@ -45,6 +48,7 @@ async function logMessage(date, steamID, message, echo, ordinal) {
|
||||
});
|
||||
}
|
||||
|
||||
client.steamLoginPromise.then(() => {
|
||||
steamUser.chat.on("friendMessage", (message) => {
|
||||
// noinspection JSIgnoredPromiseFromCall
|
||||
logMessage(dateToString(message.server_timestamp), message.steamid_friend, message.message, false, message.ordinal);
|
||||
@ -54,6 +58,7 @@ steamUser.chat.on("friendMessageEcho", (message) => {
|
||||
// noinspection JSIgnoredPromiseFromCall
|
||||
logMessage(dateToString(message.server_timestamp), message.steamid_friend, message.message, true, message.ordinal);
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {Date} date
|
||||
|
Loading…
Reference in New Issue
Block a user