diff --git a/.github/workflows/lint-and-format.yml b/.github/workflows/lint-and-format.yml new file mode 100644 index 0000000..ba5e198 --- /dev/null +++ b/.github/workflows/lint-and-format.yml @@ -0,0 +1,31 @@ +name: Lint Code + +on: + push: + branches: + - main + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.x + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install black flake8 + + - name: Format with black + run: black . + + - name: Lint with flake8 + run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + continue-on-error: false \ No newline at end of file diff --git a/nonebot_plugin_calc24/file_handle.py b/nonebot_plugin_calc24/file_handle.py index 37d84b3..b127053 100644 --- a/nonebot_plugin_calc24/file_handle.py +++ b/nonebot_plugin_calc24/file_handle.py @@ -1,9 +1,11 @@ from pathlib import Path import json + def file_path(file): return Path(__file__).resolve().parent / file + class file_handle: def file_reading(self, file: str, key: str): try: diff --git a/nonebot_plugin_calc24/xj_calc24.py b/nonebot_plugin_calc24/xj_calc24.py index 08eb1b9..894c810 100644 --- a/nonebot_plugin_calc24/xj_calc24.py +++ b/nonebot_plugin_calc24/xj_calc24.py @@ -5,7 +5,10 @@ file_handle = file_handle() legal_data_array = file_handle.file_reading("calc24-data.json", "data") -new_continuous_legal_data = {tuple(arr): None for arr in legal_data_array} +if legal_data_array is None: + raise ValueError("文件读取错误") +else: + new_continuous_legal_data = {tuple(arr): None for arr in legal_data_array} def check_if_in_dict(array): @@ -17,7 +20,6 @@ def check_if_in_dict(array): def random_number_generator(): intdata = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13] a_data = random.sample(intdata, 4) - # a_data = [1,1,1,1] if check_if_in_dict(a_data): return random.sample(intdata, 4) return a_data diff --git a/pyproject.toml b/pyproject.toml index a1cf3f7..d4500b0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nonebot-plugin-calc24" -version = "1.3.12" +version = "1.3.13" description = "A 24-point game plugin implemented using NoneBot." authors = ["AwAjie <139576615+ajdgg@users.noreply.github.com>"]