Skip to content

Commit a630549

Browse files
committed
Unstaged changed after copier update
1 parent 1758359 commit a630549

File tree

3 files changed

+73
-9
lines changed

3 files changed

+73
-9
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ repos:
3131
name: Hadolint (Dockerfile checker)
3232
# Actual Python Linters
3333
- repo: https://github.com/astral-sh/ruff-pre-commit
34-
rev: v0.7.0
34+
rev: v0.11.10
3535
hooks:
3636
- id: ruff-format
3737
- id: ruff
3838
args: ["--fix"]
3939
- repo: https://github.com/pre-commit/mirrors-mypy
40-
rev: v1.12.1
40+
rev: v1.15.0
4141
hooks:
4242
- id: mypy
4343
name: Mypy (Python type-checker)
4444
exclude: 'docs/source/.*\.py'
4545
# Uncomment below if mypy requires extra type stub packages
4646
# additional_dependencies: [types-PyYAML==6.0.12.2]
4747
- repo: https://github.com/igorshubovych/markdownlint-cli
48-
rev: v0.42.0
48+
rev: v0.45.0
4949
hooks:
5050
- id: markdownlint-fix

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ source .venv/bin/activate
3131
zeusops-bot
3232
```
3333

34+
### Config
35+
36+
Suggest the following config via `.env`:
37+
38+
``` shell
39+
export BOT_REFORGER_REFERENCE_CONFIG=data/reference_config.json
40+
export BOT_REFORGER_CONFIG_FOLDER=data/generated/
41+
export BOT_DISCORD_TOKEN=$(pass zeusops/testapp_operationbot_token)
42+
```
43+
3444
## Development
3545

3646
### Python setup

src/zeusops_bot/cli.py

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
"""Command line entrypoint for zeusops-bot"""
22

33
import argparse
4+
import logging
45
import sys
6+
from enum import IntEnum
7+
from pathlib import Path
8+
9+
from zeusops_bot import reforger_config_gen as cmd
10+
from zeusops_bot.discord import ZeusopsBot
11+
from zeusops_bot.errors import ZeusopsBotConfigException
12+
from zeusops_bot.logging import setup_logging
13+
from zeusops_bot.models import ModDetail
14+
from zeusops_bot.settings import ZeusopsBotConfig, load
15+
16+
17+
class Exit(IntEnum):
18+
"""Exit codes for the CLI"""
19+
20+
SUCCESS = 0
21+
FAILURE = 1
522

623

724
def parse_arguments(args: list[str]) -> argparse.Namespace:
@@ -19,18 +36,55 @@ def parse_arguments(args: list[str]) -> argparse.Namespace:
1936
"zeusops-bot",
2037
description="Multipurpose discord bot for the Zeusops community",
2138
)
22-
parser.add_argument("foo", help="Some parameter")
39+
parser.add_argument(
40+
"--debug",
41+
help="Enable debug logging",
42+
action="store_true",
43+
)
2344
return parser.parse_args(args)
2445

2546

2647
def cli(arguments: list[str] | None = None):
2748
"""Run the zeusops_bot cli"""
2849
if arguments is None:
2950
arguments = sys.argv[1:]
30-
args = parse_arguments(arguments)
31-
main(args.foo)
51+
_args = parse_arguments(arguments)
52+
return main(_args.debug)
53+
54+
55+
def main(debug: bool = False):
56+
"""Run the main bot"""
57+
try:
58+
config = load(ZeusopsBotConfig)
59+
except ZeusopsBotConfigException as e:
60+
envvars = e.args[0]
61+
print(f"Missing {len(envvars)} envvars:", file=sys.stderr)
62+
for envvar in envvars:
63+
print(f"- {envvar.upper()}", file=sys.stderr)
64+
return Exit.FAILURE
65+
except Exception:
66+
print("Error while loading the bot's config from envvars", file=sys.stderr)
67+
raise
68+
69+
setup_logging(debug)
70+
71+
bot = ZeusopsBot(config, logging.getLogger("zeusops.discord"))
72+
bot.run() # Token is already in config
3273

3374

34-
def main(foo):
35-
"""Run the program's main command"""
36-
print(f"Foo is: {foo}")
75+
def reforger_upload(
76+
base_config_file: Path,
77+
target_folder: Path,
78+
modlist: list[ModDetail] | None,
79+
scenario_id: str,
80+
filename: str,
81+
):
82+
"""Run the program's /zeus-upload command"""
83+
conf_generator = cmd.ReforgerConfigGenerator(base_config_file, target_folder)
84+
if modlist is not None:
85+
print(f"Loading {len(modlist)} mods, for {scenario_id=}...")
86+
else:
87+
print(f"Loading {scenario_id=}...")
88+
out_path = conf_generator.zeus_upload(scenario_id, filename, modlist)
89+
print(f"Saved under file {out_path.name}")
90+
return Exit.SUCCESS

0 commit comments

Comments
 (0)