Tmi.js Ako zistiť, či používateľ už bežal určitý príkaz

0

Otázka

Pracujem na twich topánok a snažím sa zistiť, či konkrétny používateľ už spustili príkaz. Mám tento kúsok kódu:

    if (message === '!iq') {
    
    var iqNum = Math.floor(Math.random() * 200) + 1;
    client.action('jimmytag', `${user['display-name']} Your IQ is ` + iqNum);

}

To len randomizes číslo medzi 1-200. Ale chcem to zistiť, ak používateľ už bežal pred a tlač rozdiel. Takže ak som zadajte príkaz dva krát, prvý raz napríklad sa bude tlačiť "Vaše IQ je 100"; Ale druhý raz by to malo byť "Vaše IQ je 150 (+50)". Ako môžem to urobiť?

bots javascript
2021-11-23 22:40:53
1

Najlepšiu odpoveď

0

Vytvorte prázdny objekt (nižšie const klienta)

const userIQ = {};

Kód Twich chat príkaz

    if (message.toLowerCase() === '!iq') {
    const hasIQ = userIQ.hasOwnProperty('userid');

    if (hasIQ == true) {

        var oldiqNum = userIQ['useriq']
        var newiqNum = Math.floor(Math.random() * 200) + 1;
        var iqDif = newiqNum-oldiqNum;

        userIQ.useriq = newiqNum;

        if(iqDif>0){
            client.action(channel, `@${userstate.username} Your IQ is ` + newiqNum + `(` + `+` + iqDif  + `)`);
        } else {
            client.action(channel, `@${userstate.username} Your IQ is ` + newiqNum + `(` + iqDif  + `)`);
        }

    } else {

        var iqNum = Math.floor(Math.random() * 200) + 1;

        var userid = userstate['user-id'];
        userIQ.userid = userid;

        userIQ.useriq = iqNum;
        client.action(channel, `@${userstate.username} Your IQ is ` + iqNum);
    }
}
2021-12-03 03:48:34

V iných jazykoch

Táto stránka je v iných jazykoch

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................