poshbotio / PoshBot

Powershell-based bot framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Discord backend locks up - Suspect rate limits

Kickbut101 opened this issue · comments

commented

#142 - Seems to be duplicate of this ticket!

Expected Behavior

I should be able to add-remove-update plugins at will and have the backend respect discords rate-limits so as not to lock up or lose connection to API.

Current Behavior

Currently something as simple as !Update-Plugin locks up the api with the last errors showing (verbose)

05:51:22Z","Class":"DiscordBackend","Method":"_WaitRateLimit","Severity":"Warning","LogLevel":"Info","Message":"Rate
limit reached. Sleeping [0.250] milliseconds","Data":{}}
WARNING: {"DataTime":"2019-11-13
05:51:22Z","Class":"DiscordBackend","Method":"_WaitRateLimit","Severity":"Warning","LogLevel":"Info","Message":"Rate
limit reached. Sleeping [0.250] milliseconds","Data":{}}
WARNING: {"DataTime":"2019-11-13
05:51:22Z","Class":"DiscordBackend","Method":"_SendDiscordMsg","Severity":"Warning","LogLevel":"Info","Message":"{\n
"global": false, \n "message": "You are being rate limited.", \n "retry_after": 138\n}\n","Data":{}}

Possible Solution

  • Add a delay to the reaction emojis, so that they don't try to fire off as quickly
  • Make sure the rate limiting function/code you already have in place exists on all communications with discord api (through the backend I assume?)
  • Allow emojis to be turned off from PoshBotConfig.psd1 file ?
  • Put in a counter to increase the ratelimit delay each successive time it sees it? Kind of like a cooldown

Steps to Reproduce (for bugs)

  1. Build 0.12.0 poshbot
  2. Connect bot and app in discord via https://poshbot.readthedocs.io/en/latest/guides/backends/setup-discord-backend/
  3. Follow this page to make test plugin https://poshbot.readthedocs.io/en/latest/tutorials/plugin-development/simple/
  4. Change the test plugin .psm1 file (I literally changed it from just write-output, to having an if statement to check if user input a username along with the !invoke-helloworld command).
  5. Try !update-plugin
  6. For me at this point it locks up, see the error log above.

Context

Just trying to build some bot in discord for personal use among myself and friends

Your Environment

  • Module version used: 0.12.0
  • Operating System and PowerShell version: Win10 1903, powershell 5.1 I believe?
commented

Allow emojis to be turned off from PoshBotConfig.psd1 file ?

They can be turned off from the starting script:
$pbc.AddCommandReactions = $false

@Kickbut101 Can you expand on what you mean by "lock up"? You will see rate limit messages in the log but there should be no loss of functionality.

The Rate limit reached messages are normal for reactions as Discord has a very low rate limit on them. We act on the rate limit headers received from Discord and sleep accordingly.

commented

@Kickbut101 Can you expand on what you mean by "lock up"? You will see rate limit messages in the log but there should be no loss of functionality.

The Rate limit reached messages are normal for reactions as Discord has a very low rate limit on them. We act on the rate limit headers received from Discord and sleep accordingly.

You bet!

My powershell ISE will lock up in "running" mode without allowing me to break the script which results in me having to "End Task" in task manager to get it to finally close/stop. In addition to this the bot becomes unresponsive and no longer listens or fulfills commands (like !status or !about or anything). I believe I also tried to run the script as a standalone script (running it just in a normal powershell console, outside the powershell ISE) and got same results.

This was a while ago so my memory on it is not quite as clear as it was. But I bet I can recreate it when I get home if you'd like.

commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Is this still an issue @Kickbut101?

commented

I am unsure what causes it but the .12 build I made long ago does still die on it's own for some reason. It's probably not at all related to rate limits. But It will lock up and the powershell console will still be "running" but the bot status on discord goes to offline and no commands are accepted/run.

Again though, probably not rate limit related. More likely just a bad build on my part? Unsure. You can close this one.

commented