PetyXbron / minecraft-bot

Informational Discord bot for your Minecraft server
https://mb.petyxbron.cz/
GNU General Public License v3.0
69 stars 28 forks source link

Status and activity broken #11

Open cattoman1 opened 2 years ago

cattoman1 commented 2 years ago

yea the status when using the status command is just {status} and the bot activity wont change

image

PetyXbron commented 2 years ago

Hello @Garyblu, can you send me a screenshot of your console, file of config.js (with removed "sensitive" data) to check if you set up everything right?

cattoman1 commented 2 years ago

image

cattoman1 commented 2 years ago

image

PetyXbron commented 2 years ago

@Garyblu do you have updated this project? Do you have an object messages.status on line 100? The {status} variable should be replaced with ":white_check_mark: **ONLINE**".

blaze534 commented 2 years ago

@PetyXbron i know is old but i have the same problem

PetyXbron commented 2 years ago

@blaze534 okay, so can you answer my question posted 3 months ago please?

do you have updated this project? Do you have an object messages.status on line 100. The {status} variable should be replaced with ":white_check_mark: ONLINE".

blaze534 commented 2 years ago

Immagine 2022-09-27 162831 this is line 100 of config.js

blaze534 commented 2 years ago

//CONFIG DATA EXPLANATION - https://docs.petyxbron.cz/config/config-info module.exports = { //Your bot data bot: { token: "", //Your bot token - https://tinyurl.com/discordbot-token prefix: ".", //Your custom prefix of the bot, like "!" or "." presence: "test", //Custom activity/status text status: "ONLINE", //You can choose: ONLINE, IDLE, DND (do not disturb), INVISIBLE activity: "playing", //You can choose: PLAYING, LISTENING, WATCHING, COMPETING guildID: "1003269988859252758", //Your Discord server guild ID },

//Your Minecraft server data
server: {
    name: "DogMC", //Your server name
    type: "java", //"java" or "bedrock"
    ip: "", //IP of your server - do not include port - e.g. "mc.hypixel.net"
    port: "", //PORT of your server - empty => default port (JA 25565, BE 19132)
    icon: "https://cdn.discordapp.com/icons/1003269988859252758/f6d327b504b7ac8c8662781b65b956c7.png", //Link to icon - like "https://website.com/icon.png"
    version: "1.8.8-1.19", //Minecraft version of sever
    vote: "" //Vote link - like "https://minecraftpocket-servers.com/server/80103/vote/"
},

//Basic code settings
//All settings are boolean wanted - Use "true" for enabling, "false" for disabling setting.
settings: {
    warns: true, //Show warns?
    debug: false, //Log most of the changes and updates (pretty spam)?
    inviteLink: true, //Show bot invite link on bot start?
    readyScan: true, //On bot's start, send to console server's basic info?
    split: false, //Advanced - Extract only the version like "1.17" or "1.12" etc.
    randomColor: false, //Enable random hex color generator for embeds? Overwrites embeds settings!
    statusCH: false, //Enable auto-changing status message?
    votingCH: false, //Enable voting channel?
    countingCH: true //Enable counting channel?
},

//Period of auto changing status if you are using {onlinePlayers} or {maxPlayers} in bot's presence
autoStatus: {
    time: "30s", //Period of auto changing status - like "3min", "20s" or "1min" etc.
    offline: "Offline" //Changes bot's presence to this text if the server is offline / not found
},

//Auto changing status message
statusCH: {
    channelID: "",
    time: "30s" //Period of updating status message - like "3min", "20s" or "1min" etc.
},

//Voting channel - https://docs.petyxbron.cz/config/config-info#voting-ch
votingCH: {
    channelID: "",
    time: "30s", //Time for how long the cancel reaction should be deleted.
    threads: {
        enable: false, //Create discussion threads for each votingCH message
        nameSyntax: "Voting {ID}", //Thread name ("{ID}" = ID of voting/suggestion)
        idSyntax: "001", //ID syntax - choose how many zeros should IDs show (DON'T REMOVE INTEGER "1")
        archiveTime: 1440 //Minutes after which the thread should archive in case of no recent activity
    },
    reactions: {
        first: "๐Ÿ‘", //First added reaction (the positive one)
        second: "๐Ÿ‘Ž", //Second added reaction (the negative one)
        cancel: "โŒ" //Third added reaction (cancel/remove button)
    }
},

//Counting channel - auto updating channel name
countingCH: {
    channelID: "1022848271326130206",
    time: "1s", //Period of updating channel name - like "3min", "20s" or "1min" etc.
    name: "{onlinePlayers} players online!", //Name of the channel
    offline: "Il Server รจ offlin!" //Name of the channel if the server is offline / not found
},

