@@ -88,8 +88,11 @@ async def label_autocomplete(interaction: discord.Interaction, current: str) ->
8888 config = interaction .client .cogs ['Admin' ].get_config (server )
8989 choices : list [app_commands .Choice [str ]] = [
9090 app_commands .Choice (name = x ['label' ], value = x ['label' ]) for x in config ['downloads' ]
91- if ((not current or current .casefold () in x ['label' ].casefold ()) and
92- (not x .get ('discord' ) or utils .check_roles (x ['discord' ], interaction .user )))
91+ if (
92+ (not current or current .casefold () in x ['label' ].casefold ()) and
93+ (not x .get ('discord' ) or utils .check_roles (x ['discord' ], interaction .user )) and
94+ (not x .get ('restricted' , False ) or not server .node .locals .get ('restrict_commands' , False ))
95+ )
9396 ]
9497 return choices [:25 ]
9598 except Exception as ex :
@@ -131,6 +134,14 @@ async def file_autocomplete(interaction: discord.Interaction, current: str) -> l
131134 config = next (x for x in config ['downloads' ] if x ['label' ] == label )
132135 except StopIteration :
133136 return []
137+
138+ # check if we are allowed to display the list
139+ if (
140+ (config .get ('discord' ) and not utils .check_roles (config ['discord' ], interaction .user )) or
141+ (config .get ('restricted' , False ) and server .node .locals .get ('restrict_commands' , False ))
142+ ):
143+ return []
144+
134145 base_dir = utils .format_string (config ['directory' ], server = server )
135146 exp_base , file_list = await server .node .list_directory (base_dir , pattern = config ['pattern' ], traverse = True )
136147 choices : list [app_commands .Choice [str ]] = [
@@ -357,6 +368,7 @@ async def bans(self, interaction: discord.Interaction, user: str):
357368
358369 @dcs .command (description = _ ('Update your DCS installations' ))
359370 @app_commands .guild_only ()
371+ @app_commands .check (utils .restricted )
360372 @utils .app_has_role ('DCS Admin' )
361373 @app_commands .describe (warn_time = _ ("Time in seconds to warn users before shutdown" ))
362374 @app_commands .autocomplete (branch = get_dcs_branches )
@@ -435,6 +447,7 @@ async def update(self, interaction: discord.Interaction,
435447
436448 @dcs .command (name = 'install' , description = _ ('Install modules in your DCS server' ))
437449 @app_commands .guild_only ()
450+ @app_commands .check (utils .restricted )
438451 @utils .app_has_role ('Admin' )
439452 @app_commands .autocomplete (module = available_modules_autocomplete )
440453 async def _install (self , interaction : discord .Interaction ,
@@ -457,6 +470,7 @@ async def _install(self, interaction: discord.Interaction,
457470
458471 @dcs .command (name = 'uninstall' , description = _ ('Uninstall modules from your DCS server' ))
459472 @app_commands .guild_only ()
473+ @app_commands .check (utils .restricted )
460474 @utils .app_has_role ('Admin' )
461475 @app_commands .autocomplete (module = installed_modules_autocomplete )
462476 async def _uninstall (self , interaction : discord .Interaction ,
@@ -504,7 +518,10 @@ async def download(self, interaction: discord.Interaction,
504518 await interaction .response .defer (thinking = True , ephemeral = ephemeral )
505519 config = next (x for x in self .get_config (server )['downloads' ] if x ['label' ] == what )
506520 # double-check if that user can really download these files
507- if config .get ('discord' ) and not utils .check_roles (config ['discord' ], interaction .user ):
521+ if (
522+ (config .get ('discord' ) and not utils .check_roles (config ['discord' ], interaction .user )) or
523+ (config .get ('restricted' , False ) and server .node .locals .get ('restrict_commands' , False ))
524+ ):
508525 raise app_commands .CheckFailure ()
509526 if what == 'Missions' :
510527 base_dir = await server .get_missions_dir ()
@@ -757,6 +774,7 @@ async def run_on_nodes(self, interaction: discord.Interaction, method: str, node
757774
758775 @node_group .command (description = _ ('Shuts a specific node down' ))
759776 @app_commands .guild_only ()
777+ @app_commands .check (utils .restricted )
760778 @utils .app_has_role ('Admin' )
761779 async def shutdown (self , interaction : discord .Interaction ,
762780 node : Optional [app_commands .Transform [Node , utils .NodeTransformer ]] = None ):
@@ -767,6 +785,7 @@ async def shutdown(self, interaction: discord.Interaction,
767785
768786 @node_group .command (description = _ ('Restarts a specific node' ))
769787 @app_commands .guild_only ()
788+ @app_commands .check (utils .restricted )
770789 @utils .app_has_role ('Admin' )
771790 async def restart (self , interaction : discord .Interaction ,
772791 node : Optional [app_commands .Transform [Node , utils .NodeTransformer ]] = None ):
@@ -862,6 +881,7 @@ async def _node_online(node_name: str):
862881
863882 @node_group .command (description = _ ('Upgrade DCSServerBot' ))
864883 @app_commands .guild_only ()
884+ @app_commands .check (utils .restricted )
865885 @utils .app_has_role ('Admin' )
866886 async def upgrade (self , interaction : discord .Interaction ,
867887 node : Optional [app_commands .Transform [Node , utils .NodeTransformer ]] = None ):
@@ -887,6 +907,7 @@ async def upgrade(self, interaction: discord.Interaction,
887907
888908 @node_group .command (description = _ ('Run a shell command on a node' ))
889909 @app_commands .guild_only ()
910+ @app_commands .check (utils .restricted )
890911 @utils .app_has_role ('Admin' )
891912 async def shell (self , interaction : discord .Interaction ,
892913 node : app_commands .Transform [Node , utils .NodeTransformer ],
@@ -910,6 +931,7 @@ async def shell(self, interaction: discord.Interaction,
910931
911932 @node_group .command (description = _ ("Add/create an instance\n " ))
912933 @app_commands .guild_only ()
934+ @app_commands .check (utils .restricted )
913935 @utils .app_has_role ('Admin' )
914936 @app_commands .autocomplete (name = utils .InstanceTransformer (unused = True ).autocomplete )
915937 @app_commands .describe (name = _ ("Either select an existing instance or enter the name of a new one" ))
@@ -965,6 +987,7 @@ async def add_instance(self, interaction: discord.Interaction,
965987
966988 @node_group .command (description = _ ("Delete an instance\n " ))
967989 @app_commands .guild_only ()
990+ @app_commands .check (utils .restricted )
968991 @utils .app_has_role ('Admin' )
969992 async def delete_instance (self , interaction : discord .Interaction ,
970993 node : app_commands .Transform [Node , utils .NodeTransformer ],
@@ -1002,6 +1025,7 @@ async def delete_instance(self, interaction: discord.Interaction,
10021025
10031026 @node_group .command (description = _ ("Rename an instance\n " ))
10041027 @app_commands .guild_only ()
1028+ @app_commands .check (utils .restricted )
10051029 @utils .app_has_role ('Admin' )
10061030 async def rename_instance (self , interaction : discord .Interaction ,
10071031 node : app_commands .Transform [Node , utils .NodeTransformer ],
@@ -1044,6 +1068,7 @@ async def rename_instance(self, interaction: discord.Interaction,
10441068
10451069 @node_group .command (description = _ ("Shows CPU topology" ))
10461070 @app_commands .guild_only ()
1071+ @app_commands .check (utils .restricted )
10471072 @app_commands .check (lambda interaction : sys .platform == 'win32' )
10481073 @utils .app_has_role ('Admin' )
10491074 async def cpuinfo (self , interaction : discord .Interaction ,
@@ -1057,6 +1082,7 @@ async def cpuinfo(self, interaction: discord.Interaction,
10571082
10581083 @plug .command (name = 'install' , description = _ ("Install Plugin" ))
10591084 @app_commands .guild_only ()
1085+ @app_commands .check (utils .restricted )
10601086 @app_commands .autocomplete (plugin = installable_plugins )
10611087 @utils .app_has_role ('Admin' )
10621088 async def _install (self , interaction : discord .Interaction , plugin : str ):
@@ -1074,6 +1100,7 @@ async def _install(self, interaction: discord.Interaction, plugin: str):
10741100
10751101 @plug .command (name = 'uninstall' , description = _ ("Uninstall Plugin" ))
10761102 @app_commands .guild_only ()
1103+ @app_commands .check (utils .restricted )
10771104 @app_commands .autocomplete (plugin = uninstallable_plugins )
10781105 @utils .app_has_role ('Admin' )
10791106 async def _uninstall (self , interaction : discord .Interaction , plugin : str ):
@@ -1091,6 +1118,7 @@ async def _uninstall(self, interaction: discord.Interaction, plugin: str):
10911118
10921119 @plug .command (description = _ ('Reload Plugin' ))
10931120 @app_commands .guild_only ()
1121+ @app_commands .check (utils .restricted )
10941122 @utils .app_has_role ('Admin' )
10951123 @app_commands .autocomplete (plugin = plugins_autocomplete )
10961124 async def reload (self , interaction : discord .Interaction , plugin : Optional [str ]):
@@ -1220,7 +1248,7 @@ async def on_message(self, message: discord.Message):
12201248 # read the default config if there is any
12211249 config = self .get_config ().get ('uploads' , {})
12221250 # check if upload is enabled
1223- if not config .get ('enabled' , True ):
1251+ if not config .get ('enabled' , True ) or self . node . locals . get ( 'restricted' ) :
12241252 return
12251253 # check if the user has the correct role to upload, defaults to Admin
12261254 if not utils .check_roles (config .get ('discord' , self .bot .roles ['Admin' ]), message .author ):
0 commit comments