@@ -138,7 +138,7 @@ def get_name(base_dir: str, path: str):
138138
139139@cache_with_expiration (180 )
140140async def get_airbase (server : Server , name : str ) -> dict :
141- return await server .send_to_dcs_sync ({"command" : "getAirbase" , "name" : name })
141+ return await server .send_to_dcs_sync ({"command" : "getAirbase" , "name" : name }, timeout = 60 )
142142
143143async def wh_category_autocomplete (interaction : discord .Interaction , current : str ) -> list [app_commands .Choice [str ]]:
144144 if not await interaction .command ._check_can_run (interaction ):
@@ -187,14 +187,17 @@ class Mission(Plugin[MissionEventListener]):
187187
188188 def __init__ (self , bot : DCSServerBot , listener : Type [MissionEventListener ] = None ):
189189 super ().__init__ (bot , listener )
190+ self .lock = asyncio .Lock ()
191+
192+ async def cog_load (self ) -> None :
193+ await super ().cog_load ()
190194 self .update_channel_name .add_exception_type (AttributeError )
191195 self .update_channel_name .start ()
192196 self .afk_check .start ()
193197 self .check_for_unban .add_exception_type (psycopg .DatabaseError )
194198 self .check_for_unban .start ()
195199 self .expire_token .add_exception_type (psycopg .DatabaseError )
196200 self .expire_token .start ()
197- self .lock = asyncio .Lock ()
198201 if self .bot .locals .get ('autorole' , {}):
199202 self .check_roles .add_exception_type (psycopg .DatabaseError )
200203 self .check_roles .add_exception_type (discord .errors .DiscordException )
@@ -305,7 +308,7 @@ async def read_passwords() -> dict:
305308 await interaction .response .defer ()
306309 mission_info = await server .send_to_dcs_sync ({
307310 "command" : "getMissionDetails"
308- })
311+ }, timeout = 60 )
309312 mission_info ['passwords' ] = await read_passwords ()
310313 report = Report (self .bot , self .plugin_name , 'briefing.json' )
311314 env = await report .render (mission_info = mission_info , server_name = server .name , interaction = interaction )
@@ -939,7 +942,7 @@ async def fog(self, interaction: discord.Interaction,
939942 if thickness is None and visibility is None :
940943 ret = await server .send_to_dcs_sync ({
941944 "command" : "getFog"
942- })
945+ }, timeout = 60 )
943946 else :
944947 if thickness and thickness < 100 :
945948 await interaction .followup .send (_ ("Thickness has to be in the range 100-5000" ))
@@ -951,7 +954,7 @@ async def fog(self, interaction: discord.Interaction,
951954 "command" : "setFog" ,
952955 "thickness" : thickness if thickness is not None else - 1 ,
953956 "visibility" : visibility if visibility is not None else - 1
954- })
957+ }, timeout = 60 )
955958 await interaction .followup .send (_ ("Current Fog Settings:\n - Thickness: {thickness:.2f}m\n - Visibility:\t {visibility:.2f}m" ).format (
956959 thickness = ret ['thickness' ], visibility = ret ['visibility' ]), ephemeral = ephemeral )
957960
@@ -1016,7 +1019,7 @@ async def fog_animation(self, interaction: discord.Interaction,
10161019 (key , value ["visibility" ], value ["thickness" ])
10171020 for key , value in fog .items ()
10181021 ]
1019- })
1022+ }, timeout = 60 )
10201023 message = _ ('The following preset was applied: {}.' ).format (view .result [0 ])
10211024 await interaction .followup .send (message , ephemeral = ephemeral )
10221025 finally :
@@ -1085,7 +1088,7 @@ async def airbase_info(self, interaction: discord.Interaction,
10851088 data = await _server .send_to_dcs_sync ({
10861089 "command" : "getAirbase" ,
10871090 "name" : airbase ['name' ]
1088- })
1091+ }, timeout = 60 )
10891092 colors = {
10901093 0 : "dark_gray" ,
10911094 1 : "red" ,
@@ -1130,7 +1133,7 @@ async def atis(self, interaction: discord.Interaction,
11301133 "x" : airbase ['position' ]['x' ],
11311134 "y" : airbase ['position' ]['y' ],
11321135 "z" : airbase ['position' ]['z' ]
1133- })
1136+ }, timeout = 60 )
11341137 report = Report (self .bot , self .plugin_name , 'atis.json' )
11351138 env = await report .render (airbase = airbase , data = data , server = _server )
11361139 msg = await interaction .original_response ()
@@ -1145,7 +1148,7 @@ async def atis(self, interaction: discord.Interaction,
11451148 async def capture (self , interaction : discord .Interaction ,
11461149 server : app_commands .Transform [Server , utils .ServerTransformer (
11471150 status = [Status .RUNNING , Status .PAUSED ])],
1148- idx : int , coalition : Literal ['Red' , 'Blue' , 'Neutral' ] | None = None ):
1151+ idx : int , coalition : Literal ['Red' , 'Blue' , 'Neutral' ]):
11491152 if server .status not in [Status .RUNNING , Status .PAUSED ]:
11501153 # noinspection PyUnresolvedReferences
11511154 await interaction .response .send_message (_ ("Server {} is not running." ).format (server .display_name ),
@@ -1155,11 +1158,21 @@ async def capture(self, interaction: discord.Interaction,
11551158 # noinspection PyUnresolvedReferences
11561159 await interaction .response .defer (ephemeral = utils .get_ephemeral (interaction ))
11571160 airbase = server .current_mission .airbases [idx ]
1161+ data = await server .send_to_dcs_sync ({
1162+ "command" : "getAirbase" ,
1163+ "name" : airbase ['name' ]
1164+ }, timeout = 60 )
1165+ ret_coalition = 'Red' if data ['coalition' ] == 1 else 'Blue' if data ['coalition' ] == 2 else 'Neutral'
1166+ if ret_coalition == coalition :
1167+ await interaction .followup .send (_ ('Airbase \" {}\" belonged to coalition {} already.' ).format (
1168+ airbase ['name' ], coalition .lower ()), ephemeral = True )
1169+ return
1170+
11581171 await server .send_to_dcs_sync ({
11591172 "command" : "captureAirbase" ,
11601173 "name" : airbase ['name' ],
11611174 "coalition" : 1 if coalition == 'Red' else 2 if coalition == 'Blue' else 0
1162- })
1175+ }, timeout = 60 )
11631176 await interaction .followup .send (
11641177 _ ("Airbase \" {}\" : Coalition changed to **{}**.\n :warning: Auto-capturing is now **disabled**!" ).format (
11651178 airbase ['name' ], coalition .lower ()))
@@ -1173,28 +1186,28 @@ async def manage_items(server: Server, airbase: dict, category: str, item: str |
11731186 "command" : "getWarehouseLiquid" ,
11741187 "name" : airbase ['name' ],
11751188 "item" : int (item )
1176- })
1189+ }, timeout = 60 )
11771190 else :
11781191 return await server .send_to_dcs_sync ({
11791192 "command" : "getWarehouseItem" ,
11801193 "name" : airbase ['name' ],
11811194 "item" : item
1182- })
1195+ }, timeout = 60 )
11831196 else :
11841197 if category == 'liquids' :
11851198 return await server .send_to_dcs_sync ({
11861199 "command" : "setWarehouseLiquid" ,
11871200 "name" : airbase ['name' ],
11881201 "item" : int (item ),
11891202 "value" : value * 1000
1190- })
1203+ }, timeout = 60 )
11911204 else :
11921205 return await server .send_to_dcs_sync ({
11931206 "command" : "setWarehouseItem" ,
11941207 "name" : airbase ['name' ],
11951208 "item" : item ,
11961209 "value" : value
1197- })
1210+ }, timeout = 60 )
11981211
11991212 @staticmethod
12001213 async def manage_category (server : Server , airbase : dict , category : str , value : int | None = None ) -> None :
@@ -1276,7 +1289,7 @@ async def warehouse(self, interaction: discord.Interaction,
12761289 data = await _server .send_to_dcs_sync ({
12771290 "command" : "getAirbase" ,
12781291 "name" : airbase ['name' ]
1279- })
1292+ }, timeout = 60 )
12801293
12811294 if not category or category == 'liquids' :
12821295 Info .render_liquids (embed , data )
@@ -2540,10 +2553,10 @@ async def handle_warehouse_uploads(self, message: discord.Message):
25402553 await message .channel .send (_ ("Aborted." ))
25412554 return
25422555
2543- data = await server .send_to_dcs_sync ({"command" : "getMissionSituation" })
2556+ data = await server .send_to_dcs_sync ({"command" : "getMissionSituation" }, timeout = 60 )
25442557 airports = data .get ('coalitions' , {}).get (coalition , {}).get ('airbases' )
25452558 elif match .group (1 ).upper () in ['RED' , 'BLUE' ]:
2546- data = await server .send_to_dcs_sync ({"command" : "getMissionSituation" })
2559+ data = await server .send_to_dcs_sync ({"command" : "getMissionSituation" }, timeout = 60 )
25472560 airports = data .get ('coalitions' , {}).get (match .group (1 ).upper (), {}).get ('airbases' )
25482561 elif len (match .group (1 )) == 4 :
25492562 icao = match .group (1 ).upper ()
0 commit comments