//Embeds settings
embeds: {
    colors: {
        normal: "",  //Main/successful color of embeds - choose HEX color here: https://htmlcolorcodes.com
        error: "", //Error/unsuccessful color of embeds - choose HEX color here: https://htmlcolorcodes.com
    }
},

//Program process console logging
console: {
    emojis: {
        success: "๐Ÿ’š",
        info: "๐Ÿ’™",
        warn: "๐Ÿ’›",
        error: "๐Ÿ›‘"
    }
},

//All commands settings
commands: {
    enableSlashes: true, //If you want to disable only specific slashes, leave this true and go down
    //List of all commands:
    help: {
        enableNormal: true, //Enables normal command
        enableSlash: true, //Enables slash command
        aliases: [ //Only for normal commands
            "commands", "menu"
        ],
        text: { //Custom text settings (for translating or customization)
            title: "{serverName} bot commands:",
            description: "> **Prefix:** \`{prefix}\`\n> **Commands:**\n{commands}",
            errorTitle: "Error! Command \"{arg0}\" doesn't exist.",
            errorDescription: "Command `{arg0}` was not found.\nYou are entering the wrong alias or the command is disabled."
        }
    },
    ip: {
        enableNormal: true, //Enables normal command
        enableSlash: true, //Enables slash command
        aliases: [ //Only for normal commands
            "i", "ip-address", "address", "connect", "join"
        ],
        text: { //Custom text settings (for translating or customization)
            title: "IP:",
            description: "\`{serverIp}\`:\`{serverPort}\`"
        }
    },
    list: {
        enableNormal: true, //Enables normal command
        enableSlash: true, //Enables slash command
        aliases: [ //Only for normal commands
            "l", "players", "plist"
        ],
        text: { //Custom text settings (for translating or customization)
            title: "Lista Player Online :",
            description: "**{playersOnline}**/**{playersMax}**",
            listFormat: "```{playersList}```"
        }
    },
    status: {
        enableNormal: true, //Enables normal command
        enableSlash: true, //Enables slash command
        aliases: [ //Only for normal commands
            "s", "info", "server", "overview", "ov"
        ],
        text: { //Custom text settings (for translating or customization)
            title: "Stato del server:",
            description:
                `{status}

                **Descrizione del server**
                {motd}

                **IP**
                \`{serverIp}\`:\`{serverPort}\`

                **Versione**
                {serverType} {serverVersion}

                **Players**
                **{playersOnline}**/**{playersMax}**`,
        }
    },
    test: {
        enableNormal: true, //Enables normal command
        //Test command doesn't have slash type. Is it really necessary?
        aliases: [ //Only for normal commands
            "t", "try", "testing"
        ],
        text: { //Custom text settings (for translating or customization)
            content: "Test message reply."
        }
    },
    version: {
        enableNormal: true, //Enables normal command
        enableSlash: true, //Enables slash command
        aliases: [ //Only for normal commands
            "v", "ver"
        ],
        text: { //Custom text settings (for translating or customization)
            title: "Versione di Minecraft:",
            description: "{serverType} {serverVersion}"
        }
    },
    vote: {
        enableNormal: true, //Enables normal command
        enableSlash: true, //Enables slash command
        aliases: [ //Only for normal commands
            "votelink"
        ],
        text: { //Custom text settings (for translating or customization)
            title: "Coming Soon:",
            description: "Coming Soon."
        }
    },
}

};

//CONFIG DATA EXPLANATION - https://docs.petyxbron.cz/config/config-info this is the entire config.js whithout sensitive data

PetyXbron commented 2 years ago

I am not sure why is it happening. @blaze534 can you please explain the issue again? Is it a problem with the status command, right?

blaze534 commented 2 years ago

my /status run but the activity like playing or other it

PetyXbron commented 2 years ago

Can you please send me a screenshot of full bots message response?

blaze534 commented 2 years ago

it dosent give an error

PetyXbron commented 2 years ago

I mean screenshot of the Discord message in chat app

blaze534 commented 2 years ago

wait maybe i got misunderstood i am talking about the activity like watching playing what screenshot do you need visual studio? bot profile on Discord?the Console? Immagine 2022-09-28 140118

PetyXbron commented 2 years ago

Oh, I see now

PetyXbron commented 1 year ago

@blaze534 It's working for me in the latest version [1.6.8]. Can you please send me the output from command npm list to check your dependencies versions installed?

blaze534 commented 1 year ago

โ”œโ”€โ”€ @discordjs/rest@1.3.0 โ”œโ”€โ”€ axios@0.27.2 โ”œโ”€โ”€ chalk@4.1.2 โ”œโ”€โ”€ discord-api-types@0.37.12 โ”œโ”€โ”€ discord.js@14.6.0 โ”œโ”€โ”€ fs@0.0.1-security โ”œโ”€โ”€ minecraft-motd-util@1.1.12 โ”œโ”€โ”€ minecraft-server-util@5.3.1 โ”œโ”€โ”€ ms@2.1.3 โ””โ”€โ”€ quick.db@7.1.3 i have node 17.6.0

