Shift-Cyber / bits

Humanoid Discord bot with too much power and a bit of an attitude...
GNU General Public License v3.0
2 stars 0 forks source link

Exception Being Thrown in Register Cog's "on_member_join" #16

Closed natesinger closed 1 year ago

natesinger commented 1 year ago

The bot is currently throwing an error in the registration cog's "on_member_join." No idea why this is happening yet, see the log.

{
  "textPayload": "Ignoring exception in command register\nTraceback (most recent call last):\n  File \"/usr/local/lib/python3.10/site-packages/discord/ext/commands/core.py\", line 229, in wrapped\n    ret = await coro(*args, **kwargs)\n  File \"/cogs/registration.py\", line 59, in register\n    member_role = guild.get_role(int(os.environ.get(\"MEMBER_ROLE\")))\nAttributeError: 'NoneType' object has no attribute 'get_role'\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n  File \"/usr/local/lib/python3.10/site-packages/discord/ext/commands/bot.py\", line 1349, in invoke\n    await ctx.command.invoke(ctx)\n  File \"/usr/local/lib/python3.10/site-packages/discord/ext/commands/core.py\", line 1023, in invoke\n    await injected(*ctx.args, **ctx.kwargs)  # type: ignore\n  File \"/usr/local/lib/python3.10/site-packages/discord/ext/commands/core.py\", line 238, in wrapped\n    raise CommandInvokeError(exc) from exc\ndiscord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'get_role'",
  "insertId": "y4w0jlff0y6ii",
  "resource": {
    "type": "gce_instance",
    "labels": {
      "project_id": "hab-sandbox-playhouse",
      "instance_id": "667418718185124219",
      "zone": "projects/405278113030/zones/us-central1-a"
    }
  },
  "timestamp": "2022-11-15T08:44:49.212023Z",
  "severity": "ERROR",
  "labels": {
    "python_logger": "discord.ext.commands.bot"
  },
  "logName": "projects/hab-sandbox-playhouse/logs/python",
  "sourceLocation": {
    "file": "/usr/local/lib/python3.10/site-packages/discord/ext/commands/bot.py",
    "line": "347",
    "function": "on_command_error"
  },
  "receiveTimestamp": "2022-11-15T08:44:49.230791506Z"
}
natesinger commented 1 year ago

Got this message, possibly related:

I recently received notification that Hack-A-Bit's Discord server was running, and I wanted to participate in the server. During the introduction of entering the server, it requires competitors to interact with the bot "Bit" to receive competitor status in the server. Since being a competitor, I decided to complete the necessary steps for registration, using, and completing the commands. Afterward, I got an access token but wasn't able to use it immediately because of an outside event that occurred. When I had the time to use the access code, this message appeared, "attempted registration with an expired token, please generate a new token and try again." I decided to use the !register and !register get-token commands again, however, after the second command, the process stopped and ended there. I was hoping to contact Hack-A-Bit to help figure this problem out. Below I have attached an image of what happened:

2022-11-19

Valkerse commented 1 year ago

It may be that the database still has the record of the first issued token? I don't know how the database works but I haven't found anything in the python code that would remove an expired token

natesinger commented 1 year ago

@Valkerse That's a good catch, that logic doesn't exist. We can write this into the db with pure mysql or using a python worker. Maybe it's pulling all the records and because it only fetches on it fetches a stale token. It looks like his issue is not even receiving the token, however.

https://dev.mysql.com/doc/refman/8.0/en/events-overview.html#:~:text=MySQL%20Events%20are%20tasks%20that,a%20specific%20date%20and%20time.

natesinger commented 1 year ago

@Valkerse As we discussed and you identified, the error originated from a connector timeout. The fix was to check the connector status prior to making the query, and if the connector is dead, to re-instantiate it.

https://github.com/Shift-Cyber/Bits/pull/19/commits/f43642ebdf136ab13f28d9083b985553a5cfa6c3