Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Harambot on Unraid #158

Open
cazar86 opened this issue Aug 27, 2024 · 3 comments
Open

Running Harambot on Unraid #158

cazar86 opened this issue Aug 27, 2024 · 3 comments

Comments

@cazar86
Copy link

cazar86 commented Aug 27, 2024

Hello, this is a nice bot, and I have enjoyed using it in the past. Harambot was running last year when I configured it on Unraid. I was able to add a container and add the environment variables manually. I see there are some new variables for HARAMBOT_KEY, and it wanted a port. I was able to get the guild configured but now when I run the commands I see the following in the logs of the container:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/discord/app_commands/commands.py", line 857, in _do_call
    return await self._callback(self.binding, interaction, **params)  # type: ignore
  File "/usr/local/lib/python3.10/site-packages/harambot/cogs/yahoo.py", line 44, in wrapper
    guild = Guild.get_or_none(
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 6838, in get_or_none
    return cls.get(*query, **filters)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 6833, in get
    return sq.get()
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 7285, in get
    return clone.execute(database)[0]
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 4580, in __getitem__
    self.fill_cache(item if item > 0 else 0)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 4628, in fill_cache
    iterator.next()
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 4683, in next
    self.cursor_wrapper.iterate()
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 4603, in iterate
    result = self.process_row(row)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 7914, in process_row
    data = super(ModelObjectCursorWrapper, self).process_row(row)
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 7880, in process_row
    result[attr] = converters[i](row[i])
  File "/usr/local/lib/python3.10/site-packages/harambot/database/fields.py", line 16, in python_value
    return f.decrypt(value.encode()).decode()
  File "/usr/local/lib/python3.10/site-packages/cryptography/fernet.py", line 84, in decrypt
    timestamp, data = Fernet._get_unverified_token_data(token)
  File "/usr/local/lib/python3.10/site-packages/cryptography/fernet.py", line 118, in _get_unverified_token_data
    raise InvalidToken
cryptography.fernet.InvalidToken

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/discord/app_commands/tree.py", line 1310, in _call
    await command._invoke_with_namespace(interaction, namespace)
  File "/usr/local/lib/python3.10/site-packages/discord/app_commands/commands.py", line 883, in _invoke_with_namespace
    return await self._do_call(interaction, transformed_values)
  File "/usr/local/lib/python3.10/site-packages/discord/app_commands/commands.py", line 876, in _do_call
    raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'standings' raised an exception: InvalidToken:
@DMcP89
Copy link
Owner

DMcP89 commented Aug 28, 2024

@cazar86 what are you using for your bot's database and how did you generate the value for HARAMBOT_KEY? We've introduced encryption for the access_token and refresh_token columns in v0.4.0, HARAMBOT_KEY is what stores the key the bot will use to encrypt and decrypt these values. From the stack trace it looks like it might be an issue with your key. You can use the following command in bash to generate a key that fits the requirements:

head -c 32 /dev/urandom | base64 | tr -d '=' | tr '+/' '-_'

@cazar86
Copy link
Author

cazar86 commented Sep 6, 2024

I am using linuxserver/mariadb container. Ver 15.1 Distrib 10.11.8-MariaDB. I tried to use the key provided from your command and still no luck, it doesn't create the tables in my harambot database, it is empty. The first lines I see in the log when launching the harambot container:

[2024-09-06 03:02:08] [WARNING ] discord.ext.commands.bot: Privileged message content intent is missing, commands may not work as expected.
[2024-09-06 03:02:08] [INFO    ] discord.client: logging in using static token
[2024-09-06 03:02:10] [INFO    ] discord.gateway: Shard ID None has connected to Gateway (Session ID: a76e61264f976799f45505402001b7ba).
[2024-09-06 03:02:12] [ERROR   ] discord.client: Ignoring exception in on_ready
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/peewee.py", line 3322, in execute_sql
    cursor.execute(sql, params or ())
  File "/usr/local/lib/python3.10/site-packages/MySQLdb/cursors.py", line 179, in execute
    res = self._query(mogrified_query)
  File "/usr/local/lib/python3.10/site-packages/MySQLdb/cursors.py", line 330, in _query
    db.query(q)
  File "/usr/local/lib/python3.10/site-packages/MySQLdb/connections.py", line 261, in query
    _mysql.connection.query(self, query)
MySQLdb.OperationalError: (4161, "Unknown data type: 'NOT'")

My container variables:

  -e HOST_OS="Unraid"
  -e HOST_HOSTNAME="Unraid_Hostname"
  -e HOST_CONTAINERNAME="Harambot"
  -e 'DISCORD_TOKEN'='Discord Token'
  -e 'YAHOO_KEY'='Yahoo Key'
  -e 'YAHOO_SECRET'='Yahoo Secret'
  -e 'DATABASE_URL'='mysql://user:password@IP:Port/harambot'
  -e 'LOGLEVEL'='DEBUG'
  -e 'HARAMBOT_KEY'='Key provided from command'
  -e 'PORT'='10000'
  -l net.unraid.docker.managed=dockerman
  -l net.unraid.docker.icon='https://raw.githubusercontent.com/DMcP89/harambot/main/assests/harambot-1.jpg' 'dmcp89/harambot:latest'

@DMcP89
Copy link
Owner

DMcP89 commented Sep 6, 2024

Can you try generating the key using this python script?
from cryptography.fernet import Fernet fernet_key = Fernet.generate_key() print(fernet_key.decode())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants