diff --git a/.env.example b/.env.example index 9042e8f..db1cd4c 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,6 @@ # Token of the Discord bot BOT_TOKEN= -# Log level (see logging library, defaults to INFO if not defined) +# Log level (see logging library, defaults to INFO if not defined or invalid) LOG_LEVEL=DEBUG # Server host and port to check if the bot is up SERVER_HOST=localhost diff --git a/.gitignore b/.gitignore index 5656ffd..38ba337 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,15 @@ -# Ignore the dotenv +# Dotenv file *.env -# Ignore IDE folder +# IDE folder .idea/ .vscode/ -# Ignore Python's cache +# Python's venv +venv/ + +# Python's cache __pycache__/ -# Ignore the logs folder +# Logs folder logs/ diff --git a/README.md b/README.md index 133a5d6..8ededd9 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,12 @@ [![Python lint](https://github.com/Zalk0/ChouetteBot-discord/actions/workflows/python-app.yml/badge.svg?branch=main)](https://github.com/Zalk0/ChouetteBot-discord/actions/workflows/python-app.yml) Just some random project of doing a Discord bot using [discord.py](https://github.com/Rapptz/discord.py). -You need to have Python 3.11 because I use a function that was introduced in this version (in the logging library) ! +You need to have Python 3.8 or higher installed (required by discord.py) ! -Clone the projet and install the requirements : +Clone the projet and install the requirements (preferably in a [venv](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments)) : ``` -git clone https://github.com/Zalk0/ChouetteBot-discord.git +git clone git@github.com:Zalk0/ChouetteBot-discord.git cd ChouetteBot-discord pip install -r requirements.txt ``` @@ -18,7 +18,7 @@ Before launching the bot, you need to fill in a **`.env`** file (using the [temp I provide in the repo) and put a Discord bot token inside. To have one, go to the [Discord Developer Portal](https://discord.com/developers) and create a new application. Go to the Bot section and click the Reset Token button, you can now claim the token. -You also have to enable all the Privileged Gateway Intents as I assume they're enabled in the code. +You also have to enable all the Privileged Gateway Intents as I assume they're enabled in the code (or change them). --- After having done all this you can launch the bot : diff --git a/bot.py b/bot.py index f63b084..1d46031 100644 --- a/bot.py +++ b/bot.py @@ -19,7 +19,8 @@ def __init__(self): # Define the bot debug log level self.bot_logger = logging.getLogger('bot') - self.bot_logger.setLevel(logging.getLevelNamesMapping().get(self.config['LOG_LEVEL']) or logging.INFO) + log_level = logging.getLevelName(self.config['LOG_LEVEL']) + self.bot_logger.setLevel(log_level if isinstance(log_level, int) else logging.INFO) # Set intents for the bot intents = discord.Intents.all() @@ -98,9 +99,8 @@ async def start_server(self): # Set some basic headers for security headers = { - "X-Frame-Options": "DENY", "X-Content-Type-Options": "nosniff", - "Content-Security-Policy": "default-src 'self'; frame-ancestors 'none'" + "Content-Security-Policy": "default-src 'none'; frame-ancestors 'none'" } # Remove the Server header and apply the headers