33
44import discord
55from redbot .core import Config , checks , commands
6+ from redbot .core .utils .menus import start_adding_reactions
67from redbot .core .utils .mod import is_mod_or_superior as is_mod
8+ from redbot .core .utils .predicates import ReactionPredicate
79
810log = logging .getLogger ("red.rhomelab.timeout" )
911
@@ -16,7 +18,8 @@ def __init__(self):
1618 default_guild = {
1719 "logchannel" : None ,
1820 "report" : False ,
19- "timeoutrole" : None
21+ "timeoutrole" : None ,
22+ "timeout_channel" : None
2023 }
2124 self .config .register_guild (** default_guild )
2225 self .config .register_member (
@@ -137,6 +140,11 @@ async def timeout_add(
137140
138141 async def timeout_remove (self , ctx : commands .Context , user : discord .Member , reason : str ):
139142 """Remove user from timeout"""
143+
144+ # Retrieve timeout channel
145+ timeout_channel_config = await self .config .guild (ctx .guild ).timeout_channel ()
146+ timeout_channel = ctx .guild .get_channel (timeout_channel_config )
147+
140148 # Fetch and define user's previous roles.
141149 user_roles = []
142150 for role in await self .config .member (user ).roles ():
@@ -174,6 +182,17 @@ async def timeout_remove(self, ctx: commands.Context, user: discord.Member, reas
174182 }
175183 await self .report_handler (ctx , user , action_info )
176184
185+ # Ask if user wishes to clear the timeout channel if they've defined one
186+ if timeout_channel :
187+ archive_query = await ctx .send (f"Do you wish to clear the contents of { timeout_channel .mention } ?" )
188+ start_adding_reactions (archive_query , ReactionPredicate .YES_OR_NO_EMOJIS )
189+
190+ pred = ReactionPredicate .yes_or_no (archive_query , ctx .author )
191+ await ctx .bot .wait_for ("reaction_add" , check = pred )
192+ if pred .result is True :
193+ purge = await timeout_channel .purge (bulk = True )
194+ await ctx .send (f"Cleared { len (purge )} messages from { timeout_channel .mention } ." )
195+
177196 # Commands
178197
179198 @commands .guild_only ()
@@ -202,7 +221,7 @@ async def timeoutset_report(self, ctx: commands.Context, choice: str):
202221 These reports will be sent to the configured log channel as an embed.
203222 The embed will specify the user's details and the moderator who executed the command.
204223
205- Set log channel with `[p]timeoutset logchannel`.
224+ Set log channel with `[p]timeoutset logchannel` before enabling reporting .
206225
207226 Example:
208227 - `[p]timeoutset report enable`
@@ -240,6 +259,19 @@ async def timeoutset_role(self, ctx: commands.Context, role: discord.Role):
240259 await self .config .guild (ctx .guild ).timeoutrole .set (role .id )
241260 await ctx .tick ()
242261
262+ @timeoutset .command (name = "timeoutchannel" )
263+ @checks .mod ()
264+ async def timeoutset_timeout_channel (self , ctx : commands .Context , channel : discord .TextChannel ):
265+ """Set the timeout channel.
266+
267+ This is required if you wish to optionaly purge the channel upon removing a user from timeout.
268+
269+ Example:
270+ - `[p]timeoutset timeoutchannel #timeout`
271+ """
272+ await self .config .guild (ctx .guild ).timeout_channel .set (channel .id )
273+ await ctx .tick ()
274+
243275 @timeoutset .command (name = "list" , aliases = ["show" , "view" , "settings" ])
244276 @checks .mod ()
245277 async def timeoutset_list (self , ctx : commands .Context ):
@@ -248,6 +280,7 @@ async def timeoutset_list(self, ctx: commands.Context):
248280 log_channel = await self .config .guild (ctx .guild ).logchannel ()
249281 report = await self .config .guild (ctx .guild ).report ()
250282 timeout_role = ctx .guild .get_role (await self .config .guild (ctx .guild ).timeoutrole ())
283+ timeout_channel = await self .config .guild (ctx .guild ).timeout_channel ()
251284
252285 if log_channel :
253286 log_channel = f"<#{ log_channel } >"
@@ -264,6 +297,11 @@ async def timeoutset_list(self, ctx: commands.Context):
264297 else :
265298 report = "Disabled"
266299
300+ if timeout_channel :
301+ timeout_channel = f"<#{ timeout_channel } >"
302+ else :
303+ timeout_channel = "Unconfigured"
304+
267305 # Build embed
268306 embed = discord .Embed (
269307 color = (await ctx .embed_colour ())
@@ -287,6 +325,11 @@ async def timeoutset_list(self, ctx: commands.Context):
287325 value = timeout_role ,
288326 inline = True
289327 )
328+ embed .add_field (
329+ name = "Timeout Channel" ,
330+ value = timeout_channel ,
331+ inline = True
332+ )
290333
291334 # Send embed
292335 await ctx .send (embed = embed )
0 commit comments