PetyXbron commented 1 year ago

I am sorry, but I don't know what wrong have you set. Try to check all again on your site. If I will remember any fixes for you I will contact you. Also, try to keep your project updated for any possible fixes published.

blaze534 commented 1 year ago

ok txt

llsaintsll commented 1 year ago

Hi, guys! ๐Ÿ˜„

I've identified the bug in the code, and it seems to be related to the code that injects the bot presence in the ready.js file. I went ahead and refactored the code to fix the issue. However, I can't be entirely sure that it's completely reliable.

Here's the refactored code:

const setBotPresence = async (presence, activity, status) => {
    try {
        await bot.user.setPresence({
            activities: [{ name: presence, type: at[activity] }],
            status: status,
            afk: false
        });
        if (debug) console.log(`${bot.emotes.debug} Successfully set the bot presence to ${ma(`${activity} ${presence}`)}`);
    } catch (error) {
        if (debug) console.log(`${bot.emotes.debug} Could not set the Discord bot presence! Error:\n${error}`);
    }
}

const getServerStatusData = async (type, ip, port) => {
    let errored = false, response = undefined;
    try {
        response = await util.get(`https://api.mcstatus.io/v2/status/${type}/${ip}:${port}`);
    } catch (error) {
        if (debug) console.log(`${bot.emotes.debug} Could not receive server status data! Error:\n${error}`);
        errored = true;
    }
    return { errored, response };
}

if (bot.pres) {
    let { presence, status, activity } = config.bot;
    status = status.toLowerCase();
    activity = activity.charAt(0).toUpperCase() + activity.slice(1).toLowerCase();

    if (bot.pres.includes("{onlinePlayers}") || bot.pres.includes("{maxPlayers}")) {
        async function autoUpdatingPresence() {
            let { errored, response } = await getServerStatusData(server.type, server.ip, server.port);

            if (!errored) {
                presence = presence.replaceAll("{onlinePlayers}", response.data.players.online)
                    .replaceAll("{maxPlayers}", response.data.players.max);
            } else {
                presence = config.autoStatus.offline;
            }

            await setBotPresence(presence, activity, status);
            setTimeout(autoUpdatingPresence, ms(config.autoStatus.time));
        }

        await autoUpdatingPresence();
    } else {
        await setBotPresence(presence, activity, status);
    }
}

Please review the changes and test the refactored code thoroughly to ensure it works as expected. If you encounter any issues or have any questions, feel free to reach out for further assistance.

PetyXbron commented 1 year ago

@llsaintsll I think this issue is outdated with its version. There is a chance that this problem is already fixed in the newest dev version. Also, what did you exactly change? Which lines?

PetyXbron commented 1 year ago

The screenshot by the creator of this issue doesn't look like it relates to Discord bot/client/user presence/activity. image This looks like the status command embed output or embed message from the statusCH feature.

llsaintsll commented 1 year ago

The screenshot by the creator of this issue doesn't look like it relates to Discord bot/client/user presence/activity. image This looks like the status command embed output or embed message from the statusCH feature.

Oh, I see... I thought it was related to the Bot presence, like the little message above the name, 'cause I was having this issue too.


@llsaintsll I think this issue is outdated with its version. There is a chance that this problem is already fixed in the newest dev version. Also, what did you exactly change? Which lines?

In the original code, the problem happens here:

if (!errored) {
    // Code omitted for brevity... ๐Ÿ˜ƒ 
} else {
    const presence = config.autoStatus.offline;
    // More code omitted... ๐Ÿ˜ƒ 
}
presence = config.bot.presence;

The presence variable is reset to its original value at the end of each iteration of the autoUpdatingPresence() function, meaning that any changes that were made to it get overwritten.

So, I try to rewritte the equivalent part of the code like this:

if (!errored) {
    presence = presence.replaceAll("{onlinePlayers}", response.data.players.online)
        .replaceAll("{maxPlayers}", response.data.players.max);
} else {
    presence = config.autoStatus.offline;
}

await setBotPresence(presence, activity, status);

In this version of the code, the presence variable is not reset to its original value after each iteration, meaning that changes to it are preserved until the next time autoUpdatingPresence() is called.

The key change that was made to fix the problem was to remove the line presence = config.bot.presence; at the end of the autoUpdatingPresence() function and instead to handle the updating of presence entirely within the if (!errored) and else branches of the code.

I hope my explanation makes sense! If you have any doubts, feel free to reach out me. I'll try the dev branch of the code. ๐Ÿ˜„