Skip to content

Commit

Permalink
Organise and add mypy (#4)
Browse files Browse the repository at this point in the history
* Organise to module
* Use future annotations
* Update license, readme, add mypy workflow
* Update inits & setups for extensions. Format to line-length 100
* Fix mypy problems
  • Loading branch information
Tyrannicodin authored Nov 15, 2024
1 parent a162a56 commit 4bee20c
Show file tree
Hide file tree
Showing 26 changed files with 1,125 additions and 373 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SECRET="BlaBlaBlaBlaBlaBlaBlaBlaBlaBlaBlaBla"
2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

24 changes: 24 additions & 0 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: MyPy
on: [push, pull_request]
jobs:
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v3
with:
python-version: 3.12.4
- uses: tsuyoshicho/[email protected]
with:
github_token: ${{ secrets.github_token }}
# Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
reporter: github-pr-review
# Change reporter level if you need.
# GitHub Status Check won't become failure with warning.
level: warning
# Change the current directory to run mypy command.
# mypy command reads setup.cfg or other settings file in this path.
workdir: .

setup_command: pip install -r requirements.txt
setup_method: install
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
__pycache__
*.tmp
*.json
.env

.conda
.venv

.vscode
.*_cache

servers
universe.pkl
695 changes: 674 additions & 21 deletions LICENSE

Large diffs are not rendered by default.

25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
# HC-TCG Bot
This is a discord bot designed for the hermitcraft tcg online server. It has commands that can be used for many things such as deck viewing, card information, admin commands for http://hc-tcg.fly.dev and more.
The HC-TCG Bot is a bot for [hc-tcg online](https://hc-tcg.online). It interfaces with the api and has commands for the official hc-tcg online server.

## Features
- Card and deck information
- Deck of the day competitions
- Bug report management
- Game creation and counting

## Running
To install dependencies, run `pip install -r requirements.txt`
Optionally, also install tqdm using `pip install tqdm` to see progress bars when updating data
Rename .env.example to .env and enter your discord bot key, then create a servers directory. The servers directory contains python files which define a single server object.

It is recommended to run in a virtual environment, such as anaconda or venv.
To install dependencies directly, run `pip install -r requirements.txt`

I recommend first running [update_data.py](/update_data.py) to create a static universe. This will allow the bot to start quickly. To start the actual bot run [main.py](/main.py)
Optionally, also install tqdm using `pip install tqdm` to see a progress bar when loading card data.

## Formatting
For formatting I use ruff, you can access the configuration in ruff.toml
## Formatting and code style
We use ruff for formatting and linting, and mypy for type checking.
```
ruff format
ruff check
mypy -p bot
```
1 change: 1 addition & 0 deletions bot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""HC-TCG online bot."""
22 changes: 22 additions & 0 deletions bot/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Load environment config."""

from __future__ import annotations

import os

import dotenv


class Config:
"""Load environement variables as class."""

def __init__(self: Config) -> None:
"""Load environement variables as class."""
dotenv.load_dotenv()

env = os.environ

self.SECRET: str = env.get("DISCORD_SECRET") or ""


CONFIG = Config()
1 change: 1 addition & 0 deletions bot/exts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Bot extensions."""
Loading

0 comments on commit 4bee20c

Please sign in to comment.