#not working
88 messages · Page 1 of 1 (latest)
Please share the code
I am not sure
???
let userData = {};
// Read user data from file
if (fs.existsSync(userDataPath)) {
const userDataRaw = fs.readFileSync(userDataPath);
userData = JSON.parse(userDataRaw);
}
const userStats = userData.UserStats;
for (const userKey in userStats) {
if (Object.hasOwnProperty.call(userStats, userKey)) {
const user = userStats[userKey];
console.log('all users:', user.ID)
// Check if the user's ID exists in winnersIDs array
if (winningTeamValue.includes(user.ID)) {
if (user.rank === "bronze") {
user.elo += 20;
user.wins += 1;
if (userId.includes(user.ID)) {
user.elo += 5;
user.mvp +=1
}
} else if (user.rank === "iron") {
user.elo += 15;
user.wins += 1;
if (userId.includes(user.ID)) {
user.elo += 5;
user.mvp +=1
}
} // losing team //
} else if (losingTeamValue.includes(user.ID)) {
if (user.rank === "bronze") {
user.loses += 1;
} else if (user.rank === "iron") {
user.elo -= 5;
user.loses += 1;
}
}
}
}
fs.writeFileSync(userDataPath, JSON.stringify(userData, null, 2));
this is my previous code
Anything else?
i mean only 2 files?
this is my latest code for another cmd
can't send it for whatever reason
yes
but only the latest code has problems
which it doesn't get all the user ids from the json file (only 1 or 2 out of 12)
and even if the user id mentioned and extracted matched the user id from the json file
it still skips the part where it adds elo to the user's info in the json file
Is this latest code?
Did you import fs?
yes
i did const fs = require('fs')
same as the old one
const fs = require('fs');
let userData = {};
const userDataPath = 'path/to/your/userData.json';
const winningTeamValue = ['id1', 'id2'];
const losingTeamValue = ['id3', 'id4'];
const userId = ['id1', 'id2'];
if (fs.existsSync(userDataPath)) {
const userDataRaw = fs.readFileSync(userDataPath);
userData = JSON.parse(userDataRaw);
}
const userStats = userData.UserStats;
for (const userKey in userStats) {
if (Object.hasOwnProperty.call(userStats, userKey)) {
const user = userStats[userKey];
console.log('Processing user:', user.ID);
if (winningTeamValue.includes(user.ID)) {
console.log('User is in winning team:', user.ID);
if (user.rank === "bronze") {
user.elo += 20;
user.wins += 1;
if (userId.includes(user.ID)) {
user.elo += 5;
user.mvp += 1;
}
} else if (user.rank === "iron") {
user.elo += 15;
user.wins += 1;
if (userId.includes(user.ID)) {
user.elo += 5;
user.mvp += 1;
}
}
} else if (losingTeamValue.includes(user.ID)) {
console.log('User is in losing team:', user.ID);
if (user.rank === "bronze") {
user.loses += 1;
} else if (user.rank === "iron") {
user.elo -= 5;
user.loses += 1;
}
}
}
}
fs.writeFileSync(userDataPath, JSON.stringify(userData, null, 2));
console.log('User data updated successfully');
yes
i did.....
Doesn`t it work?
maybe i'll send u the console logs
for both
this is the console log for the working code:
Value of winningTeam: 2
winningTeam is 2
members in losing team: [ '860006790115754004', '1242656988144599102' ]
members in winning team: [ '896397461382377524', '1242658165263433759' ]
Final winningTeamValue: [ '896397461382377524', '1242658165263433759' ]
all users: 1242658165263433759
all users: 1242656988144599102
all users: 896397461382377524
all users: 860006790115754004
all users: 691875951541485610
all users: 797404156381626378
all users: 1242658835676790816
all users: 915089487325974538
all users: 737357511950073926
all users: 1040602353520357467
all users: 827192816756588585
all users: 897831962700574762
and this is the console log for the code that is not working:
mentioned user: 860006790115754004
all users: 1242658165263433759
Reveived message: user does not exist
it only extracts one user id from the json file
and like i said. even if both ids match, it doesn't work
mentioned user: 1242658165263433759
all users: 1242658165263433759
Received message: user does not exist
Could you please share the json?
file?
yeah
or just the stuff inside
file
cuz i dont think sharing files is allowed
ok
{
"UserStats": {
"User1": {
"ID": "1242658165263433759",
"username": "censored2",
"elo": 20,
"wins": 1,
"loses": 0,
"mvp": 0,
"rank": "bronze"
},
"User2": {
"ID": "1242656988144599102",
"username": "censored1",
"elo": 0,
"wins": 0,
"loses": 1,
"mvp": 0,
"rank": "bronze"
},
"User3": {
"ID": "896397461382377524",
"username": "trasher",
"elo": 25,
"wins": 1,
"loses": 0,
"mvp": 1,
"rank": "bronze"
},
"User4": {
"ID": "860006790115754004",
"username": "duweird",
"elo": 0,
"wins": 0,
"loses": 1,
"mvp": 0,
"rank": "bronze"
},
"User5": {
"ID": "691875951541485610",
"username": "iloveu",
"elo": 0,
"wins": 0,
"loses": 0,
"mvp": 0,
"rank": "bronze"
},
"User6": {
"ID": "797404156381626378",
"username": "monkey",
"elo": 0,
"wins": 0,
"loses": 0,
"mvp": 0,
"rank": "bronze"
},
"User7": {
"ID": "1242658835676790816",
"username": "censored3",
"elo": 0,
"wins": 0,
"loses": 0,
"mvp": 0,
"rank": "bronze"
},
"User8": {
"ID": "915089487325974538",
"username": "bunnive",
"elo": 0,
"wins": 0,
"loses": 0,
"mvp": 0,
"rank": "bronze"
},
"User9": {
"ID": "737357511950073926",
"username": "GoatedDaddy",
"elo": 0,
"wins": 0,
"loses": 0,
"mvp": 0,
"rank": "bronze"
},
"User10": {
"ID": "1040602353520357467",
"username": "factuality",
"elo": 0,
"wins": 0,
"loses": 0,
"mvp": 0,
"rank": "bronze"
},
"User11": {
"ID": "827192816756588585",
"username": "dogfish",
"elo": 0,
"wins": 0,
"loses": 0,
"mvp": 0,
"rank": "bronze"
}
}}
i changed some usernames cuz they were inappropriate
btw these are all added automatically when someone uses the =register command
This is not working?
no
this
Do you mean if we add user.ID there, it works fine?
no
it's just something i forgot to add when copy and pasting it here
cuz i was trying to fix it myself beforea asking for help
?
yes it is not working
did you fix it?
You can go over the word limit it'll just turn into a message.txt which is fine, and sharing files is fine (as long as it's not zipped) but we prefer you use something like hastebin
would you mind telling what fixed it?
all curious
like
the userId
.includes
was the part which messed everythingup
i did === and it worked
btw
how do i use hastebin
I think I told you some days ago that you were looping over user and inside the loop handling always 1 user, not an array 🤔
yea
hmm.. I always use codepen
whats dat
but I guess hastebin is similar (?)
just another "sandbox" 🙂