-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/pr_refactor'
# Conflicts: # src/main.py # src/module/button.py # src/resources/const.py
- Loading branch information
Showing
128 changed files
with
186,081 additions
and
7,006 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# See https://pre-commit.com for more information | ||
# See https://pre-commit.com/hooks.html for more hooks | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.5.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: check-added-large-files | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
# Ruff version. | ||
rev: v0.2.1 | ||
hooks: | ||
# Run the linter. | ||
- id: ruff | ||
args: [ "--select", "I", "--fix" ] | ||
# Run the formatter. | ||
- id: ruff-format | ||
- repo: https://github.com/pre-commit/mirrors-mypy | ||
rev: v1.8.0 | ||
hooks: | ||
- id: mypy | ||
language: system | ||
pass_filenames: false | ||
- repo: local | ||
hooks: | ||
- id: pytest-check | ||
stages: [push] | ||
types: [python] | ||
name: pytest-check | ||
entry: python -m pytest | ||
language: system | ||
pass_filenames: false | ||
always_run: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,24 +7,28 @@ A Discord bot to receive Tekken 8 frame data primarily from [Wavu Wiki](https:// | |
Clone this repository to a Linux server that has Python 3.10.0+ and install the dependencies with: | ||
|
||
```bash | ||
git clone [email protected]:TLNBS2405/heihachi.git | ||
git clone [email protected]:AbhijeetKrishnan/heihachi.git | ||
cd heihachi | ||
python3 -m pip install -r requirements.txt | ||
python3 -m pip install . | ||
``` | ||
### Config | ||
|
||
The Heihachi bot is configured using the `src/resources/config.json` file. A sample file is provided in `src/resources/config.sample.json`. You should copy this file to `src/resources/config.json` and fill in the required fields. | ||
The Heihachi bot is configured using a `config.json` file. A sample file is provided in `static/config.sample.json`. | ||
|
||
```json | ||
{ | ||
"DISCORD_TOKEN": "YOUR_DISCORD_TOKEN", | ||
"FEEDBACK_CHANNEL_ID": "feedback_channel_id", | ||
"ACTION_CHANNEL_ID": "action_channel_id" | ||
"ACTION_CHANNEL_ID": "action_channel_id", | ||
"BLACKLIST": ["user1", "user2"], | ||
"ID_BLACKLIST": [0, 1] | ||
} | ||
``` | ||
You can obtain your own Discord token by creating a Discord bot ([instructions](https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token)). | ||
You can obtain your own Discord token by creating a Discord bot ([instructions](https://discordpy.readthedocs.io/en/stable/discord.html)). | ||
The bot must have the "Message Content Intent" enabled on the Discord Developer Portal. The bot uses a permissions integer | ||
of 551903315968 (Send Messages, Embed Links, Use Slash Commands, Use Embedded Activities). | ||
|
||
The `FEEDBACK_CHANNEL_ID` is the channel where the bot will send feedback messages. The bot supports the slash command `/fd feedback <message>` to allow users to provide feedback on the bot's operation or frame data, and have the bot repost it in a dedicated channel for easier tracking. | ||
The `FEEDBACK_CHANNEL_ID` is the channel where the bot will send feedback messages. The bot supports the slash command `/feedback <message>` to allow users to provide feedback on the bot's operation or frame data, and have the bot repost it in a dedicated channel for easier tracking. | ||
|
||
![Feedback](/assets/feedback_example.png) | ||
|
||
|
@@ -34,14 +38,16 @@ The `ACTION_CHANNEL_ID` is the channel where the bot will send "actioned" messag | |
|
||
Channel IDs can be obtained by right-clicking on a channel and selecting "Copy Channel ID" at the very bottom. | ||
|
||
### Running the bot | ||
_The bot must have permission to read and send messages in the feedback and action channels._ | ||
|
||
The `BLACKLIST` and `ID_BLACKLIST` are lists of user IDs and channel IDs respectively, who are not allowed to use the bot. This is useful for blacklisting users who abuse the bot or are otherwise not welcome. | ||
|
||
The executable is `src/main.py`. Don't forget to put this project into your `PYTHONPATH`! | ||
### Running the bot | ||
|
||
Execute the below command from the project's root directory - | ||
|
||
```bash | ||
PYTHONPATH=. python3 src/main.py | ||
python3 src/main.py path/to/config.json --export_dir path/to/export/dir | ||
``` | ||
|
||
## Commands | ||
|
@@ -50,6 +56,19 @@ The bot supports the following slash commands - | |
|
||
| Command | Description | | ||
| --- | --- | | ||
| `/fd <character> <move>` | Get frame data of a move from a character | | ||
| `/<character> <move>` | Same as above | | ||
| `/fd <character> <move>` | Get frame data of a particular character's move | | ||
| `/feedback <message>` | Send feedback to the bot owner | | ||
|
||
## Testing | ||
|
||
To install the development dependencies, run - | ||
|
||
```bash | ||
python3 -m pip install -e .[dev] | ||
``` | ||
|
||
The bot uses `pytest` for testing. To run the tests, execute the below command from the project's root directory - | ||
|
||
```bash | ||
python3 -m pytest | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
[build-system] | ||
requires = ["hatchling"] | ||
build-backend = "hatchling.build" | ||
|
||
[project] | ||
name = "heihachi" | ||
version = "2.1.0" | ||
description = "A Discord bot to receive Tekken 8 frame data primarily from Wavu Wiki" | ||
readme = "README.md" | ||
authors = [ | ||
{ name = "TLNBS2405", email = "[email protected]" }, | ||
{ name = "Abhijeet Krishnan", email = "[email protected]" }, | ||
] | ||
license = {file = "LICENSE"} | ||
classifiers = [ | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3.10", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
] | ||
requires-python = ">= 3.10" | ||
dependencies = [ | ||
"discord.py", | ||
"beautifulsoup4", | ||
"Requests", | ||
"lxml", | ||
"fast-autocomplete[levenshtein]" | ||
] | ||
|
||
[project.urls] | ||
Repository = "https://github.com/AbhijeetKrishnan/heihachi" | ||
"Bug Tracker" = "https://github.com/AbhijeetKrishnan/heihachi/issues" | ||
|
||
[project.optional-dependencies] | ||
dev = [ | ||
"pre-commit", | ||
"mypy", | ||
"pytest", | ||
"types-requests" | ||
] | ||
|
||
[tool.ruff] | ||
target-version = "py310" | ||
line-length = 127 | ||
src = ["src"] | ||
|
||
[tool.mypy] | ||
python_version = "3.10" | ||
strict = true | ||
warn_return_any = true | ||
warn_unused_configs = true | ||
warn_redundant_casts = true | ||
warn_unreachable = true | ||
pretty = true | ||
exclude = [ | ||
"build", | ||
"dist", | ||
"venv", | ||
"tests", | ||
] | ||
files = [ | ||
"src/**/*.py", | ||
] | ||
ignore_missing_imports = true | ||
|
||
[tool.pytest.ini_options] | ||
minversion = "6.0" | ||
addopts = [ | ||
"-ra -q", | ||
"--import-mode=importlib" | ||
] | ||
testpaths = [ | ||
"src/**/tests" | ||
] | ||
console_output_style = "progress" |
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .json_directory import JsonDirectory as JsonDirectory | ||
from .wavu import Wavu as Wavu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .json_directory import JsonDirectory as JsonDirectory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import json | ||
import logging | ||
import os | ||
|
||
import requests | ||
|
||
from framedb import Character, CharacterName, FrameService, Move, Url | ||
|
||
logger = logging.getLogger("main") | ||
|
||
|
||
class JsonDirectory(FrameService): | ||
def __init__(self, char_meta_dir: str, movelist_dir: str) -> None: | ||
self.name = f"JSON Directory ({movelist_dir})" | ||
self.icon = None | ||
self.movelist_dir = movelist_dir | ||
|
||
try: | ||
with open(char_meta_dir, "r") as f: | ||
self.character_meta = json.load(f) | ||
except Exception as e: | ||
raise Exception(f"Could not load character meta data from {char_meta_dir}") from e | ||
|
||
def get_frame_data(self, character: CharacterName, session: requests.Session | None = None) -> Character: | ||
# TODO: duplicated across wavu and json_directory -> refactor | ||
target_char_meta = None | ||
for char_meta in self.character_meta: | ||
if char_meta["name"] == character.value: | ||
target_char_meta = char_meta | ||
break | ||
if target_char_meta is None: | ||
raise Exception(f"Could not find character meta data for {character.value}") | ||
|
||
name = CharacterName(target_char_meta["name"]) | ||
portrait = target_char_meta["portrait"] | ||
page = target_char_meta["page"] | ||
|
||
filepath = os.path.abspath(os.path.join(self.movelist_dir, f"{character.value}.json")) | ||
with open(filepath, encoding="utf-8") as move_file: | ||
move_file_contents = json.load(move_file) | ||
movelist = { | ||
move["id"]: Move( | ||
id=move["id"], | ||
name=move["name"], | ||
input=move["input"], | ||
target=move["target"], | ||
damage=move["damage"], | ||
on_block=move["on_block"], | ||
on_hit=move["on_hit"], | ||
on_ch=move["on_ch"], | ||
startup=move["startup"], | ||
recovery=move["recovery"], | ||
notes=move["notes"], | ||
image=move["image"], | ||
video=move["video"], | ||
alias=move["alias"], | ||
) | ||
for move in move_file_contents | ||
} | ||
char = Character(name, portrait, movelist, page) | ||
return char | ||
|
||
def get_move_url(self, character: Character, move: Move) -> Url | None: | ||
return None |
Oops, something went wrong.