Skip to content

Commit e06c5c6

Browse files
committed
CHANGES:
- Mission: you can now define a channel different from the admin channel to upload missions into.
1 parent 00f6bea commit e06c5c6

File tree

4 files changed

+58
-8
lines changed

4 files changed

+58
-8
lines changed

core/utils/discord.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,13 +1594,16 @@ def __init__(self, server: Server, message: discord.Message, pattern: list[str])
15941594
self.server = server
15951595

15961596
@staticmethod
1597-
async def get_server(message: discord.Message) -> Optional[Server]:
1597+
async def get_server(message: discord.Message, channel_id: Optional[int] = None) -> Optional[Server]:
15981598
from services.bot import BotService
15991599
from services.servicebus import ServiceBus
16001600

16011601
bot = ServiceRegistry.get(BotService).bot
16021602
server = bot.get_server(message, admin_only=True)
1603-
if not server and message.channel.id == bot.locals.get('channels', {}).get('admin'):
1603+
if not channel_id:
1604+
channel_id = bot.locals.get('channels', {}).get('admin')
1605+
1606+
if not server and message.channel.id == channel_id:
16041607
bus = ServiceRegistry.get(ServiceBus)
16051608
ctx = await bot.get_context(message)
16061609
server = await utils.server_selection(bus, ctx, title=_("To which server do you want to upload?"))

plugins/mission/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ DEFAULT:
8181
- pilot_death
8282
- shot
8383
- hit
84-
uploads: # Configure how mission uploads are handled
85-
enabled: true # Here you can disable the feature at all (default: true = enabled)
84+
uploads: # Configure how mission uploads are handled
85+
enabled: true # Here you can disable the feature at all (default: true = enabled)
86+
channel: 112233445566778899 # Optional: mission upload channel (default: admin channel)
8687
discord:
87-
- DCS Admin # Define which roles are allowed to upload missions (default: DCS Admin)
88+
- DCS Admin # Define which roles are allowed to upload missions (default: DCS Admin)
8889
```
8990
9091
## Auto-Scanning

plugins/mission/commands.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2091,7 +2091,39 @@ async def on_message(self, message: discord.Message):
20912091
return
20922092

20932093
# check if we are in the correct channel
2094-
server = await MissionUploadHandler.get_server(message)
2094+
server = None
2095+
for node_name, node in self.locals.items():
2096+
if node_name == 'commands':
2097+
continue
2098+
if node_name == DEFAULT_TAG:
2099+
channel = node.get('uploads', {}).get('channel')
2100+
if channel:
2101+
if message.channel.id == channel:
2102+
server = await MissionUploadHandler.get_server(message, channel)
2103+
break
2104+
elif 'uploads' in node:
2105+
channel = node.get('uploads', {}).get('channel')
2106+
if message.channel.id == channel:
2107+
server = next((
2108+
server for server in self.bus.servers.values()
2109+
if server.instance.name == node_name
2110+
), None)
2111+
break
2112+
else:
2113+
for instance_name, instance in node.items():
2114+
channel = instance.get('uploads', {}).get('channel')
2115+
if message.channel.id == channel:
2116+
server = next((
2117+
server for server in self.bus.servers.values()
2118+
if server.instance.name == instance_name
2119+
), None)
2120+
break
2121+
else:
2122+
continue
2123+
break
2124+
else:
2125+
server = await MissionUploadHandler.get_server(message)
2126+
20952127
if not server:
20962128
return
20972129

plugins/mission/schemas/mission_schema.yaml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
schema;default_schema:
1+
schema;instance_schema:
2+
type: map
3+
func: is_node
4+
nullable: false
5+
mapping:
6+
regex;(.+):
7+
include: 'element_schema'
8+
9+
schema;element_schema:
210
type: map
311
nullable: false
412
mapping:
@@ -12,6 +20,7 @@ schema;default_schema:
1220
nullable: false
1321
mapping:
1422
enabled: {type: bool, nullable: false}
23+
channel: {type: int, nullable: false}
1524
discord:
1625
type: seq
1726
sequence:
@@ -23,8 +32,13 @@ func: check_main_structure
2332
nullable: false
2433
mapping:
2534
DEFAULT:
26-
include: 'default_schema'
35+
include: 'element_schema'
2736
commands:
2837
include: 'commands_schema'
2938
chat_commands:
3039
include: 'chat_commands_schema'
40+
regex;(.+):
41+
type: any
42+
func: any_of
43+
nullable: false
44+
enum: ['element_schema', 'instance_schema']

0 commit comments

Comments
 (0)