Basically, my bot responds to a command (!accounts) by providing users with information based on their ID. For example, if an ID of 662 sends the command !account, the bot will search for steamID 662 in the json files and display the currency and corresponding ID.
I've got that part figured out. Now, I need assistance with creating a new account in the json file if the user's ID doesn't already exist.
This is the current json code:
{
"tradesettings": {
"pollInterval": 5000,
"confirmationChecker": 10000,
"acceptEscrow": false,
"acceptScammers": false,
"ourmaxitems": 50,
"theirmaxitems": 5
},
"accsettings": {
"amountofaccounts": 3
},
"accounts":[
{ "botID":"3", "steamID":"662", "balance": 0 },
{ "botID":"2", "steamID":"211", "balance": 0 },
{ "botID":"1", "steamID":"76561198026027024x", "balance": 666 },
{ "botID":"0", "steamID":"", "balance": 0 }
]}
If I want to add an extra entry, it should look like this:
{ "botID":"4", "steamID":"421", "balance": 0 },
Resulting in:
"accounts":[
{ "botID":"4", "steamID":"421", "balance": 0 },
{ "botID":"3", "steamID":"662", "balance": 0 },
{ "botID":"2", "steamID":"211", "balance": 0 },
{ "botID":"1", "steamID":"951", "balance": 666 },
{ "botID":"0", "steamID":"", "balance": 0 }]
How can I achieve this - creating a new account with a unique ID? By the way, my bot script is in myBot.js within the same folder as the config.json file.
Here's the code snippet for editing the configuration:
if(ok == 1) {
console.log("[SERVER] "+steamID.getSteamID64()+" is requesting account information.");
for(r=0;r<= config.accsettings.amountofaccounts ;r++) {
if (config.accounts[r].steamID != "undefined") {
if(config.accounts[r].steamID == steamID.getSteamID64()) {
console.log("[SERVER] "+ steamID.getSteamID64() +" is asking for account info, responding accordingly.\n")
client.chatMessage(steamID.getSteamID64(), "\nDisplaying your account on this bot\nBotID: "+config.accounts[r].botID+"\nSteamID: "+config.accounts[r].steamID+"\nBalance: "+config.accounts[r].balance);
break;
ok = 0;
r = 0;
}
}
if(r == config.accsettings.amountofaccounts) {
console.log("[SERVER] "+steamID.getSteamID64()+" does not have an account here, creating one for them.");
client.chatMessage(steamID.getSteamID64(),"Hold on, creating an account.\n\nDone, please type '!account' to view it\n(took 0.03 seconds)");
//var item2={ "botID":config.accsettings.amountofaccounts+1, "steamID":steamID.getSteamID64(), "balance": 0 };
//config.accounts.push(item2)
config.accounts.push({botId: "10", steamID: "11", balance: 0});
break;
r = 0;
ok = 0;
}
}
}
There is also another file named config.json which contains the JSON data.