diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 33b0596..c3b851a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -17,7 +17,6 @@ "features": { "ghcr.io/devcontainers/features/git:1": {}, "ghcr.io/devcontainers/features/github-cli:1": {}, - "ghcr.io/devcontainers/features/python:1": {} }, "customizations": { "vscode": { @@ -31,7 +30,7 @@ "settings": { // "python.editor.defaultFormatter": "ms-python.autopep8", "[python]": { - "editor.defaultFormatter": "ms-python.autopep8", + "editor.defaultFormatter": "ms-python.python", "editor.formatOnSave": true }, "autopep8.args": [ diff --git a/.gitignore b/.gitignore index a54fa06..dfb251c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ src/.env .ipynb_checkpoints discord.py *.db -pics \ No newline at end of file +pics +*.egg-info \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index a14af3b..0000000 --- a/README.md +++ /dev/null @@ -1,71 +0,0 @@ -# Overview - -Kwaylon lives in a Docker container - -- `docker-compose.yml` - - Used to easily run the container with some preset configurations -- `Dockerfile` - - Used by `docker-compose` to (re)build the container, if necessary - - Runs `src/main.py` as it's [CMD](https://docs.docker.com/engine/reference/builder/#cmd) -- `src/main.py` - - Handles getting the login token from an environment variable - - Connects event callbacks to Kwaylon methods - - Runs the Discord client -- `kwaylon.Kwaylon(Client)` - - Defines the logic - -# Operation - -## Messages - -Messages are each handled separately with the `Kwaylon.handle_message` callback, which applies the following logic - -1. `Kwaylon.read_command` - Used to manually force Kwaylon to read N days backwards in each `TextChannel` and record the reactions to the database. -2. `Kwaylon.respond_to_joke` -3. `Kwaylon.respond_to_emoji` - Used for the emoji leaderboard commands - -### Read Command -Looks for a mention of the bot with "read N days" - -### Respond to Jokes - -Iterates through each object that inherits from `kwaylon.jokes.Joke` - -### Respond to Emoji Command - -# Files - -## File Structure - -Files are ultimately stored on the NAS in `/home/Kwaylon` for the `john` user, which is mounted to `/mnt/Kwaylon` on the -Raspberry Pi - -``` -└── ./Kwaylon - ├── data - │ └── messages.db - ├── src - | ├── .env - | ├── kwaylon - | └── main.py - ├── docker-compose.yml - └── Dockerfile -``` - -## Message Database - -The path of the message database defaults to working with the [file structure](#file-structure) above although it can -also be passed into the `Kwaylon` constructor using the `db_path` argument. - -## Mounting on Raspberry Pi - -Run [`dietpi-drive_manager`](https://dietpi.com/docs/dietpi_tools/#dietpi-drive-manager) for access to the wizard for -mounting network drives in DietPi. - -- `Add network drive` -- `samba` -- `JOHN-NAS` -- `home/Kwaylon` -- `john` -- `` -- `/mnt/Kwaylon` \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b0aae0a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,23 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "kwaylon" +authors = [ + {name = "John Lancaster", email = "32917998+jsl12@users.noreply.github.com" } +] +version = "2.0.0" +description = "Alter-ego/nemesis of Kaylon Page" +dependencies = [ + 'discord.py', + 'pandas', + 'nltk', + 'python-dotenv', + 'yfinance', + 'rich' +] +requires-python = ">=3.9" + +[project.scripts] +kwaylon = "kwaylon:main" diff --git a/requirements.txt b/requirements.txt index afbe35c..524a175 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,10 +4,6 @@ discord.py nltk python-dotenv -# stockquotes yfinance -beautifulsoup4 -requests -lxml rich \ No newline at end of file diff --git a/src/kwaylon/__init__.py b/src/kwaylon/__init__.py index 4a05064..3a14815 100644 --- a/src/kwaylon/__init__.py +++ b/src/kwaylon/__init__.py @@ -1,3 +1,26 @@ -from .jokes import Joke, GifJoke +import asyncio +import logging +import os + +from dotenv import load_dotenv + +from .jokes import GifJoke, Joke from .kwaylon import Kwaylon from .reactions import ReactionData + + +def main(token_var: str = 'DISCORD_TOKEN'): + load_dotenv() + loop = asyncio.new_event_loop() + loop.create_task( + Kwaylon.create_and_start( + os.getenv(token_var), + logging.DEBUG + ) + ) + logging.getLogger('discord').setLevel(logging.WARNING) + logging.getLogger('urllib3').setLevel(logging.INFO) + try: + loop.run_forever() + except KeyboardInterrupt: + pass diff --git a/src/main.py b/src/main.py deleted file mode 100644 index 9a6390c..0000000 --- a/src/main.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/local/bin/python - -import asyncio -import logging -import os - -from dotenv import load_dotenv - -from kwaylon import Kwaylon - -if __name__ == '__main__': - load_dotenv() - loop = asyncio.new_event_loop() - loop.create_task( - Kwaylon.create_and_start( - os.getenv('DISCORD_TOKEN'), - logging.DEBUG - ) - ) - logging.getLogger('discord').setLevel(logging.WARNING) - logging.getLogger('urllib3').setLevel(logging.INFO) - try: - loop.run_forever() - except KeyboardInterrupt: - pass