22
33import discord
44from redbot .core import Config , checks , commands
5+ from redbot .core .utils .menus import start_adding_reactions
56from redbot .core .utils .mod import is_mod_or_superior as is_mod
7+ from redbot .core .utils .predicates import ReactionPredicate
68
79
810class Timeout (commands .Cog ):
@@ -13,7 +15,8 @@ def __init__(self):
1315 default_guild = {
1416 "logchannel" : None ,
1517 "report" : False ,
16- "timeoutrole" : None
18+ "timeoutrole" : None ,
19+ "timeout_channel" : None
1720 }
1821 self .config .register_guild (** default_guild )
1922 self .config .register_member (
@@ -105,6 +108,11 @@ async def timeout_add(self, ctx: commands.Context, user: discord.Member, reason:
105108
106109 async def timeout_remove (self , ctx : commands .Context , user : discord .Member , reason : str ):
107110 """Remove user from timeout"""
111+
112+ # Retrieve timeout channel
113+ timeout_channel_config = await self .config .guild (ctx .guild ).timeout_channel ()
114+ timeout_channel = ctx .guild .get_channel (timeout_channel_config )
115+
108116 # Fetch and define user's previous roles.
109117 user_roles = []
110118 for role in await self .config .member (user ).roles ():
@@ -132,6 +140,17 @@ async def timeout_remove(self, ctx: commands.Context, user: discord.Member, reas
132140 }
133141 await self .report_handler (ctx , user , action_info )
134142
143+ # Ask if user wishes to clear the timeout channel if they've defined one
144+ if timeout_channel :
145+ archive_query = await ctx .send (f"Do you wish to clear the contents of { timeout_channel .mention } ?" )
146+ start_adding_reactions (archive_query , ReactionPredicate .YES_OR_NO_EMOJIS )
147+
148+ pred = ReactionPredicate .yes_or_no (archive_query , ctx .author )
149+ await ctx .bot .wait_for ("reaction_add" , check = pred )
150+ if pred .result is True :
151+ purge = await timeout_channel .purge (bulk = True )
152+ await ctx .send (f"Cleared { len (purge )} messages from { timeout_channel .mention } ." )
153+
135154 # Commands
136155
137156 @commands .guild_only ()
@@ -160,7 +179,7 @@ async def timeoutset_report(self, ctx: commands.Context, choice: str):
160179 These reports will be sent to the configured log channel as an embed.
161180 The embed will specify the user's details and the moderator who executed the command.
162181
163- Set log channel with `[p]timeoutset logchannel`.
182+ Set log channel with `[p]timeoutset logchannel` before enabling reporting .
164183
165184 Example:
166185 - `[p]timeoutset report enable`
@@ -198,6 +217,19 @@ async def timeoutset_role(self, ctx: commands.Context, role: discord.Role):
198217 await self .config .guild (ctx .guild ).timeoutrole .set (role .id )
199218 await ctx .tick ()
200219
220+ @timeoutset .command (name = "timeoutchannel" )
221+ @checks .mod ()
222+ async def timeoutset_timeout_channel (self , ctx : commands .Context , channel : discord .TextChannel ):
223+ """Set the timeout channel.
224+
225+ This is required if you wish to optionaly purge the channel upon removing a user from timeout.
226+
227+ Example:
228+ - `[p]timeoutset timeoutchannel #timeout`
229+ """
230+ await self .config .guild (ctx .guild ).timeout_channel .set (channel .id )
231+ await ctx .tick ()
232+
201233 @timeoutset .command (name = "list" )
202234 @checks .mod ()
203235 async def timeoutset_list (self , ctx : commands .Context ):
@@ -206,6 +238,7 @@ async def timeoutset_list(self, ctx: commands.Context):
206238 log_channel = await self .config .guild (ctx .guild ).logchannel ()
207239 report = await self .config .guild (ctx .guild ).report ()
208240 timeout_role = ctx .guild .get_role (await self .config .guild (ctx .guild ).timeoutrole ())
241+ timeout_channel = await self .config .guild (ctx .guild ).timeout_channel ()
209242
210243 if log_channel :
211244 log_channel = f"<#{ log_channel } >"
@@ -222,6 +255,11 @@ async def timeoutset_list(self, ctx: commands.Context):
222255 else :
223256 report = "Disabled"
224257
258+ if timeout_channel :
259+ timeout_channel = f"<#{ timeout_channel } >"
260+ else :
261+ timeout_channel = "Unconfigured"
262+
225263 # Build embed
226264 embed = discord .Embed (
227265 color = (await ctx .embed_colour ())
@@ -245,6 +283,11 @@ async def timeoutset_list(self, ctx: commands.Context):
245283 value = timeout_role ,
246284 inline = True
247285 )
286+ embed .add_field (
287+ name = "Timeout Channel" ,
288+ value = timeout_channel ,
289+ inline = True
290+ )
248291
249292 # Send embed
250293 await ctx .send (embed = embed )
0 commit comments