Assaro / DD_Bot

Discord Bot to Control Docker Services via the Docker Socket
GNU General Public License v3.0
35 stars 5 forks source link

Unable to query docker #17

Closed nodiaque closed 1 year ago

nodiaque commented 1 year ago

Hello,

I just tried installing this bot on my unraid and whn I type /list, the log of the docker show this:


GameManBot: Contacting Docker Service...
Unhandled exception. Discord.Net.HttpException: The server responded with error 50035: Invalid Form Body
at Discord.Net.Queue.RequestBucket.SendAsync(RestRequest request)
at Discord.Net.Queue.RequestQueue.SendAsync(RestRequest request)
at Discord.API.DiscordRestApiClient.SendInternalAsync(String method, String endpoint, RestRequest request)
at Discord.API.DiscordRestApiClient.SendJsonAsync[TResponse](String method, String endpoint, Object payload, BucketId bucketId, ClientBucketType clientBucket, RequestOptions options)
at Discord.API.DiscordRestApiClient.ModifyInteractionResponseAsync(ModifyInteractionResponseParams args, String interactionToken, RequestOptions options)
at Discord.Rest.InteractionHelper.ModifyInteractionResponseAsync(BaseDiscordClient client, String token, Action`1 func, RequestOptions options)
at Discord.WebSocket.SocketInteraction.ModifyOriginalResponseAsync(Action`1 func, RequestOptions options)
at DD_Bot.Application.Commands.ListCommand.Execute(SocketSlashCommand arg, DockerService dockerService, DiscordSettings settings) in /home/assaro/coding/DD_Bot_Releases/src/DD_Bot.Application/Commands/ListCommand.cs:line 91
at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
at System.Threading.Thread.StartCallback()

I'm on unraid 6.9.2

Assaro commented 1 year ago

Can you please post your settings.json (blur out the token), the Docker Settings in Unraid and a list of your Docker containers?

nodiaque commented 1 year ago

Sure thing, here's the settings.json

{

  "LanguageSettings": {
    "Language": "en"
  },
  "DiscordSettings": {
    "Token": "#####",
    "AdminIDs": [
     #########
    ],
    "UserWhitelist": true,
    "UserIDs": [
      #####
    ],
    "UsersCanStopContainers": false,
    "AllowedContainers": []
  },
  "DockerSettings": {
    "BotName": "GameManBot",
    "Retries": 6,
    "TimeBeforeRetry": 5
  }
}

and here's the unraid setup. I tried also with bridge network and it didn't change anything. image

Assaro commented 1 year ago

Okay. Another Question. Does this occur regardless of the user being an Admin/Whitelisted?

Could you test whether the error still occurs if you change your user to have no rights to use the command at all?

nodiaque commented 1 year ago

I tried with my user as admin, I don't think it's a permission cause on the discord, when I do /list, it says it will query docker to have the list and I get the error below.

I removed myself from the adminsid, the bot now tell me "You are not allowed to use this command". But, on the docker side, I do see this message on DD_Bot docker: "GameManBot: Contacting Docker Service..." but nothing else.

Assaro commented 1 year ago

Can you tell me how many docker containers you have? I think the bot is hitting the character limit of discord

nodiaque commented 1 year ago

54 container and growing

Assaro commented 1 year ago

That's what i thought. There are too many characters. That is something i cannot fix right now. Will take some time and rebuilding that command. Will be done. But i am sorry to say that i currently can't give you an estimate on it. For now, i recommend you to not use the list command as admin. If you are a normal user the command only displays the whitelisted items. I will think about a way to fix that and will do that as soon as possible

nodiaque commented 1 year ago

I might check your code and check on how to split in multiple message or a thread.

I'll also check unraid if I could put a tag in the docker and make the list command list only the tagged container, that would allow for role!

Assaro commented 1 year ago

I might check your code and check on how to split in multiple message or a thread.

Feel free to do that. I am a little short on time right now.

I'll also check unraid if I could put a tag in the docker and make the list command list only the tagged container, that would allow for role!

If you set these tags in Unraid only it will not work. It would have to be tags in the docker run command of each container

Assaro commented 1 year ago

I have published a solution to the bugfix branch. It automatically splits the list after a set amount of containers and sends it in multiple messages. The amount of containers included in one message can be changed in the settings. please pull the container from ddbot/bugfix and test it. I will merge it to the main branch if everything works for you

nodiaque commented 1 year ago

Hello, just tried it. It doesn't crash anymore but only 1 message is sent with 24 containers. No error in log, it show the samething as what is received in docker.

Assaro commented 1 year ago

That does sound odd. Can you send me a screenshot of you using the command and the message you get afterwards? Want to see which message is not working correctly

nodiaque commented 1 year ago

you know what, I'm the idiot here. I was checking on my phone and didn't see the previous message. I open on my laptop and saw 2 messages posted, what made me think it "wasn't working" was because what I was seeing was the same as the log from the docker image

it's working!

do you think it can be listed in A-Z order?

Assaro commented 1 year ago

If i recall correctly it is sorted. The split messages probably destroyed it somehow. Gonna look into it

Assaro commented 1 year ago

All fixed. Added sorting and numbering if there are multiple messages. It is now part of the base branch and will be pushed to ddbot/latest in a few minutes