Yoshi-E / ArmaRconDiscordBot

Discord Bot to connect to an arma server using BEC and Rcon
Other
18 stars 12 forks source link

Unable to access settings #67

Open mcknight05 opened 1 month ago

mcknight05 commented 1 month ago

Using a discord bot host for the bot. Cannot access using localhost

Is there a way around this to still setup the bot?

Yoshi-E commented 1 month ago

Yes, each module has a ".settings" folder that contains the default config files. E.g. https://github.com/Yoshi-E/ArmaRconDiscordBot/tree/master/modules/core/.settings

Duplicate the settings files and change the extension from .default_json to .json. Fill in the values. Entries ending with "_description" are just the texts for the UI and can be ignored.

For your use case doing this for the modules "core", and "rcon" should be sufficient. Other modules should be disabled by default.

mcknight05 commented 1 month ago

Perfect, I'll try that when I'm home and I'll let you know. On another note, I saw yesterday some of the descriptions in the file for start server and stop server give an example of an exe file for the armaserver file.

Since the arma server is hosted on Linux, will that still work if I put in the appropriate file?

mcknight05 commented 1 month ago

Perfect, I'll try that when I'm home and I'll let you know. On another note, I saw yesterday some of the descriptions in the file for start server and stop server give an example of an exe file for the armaserver file.

Since the arma server is hosted on Linux, will that still work if I put in the appropriate file?

Although I realise now that was for the settings within the arma module

Yoshi-E commented 1 month ago

Yes, if you are hosting the bot on a different server, it wont be able to access the arma 3 server directly to read logs, or to start or stop it. That's why the arma module isn't of much use to you here.

In principle its just a simple subprocess.Popen call that should work on all platforms: https://github.com/Yoshi-E/ArmaRconDiscordBot/blob/098b6b73889afa8e9ed2262f0710279ffda44f58/modules/arma/module.py#L223

mcknight05 commented 1 month ago

I have the bot running on my discord server now, thanks :) My only question is now, in which file do I modify permissions? right now I can't use any of the rcon commands

Yoshi-E commented 1 month ago

In "modules/core/" you should find the files permissions_@everyone.json and permissions_Admin.json etc. Its the format of permissions_{role}.json --> role being the name of the discord role.

mcknight05 commented 1 month ago

So I have the bot working now with the permissions configured correctly. Most of the commands work perfectly fine. The one thing I seem to have an issue with is sending messages to server/player. When I run the command, it executes, but shows a blank message ingame.

Screenshot 2024-07-28 231733

Yoshi-E commented 1 month ago

Great to hear!

I am a bit puzzled as to why the say command is not working correctly. The say command is pretty trivial:

https://github.com/Yoshi-E/ArmaRconDiscordBot/blob/098b6b73889afa8e9ed2262f0710279ffda44f58/modules/rcon/module.py#L527-L536

For some reason the message parameter doesn't seem to be set. I am unsure why. You could try replacing that code with this to figure out where it goes wrong:

    @CommandChecker.command(name='say',
        brief="Sends a global message",
        pass_context=True)
    async def sayGlobal(self, ctx, *message):
        name = ctx.message.author.name
        if not message:
            await ctx.send("No message provided.")
            return

        message = " ".join(message)
        message = self.setEncoding(message)
        if not message:
            await ctx.send("Encoding Broke it.")

        await self.arma_rcon.sayGlobal(f"{name}: {message}")

        msg = f"Send: {name}: `{message}`"
        await ctx.send(msg)

If you are willing to experiment, you can try this out and report back. It is possible the encoding breaks it, or perhaps discord API changed again...

I currently do not have a setup to reproduce this issue, so you can try it out yourself or wait 1-2 weeks.

mcknight05 commented 1 month ago

Tried with new code, bot says no message provided. Nothing shows ingame, whereas the previous code did show a blank message Screenshot 2024-07-29 002701

mcknight05 commented 1 month ago

Also tried the sayPlayer command, that doesn't seem to work either, unless I am imputting the command wrong. Although for my purpose I do care more about the normal say command Screenshot 2024-07-29 003753

Yoshi-E commented 1 month ago

Thank you, that helped to identify the issue. It is in Fact a change in discords API (>Version 1.0). I will review and migrate the code at a later time, but a quick fix should be possible: https://github.com/Yoshi-E/ArmaRconDiscordBot/blob/098b6b73889afa8e9ed2262f0710279ffda44f58/modules/core/utils.py#L268-L269

Add the ctx like so:

            async def wrapper(ctx, *args,**kwargs):
                return await func(ctx, *args,**kwargs)

I'll commit the changes once I verify that it didnt break anything.

mcknight05 commented 1 month ago

Good news the say command now fully works, thanks for that :) Screenshot 2024-07-29 123140

I did test a few tests on other commands like sayPlayer and kickPlayer which will now return a valid response on discord when I input the command, following with my player id (which I assume refers to steamid64?) but it will not perform said action ingame.

Screenshot 2024-07-29 123108

Yoshi-E commented 1 month ago

The Player ID used by most commands is the player number generated by Battleye for the current game session (not to be confused with Battleye ID or SteamID).

Use the command !players to get a list of players and their corresponding number image

Here it would be e.g. 2 for the player Ztppp

Some commands come with two versions: !banPlayer PlayerID (Use if the player is still online) !addBan GUID/BattleyeID (Use if the player is already disconnected or online)

the !player+ command will provide both GUID and PlayerID of current players

if you enable the rcon_database module you can also use !find name playername to search for people that have disconnected.

mcknight05 commented 1 month ago

Ahhhhh right, it works perfectly now. Tried both sayPlayer and kickPlayer, working as intended.

Some commands come with two versions: !banPlayer PlayerID (Use if the player is still online) !addBan GUID/BattleyeID (Use if the player is already disconnected or online)

the !player+ command will provide both GUID and PlayerID of current players

if you enable the rcon_database module you can also use !find name playername to search for people that have disconnected.

I'll keep that in mind, anyways thanks for all the help, much appreciated and is a cool bot to have with a server