Skip to content

Commit

Permalink
chore: logininfo dataExport now uses DataManager logininfo prop inste…
Browse files Browse the repository at this point in the history
…ad of reconstructing from bots collection

This fixes skipped accounts not being included in the result, enables us to properly dispatch dataUpdate event and unifies behavior with the other functions. If the bot order is being changed by e.g. a plugin, logininfo MUST be updated and logininfo exported to persist that change.
  • Loading branch information
3urobeat committed Jan 10, 2025
1 parent f41c55d commit 063207d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/data/fileStructure.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@
{
"path": "src/dataManager/dataExport.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/dataManager/dataExport.js",
"checksum": "e65e3832a53946a1604a1b47d0c99442"
"checksum": "215ee2110d08ee1b95c8e720170fc8f8"
},
{
"path": "src/dataManager/dataImport.js",
Expand Down
21 changes: 12 additions & 9 deletions src/dataManager/dataExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 2023-07-04 21:29:42
* Author: 3urobeat
*
* Last Modified: 2025-01-08 19:43:03
* Last Modified: 2025-01-10 16:49:06
* Modified By: 3urobeat
*
* Copyright (c) 2023 - 2025 3urobeat <https://github.com/3urobeat>
Expand Down Expand Up @@ -118,14 +118,14 @@ DataManager.prototype.writeLogininfoToDisk = function() {
if (fs.existsSync(srcdir + "/../logininfo.json")) {
logger("debug", "DataManager dataExport: Writing to logininfo.json...");

// Construct logininfo object
const logininfojson = {};

// Re-Construct logininfo object. Iterate over bots instead of logininfo to retain a changed bots hierarchy
for (const e of this.controller.getBots("*")) {
logininfojson[`bot${e.index}`] = [ e.accountName, e.loginData.logOnOptions.password, e.loginData.logOnOptions.sharedSecret ];
for (const e of this.logininfo) {
logininfojson[`bot${e.index}`] = [ e.accountName, e.password, e.sharedSecret ];
}

//this.controller._dataUpdateEvent("logininfo", null, logininfojson); // TODO
this.controller._dataUpdateEvent("logininfo", null, this.logininfo);

// Get arrays on one line
const stringifiedlogininfo = JSON.stringify(logininfojson, function(k, v) { // Credit: https://stackoverflow.com/a/46217335/12934162
Expand All @@ -148,12 +148,15 @@ DataManager.prototype.writeLogininfoToDisk = function() {
const accountstxt = [ "//Comment: Provide login information in the form of username:password. Read instructions here: https://github.com/3urobeat/steam-comment-service-bot/blob/master/docs/wiki/setup_guide.md#accounts" ]; // Re-add comment

// Re-construct accounts.txt string. Iterate over bots instead of logininfo to retain a changed bots hierarchy
for (const e of this.controller.getBots("*")) {
if (e.loginData.logOnOptions.sharedSecret) accountstxt.push(`${e.accountName}:${e.loginData.logOnOptions.password}:${e.loginData.logOnOptions.sharedSecret}`);
else accountstxt.push(`${e.accountName}:${e.loginData.logOnOptions.password}`);
for (const e of this.logininfo) {
if (e.sharedSecret) {
accountstxt.push(`${e.accountName}:${e.password}:${e.sharedSecret}`);
} else {
accountstxt.push(`${e.accountName}:${e.password}`);
}
}

//this.controller._dataUpdateEvent("logininfo", null, accountstxt); // TODO
this.controller._dataUpdateEvent("logininfo", null, this.logininfo);

fs.writeFile(srcdir + "/../accounts.txt", accountstxt.join("\n"), (err) => {
if (err) logger("error", "DataManager: Error writing accounts to accounts.txt: " + err);
Expand Down

0 comments on commit 063207d

Please sign in to comment.