3
3
4
4
import discord
5
5
from redbot .core import Config , checks , commands
6
+ from redbot .core .utils .menus import start_adding_reactions
6
7
from redbot .core .utils .mod import is_mod_or_superior as is_mod
8
+ from redbot .core .utils .predicates import ReactionPredicate
7
9
8
10
log = logging .getLogger ("red.rhomelab.timeout" )
9
11
@@ -16,7 +18,8 @@ def __init__(self):
16
18
default_guild = {
17
19
"logchannel" : None ,
18
20
"report" : False ,
19
- "timeoutrole" : None
21
+ "timeoutrole" : None ,
22
+ "timeout_channel" : None
20
23
}
21
24
self .config .register_guild (** default_guild )
22
25
self .config .register_member (
@@ -137,6 +140,11 @@ async def timeout_add(
137
140
138
141
async def timeout_remove (self , ctx : commands .Context , user : discord .Member , reason : str ):
139
142
"""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
+
140
148
# Fetch and define user's previous roles.
141
149
user_roles = []
142
150
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
174
182
}
175
183
await self .report_handler (ctx , user , action_info )
176
184
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
+
177
196
# Commands
178
197
179
198
@commands .guild_only ()
@@ -202,7 +221,7 @@ async def timeoutset_report(self, ctx: commands.Context, choice: str):
202
221
These reports will be sent to the configured log channel as an embed.
203
222
The embed will specify the user's details and the moderator who executed the command.
204
223
205
- Set log channel with `[p]timeoutset logchannel`.
224
+ Set log channel with `[p]timeoutset logchannel` before enabling reporting .
206
225
207
226
Example:
208
227
- `[p]timeoutset report enable`
@@ -240,6 +259,19 @@ async def timeoutset_role(self, ctx: commands.Context, role: discord.Role):
240
259
await self .config .guild (ctx .guild ).timeoutrole .set (role .id )
241
260
await ctx .tick ()
242
261
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
+
243
275
@timeoutset .command (name = "list" , aliases = ["show" , "view" , "settings" ])
244
276
@checks .mod ()
245
277
async def timeoutset_list (self , ctx : commands .Context ):
@@ -248,6 +280,7 @@ async def timeoutset_list(self, ctx: commands.Context):
248
280
log_channel = await self .config .guild (ctx .guild ).logchannel ()
249
281
report = await self .config .guild (ctx .guild ).report ()
250
282
timeout_role = ctx .guild .get_role (await self .config .guild (ctx .guild ).timeoutrole ())
283
+ timeout_channel = await self .config .guild (ctx .guild ).timeout_channel ()
251
284
252
285
if log_channel :
253
286
log_channel = f"<#{ log_channel } >"
@@ -264,6 +297,11 @@ async def timeoutset_list(self, ctx: commands.Context):
264
297
else :
265
298
report = "Disabled"
266
299
300
+ if timeout_channel :
301
+ timeout_channel = f"<#{ timeout_channel } >"
302
+ else :
303
+ timeout_channel = "Unconfigured"
304
+
267
305
# Build embed
268
306
embed = discord .Embed (
269
307
color = (await ctx .embed_colour ())
@@ -287,6 +325,11 @@ async def timeoutset_list(self, ctx: commands.Context):
287
325
value = timeout_role ,
288
326
inline = True
289
327
)
328
+ embed .add_field (
329
+ name = "Timeout Channel" ,
330
+ value = timeout_channel ,
331
+ inline = True
332
+ )
290
333
291
334
# Send embed
292
335
await ctx .send (embed = embed )
0 commit comments