#not working

88 messages · Page 1 of 1 (latest)

ripe nimbus
#

so basically i copy and pasted my previous code to a new js file

#

cuz both of them have similar concept and purposes

main narwhal
#

I am not sure

ripe nimbus
#

wait

#

i'm cutting off unecessary stuff

#

cuz discord message word limit

main narwhal
#

Yeah, right

#

so make the txt and share this here

main narwhal
ripe nimbus
#
        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

main narwhal
#

Anything else?

ripe nimbus
main narwhal
#

i mean only 2 files?

ripe nimbus
#

this is my latest code for another cmd

ripe nimbus
ripe nimbus
#

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

main narwhal
#

Did you import fs?

ripe nimbus
#

i did const fs = require('fs')

#

same as the old one

main narwhal
#

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');

main narwhal
#

I just fixed it

#

But you have to enter the json file correctly

ripe nimbus
#

i did.....

main narwhal
ripe nimbus
#

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
main narwhal
#

Could you please share the json?

ripe nimbus
#

file?

main narwhal
#

yeah

ripe nimbus
#

or just the stuff inside

main narwhal
#

file

ripe nimbus
#

cuz i dont think sharing files is allowed

main narwhal
#

ok

ripe nimbus
#
{
  "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

ripe nimbus
#

no

ripe nimbus
main narwhal
ripe nimbus
#

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

main narwhal
ripe nimbus
#

?

main narwhal
#

I am so sorry

#

I am confussed

ripe nimbus
#

nevermind you tried ur best to help me

#

appreciate that

main narwhal
#

Nooo

#

Now your script is not working. Right?

ripe nimbus
#

yes it is not working

main narwhal
#

Please use my lasted code

main narwhal
spring void
ripe nimbus
#

nvm i found the issue

#

now it's done and works fine

junior grail
ripe nimbus
#

the userId

#

.includes

#

was the part which messed everythingup

#

i did === and it worked

#

btw

#

how do i use hastebin

junior grail
#

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 🤔

junior grail
ripe nimbus
junior grail
#

but I guess hastebin is similar (?)

junior grail