|
1 | 1 | """zeus_upload extension"""
|
2 | 2 |
|
| 3 | +import typing |
| 4 | + |
3 | 5 | import discord
|
| 6 | +from discord.commands import option |
4 | 7 | from discord.ext import commands
|
| 8 | +from discord.utils import basic_autocomplete |
5 | 9 | from pydantic import TypeAdapter, ValidationError
|
6 | 10 |
|
| 11 | +if typing.TYPE_CHECKING: |
| 12 | + from zeusops_bot.discord import ZeusopsBot |
7 | 13 | from zeusops_bot.errors import (
|
8 | 14 | ConfigFileInvalidJson,
|
9 | 15 | ConfigFileNotFound,
|
10 | 16 | ConfigPatchingError,
|
11 | 17 | )
|
12 | 18 | from zeusops_bot.models import ModDetail
|
13 | 19 | from zeusops_bot.reforger_config_gen import ReforgerConfigGenerator, extract_mods
|
14 |
| -from zeusops_bot.settings import ZeusopsBotConfig |
15 | 20 |
|
16 | 21 | modlist_typeadapter = TypeAdapter(list[ModDetail])
|
17 | 22 |
|
18 | 23 |
|
| 24 | +def _autocomplete_missions(ctx: discord.AutocompleteContext) -> list[str]: |
| 25 | + """List known missions |
| 26 | +
|
| 27 | + Used to populate the autocomplete list in /zeus-set-mission. |
| 28 | +
|
| 29 | + TODO: Return list[discord.OptionChoice] instead? |
| 30 | + """ |
| 31 | + return ctx.bot.reforger_confgen.list_missions() |
| 32 | + |
| 33 | + |
19 | 34 | class ZeusUpload(commands.Cog):
|
20 | 35 | """ZeusUpload cog for handling mission uploads"""
|
21 | 36 |
|
22 |
| - def __init__(self, bot: discord.Bot, config: ZeusopsBotConfig): |
| 37 | + def __init__(self, bot: "ZeusopsBot", reforger_confgen: ReforgerConfigGenerator): |
23 | 38 | """Initialise the cog"""
|
24 | 39 | self.bot = bot
|
25 |
| - self.config = config |
26 |
| - self.reforger_confgen = ReforgerConfigGenerator( |
27 |
| - base_config_file=config.reforger.reference_config, |
28 |
| - target_folder=config.reforger.config_folder, |
29 |
| - ) |
| 40 | + self.reforger_confgen = reforger_confgen |
30 | 41 |
|
31 | 42 | @commands.slash_command(name="zeus-upload")
|
32 | 43 | @discord.option(
|
@@ -91,7 +102,16 @@ async def zeus_upload(
|
91 | 102 | await ctx.respond(f"Mission uploaded successfully under {path=}")
|
92 | 103 |
|
93 | 104 | @commands.slash_command(name="zeus-set-mission")
|
94 |
| - async def zeus_set_mission(self, ctx: discord.ApplicationContext, filename: str): |
| 105 | + @option( |
| 106 | + "filename", |
| 107 | + description="Mission filename", |
| 108 | + autocomplete=basic_autocomplete(_autocomplete_missions), |
| 109 | + ) |
| 110 | + async def zeus_set_mission( |
| 111 | + self, |
| 112 | + ctx: discord.ApplicationContext, |
| 113 | + filename: str, |
| 114 | + ): |
95 | 115 | """Activate the given a mission file as a Zeus"""
|
96 | 116 | try:
|
97 | 117 | self.reforger_confgen.zeus_set_mission(filename)
|
|
0 commit comments