55from typing import TYPE_CHECKING
66
77from bot .ext import Context , Response , commands
8- from bot .utils import StringTools
8+ from bot .utils import Role , StringTools
99
1010from .translations import Translations
1111
@@ -29,11 +29,14 @@ async def component_command_error(self, payload: commands.CommandErrorPayload) -
2929 def guards_component (self , ctx : commands .Context ) -> bool : # NOQA
3030 return True
3131
32+ async def component_before_invoke (self , ctx : Context ) -> None :
33+ self .translations .ctx_set (ctx )
34+
3235 @commands .group (name = "set" , aliases = [], invoke_fallback = True )
3336 async def set (self , ctx : Context , * , args ) -> Response :
3437 return self .translations .Exceptions .echo (ctx , args )
3538
36- @set .command (name = "mention" , aliases = [])
39+ @set .command (name = "mention" , aliases = [], pipeble = False )
3740 async def set_mention (self , ctx : Context , * , args : str ) -> Response :
3841 translations = self .translations .Mention
3942 if args .lower () not in ["on" , "off" ]:
@@ -58,7 +61,7 @@ async def set_city(self, ctx: Context, *, args: str) -> Response:
5861 await ctx .user .save ()
5962 return translations .city_added (ctx )
6063
61- @set .command (name = "nick" , aliases = ["nickname" ])
64+ @set .command (name = "nick" , aliases = ["nickname" ], pipeble = False )
6265 async def set_nick (self , ctx : Context , * , args : str ) -> Response :
6366 translations = self .translations .Nick
6467 nickname = args
@@ -74,7 +77,7 @@ async def set_nick(self, ctx: Context, *, args: str) -> Response:
7477 await ctx .user .save ()
7578 return translations .nick_changed (ctx )
7679
77- @set .command (name = "color" , aliases = [])
80+ @set .command (name = "color" , aliases = [], pipeble = False )
7881 async def set_color (self , ctx : Context , * , args : str ) -> Response :
7982 translations = self .translations .Color
8083 if args .lower () == "remove" :
@@ -87,7 +90,7 @@ async def set_color(self, ctx: Context, *, args: str) -> Response:
8790 await ctx .user .save ()
8891 return translations .color_changed (ctx , color )
8992
90- @set .command (name = "reminder" , aliases = [])
93+ @set .command (name = "reminder" , aliases = [], pipeble = False )
9194 async def set_reminder (self , ctx : Context , * , args : str ) -> Response :
9295 translations = self .translations .Reminder
9396 if args .lower () not in ["on" , "off" ]:
@@ -101,6 +104,115 @@ async def set_reminder(self, ctx: Context, *, args: str) -> Response:
101104 await ctx .user .save ()
102105 return translations .reminder_off (ctx )
103106
107+ @commands .guard ([Role .admin ])
108+ @set .command (name = "banword" , aliases = [])
109+ async def set_banword (self , ctx : Context , action : str , * , args : str ) -> Response :
110+ translations = self .translations .Banword
111+ words = translations .add_remove_lang ()
112+ _words = self .StringTools .extract_words_simple (args )
113+ add , remove , clean = words .get ("add" ), words .get ("remove" ), words .get ("clean" )
114+ channel = self .bot .channels [ctx .channel .name .lower ()]
115+ if channel .removed :
116+ return translations .who ()
117+ if action .lower () not in ["add" , "remove" , "clean" , * clean , * add , * remove ]:
118+ await self ._send_bug (ctx , ctx .channel .name )
119+ return translations .add_remove (action )
120+ if action .lower () in ["add" , * add ]:
121+ for world in _words :
122+ channel .banwords [world ] = int (ctx .author .id )
123+ await channel .save ()
124+ return translations .added ()
125+ elif action .lower () in ["remove" , * remove ]:
126+ for world in _words :
127+ channel .banwords .pop (world )
128+ await channel .save ()
129+ return translations .removed ()
130+ elif action .lower () in ["clean" , * clean ]:
131+ channel .banwords = {}
132+ return translations .cleaned ()
133+ else :
134+ return translations .what (action )
135+
136+ @commands .guard ([Role .admin ])
137+ @set .command (name = "enable" , aliases = ["disable" ], pipeble = False )
138+ async def set_enable_disable (self , ctx : Context , arg : str ) -> Response :
139+ translations = self .translations .Enable
140+ channel = self .bot .channels [ctx .channel .name .lower ()]
141+ invoked = ctx .invoked_with .lower ()
142+ protected_commands = {"set" , "enable" , "disable" , "help" , "start" , "stop" }
143+ if arg .lower () in protected_commands :
144+ return translations .why (arg )
145+ if arg .lower () == "all" :
146+ if invoked == "set enable" :
147+ channel .disabled .clear ()
148+ await channel .save ()
149+ return translations .all_enabled ()
150+ elif invoked == "set disable" :
151+ for cmd in ctx .bot .commands :
152+ if ctx .bot .commands [cmd ].name not in protected_commands :
153+ channel .disabled [ctx .bot .commands [cmd ].name .lower ()] = int (ctx .author .id )
154+ await channel .save ()
155+ return translations .all_disabled ()
156+ command_to_manage = ctx .bot .get_command (arg .lower ())
157+ if not command_to_manage :
158+ return translations .no_command (arg )
159+ if invoked == "set enable" :
160+ if command_to_manage .name not in channel .disabled :
161+ return translations .command_already_enabled (arg )
162+ channel .disabled .pop (command_to_manage .name .lower (), None )
163+ await channel .save ()
164+ return translations .command_enabled (arg )
165+ elif invoked == "set disable" :
166+ if command_to_manage .name in protected_commands :
167+ return translations .why (arg )
168+ if command_to_manage .name in channel .disabled :
169+ return translations .command_already_disabled (arg )
170+ channel .disabled [command_to_manage .name .lower ()] = int (ctx .author .id )
171+ await channel .save ()
172+ return translations .command_disabled (arg )
173+ return translations .options ()
174+
175+ @commands .guard ([Role .admin ])
176+ @set .command (name = "prefix" , aliases = [], pipeble = False )
177+ async def set_prefix (self , ctx : Context , arg : str ) -> Response :
178+ translations = self .translations .Prefix
179+ prefix_size = 2
180+ if len (arg ) >= prefix_size :
181+ return translations .too_long (arg , prefix_size )
182+ channel = self .bot .channels [ctx .channel .name .lower ()]
183+ channel .prefix = arg
184+ await channel .save ()
185+ return translations .prefix_changed (arg )
186+
187+ @commands .guard ([Role .admin ])
188+ @set .command (name = "start" , aliases = ["on" , "stop" , "off" ], pipeble = False , whispable = True )
189+ async def set_start_stop (self , ctx : Context ) -> Response :
190+ translations = self .translations .StartStop
191+ invoked = ctx .invoked_with .lower ()
192+ channel = self .bot .channels [ctx .channel .name .lower ()]
193+ if invoked .lower () in ["set start" , "set on" ]:
194+ if channel .online :
195+ return translations .already_on ()
196+ channel .online = True
197+ await channel .save ()
198+ return translations .started ()
199+ elif invoked .lower () in ["set stop" , "set off" ]:
200+ await channel .save ()
201+ if channel .online :
202+ channel .online = False
203+ await channel .save ()
204+ return translations .stopped ()
205+ return translations .already_off ()
206+ return translations .shrug ()
207+
208+ async def _send_bug (self , ctx : Context , name : str ):
209+ if self .bot .mock :
210+ return None
211+ fake_exc = self .translations .SupportTools .fake_stacktrace (
212+ f"Somehow a command has invoked for removed channel: { name } "
213+ )
214+ return await self .bot .CommandHandler .send_bug (ctx , fake_exc )
215+
104216
105217async def setup (bot : Gorenmu ) -> None :
106218 await bot .add_component (SetCmd (bot ))
0 commit comments