@@ -40,6 +40,8 @@ async def setup(self, ctx):
4040 c = await self .bot .modmail_guild .create_text_channel (name = 'bot-logs' , category = categ )
4141 await c .edit (topic = 'You can delete this channel if you set up your own log channel.' )
4242 await c .send ('Use the `config set log_channel_id` command to set up a custom log channel.' )
43+ self .bot .config ['main_category_id' ] = categ .id
44+ await self .bot .config .update ()
4345
4446 await ctx .send ('Successfully set up server.' )
4547
@@ -156,6 +158,9 @@ async def _close(self, ctx, *, after: UserFriendlyTime=None):
156158 Silently close a thread (no message)
157159 - `close silently`
158160 - `close in 10m silently`
161+
162+ Cancel closing a thread:
163+ - close cancel
159164 """
160165
161166 thread = await self .bot .threads .find (channel = ctx .channel )
@@ -167,6 +172,14 @@ async def _close(self, ctx, *, after: UserFriendlyTime=None):
167172 close_after = (after .dt - now ).total_seconds () if after else 0
168173 message = after .arg if after else None
169174 silent = str (message ).lower () in {'silent' , 'silently' }
175+ cancel = str (message ).lower () == 'cancel'
176+
177+ if cancel and thread .close_task is not None and not thread .close_task .cancelled ():
178+ thread .close_task .cancel ()
179+ await ctx .send (embed = discord .Embed (color = discord .Color .red (), description = 'Scheduled close has been cancelled.' ))
180+ return
181+ elif cancel :
182+ return await ctx .send (embed = discord .Embed (color = discord .Color .red (), description = 'This thread has not already been scheduled to close.' ))
170183
171184 if after and after .dt > now :
172185 await self .send_scheduled_close_message (ctx , after , silent )
@@ -177,6 +190,105 @@ async def _close(self, ctx, *, after: UserFriendlyTime=None):
177190 message = message ,
178191 silent = silent ,
179192 )
193+
194+ @commands .command (aliases = ['alert' ])
195+ async def notify (self , ctx , * , role = None ):
196+ """Notify a given role or yourself to the next thread message received.
197+
198+ Once a thread message is received you will be pinged once only.
199+ """
200+ thread = await self .bot .threads .find (channel = ctx .channel )
201+ if thread is None :
202+ return
203+
204+ if not role :
205+ mention = ctx .author .mention
206+ elif role .lower () in ('here' , 'everyone' ):
207+ mention = '@' + role
208+ else :
209+ converter = commands .RoleConverter ()
210+ role = await converter .convert (ctx , role )
211+ mention = role .mention
212+
213+ if str (thread .id ) not in self .bot .config ['notification_squad' ]:
214+ self .bot .config ['notification_squad' ][str (thread .id )] = []
215+
216+ mentions = self .bot .config ['notification_squad' ][str (thread .id )]
217+
218+ if mention in mentions :
219+ return await ctx .send (embed = discord .Embed (color = discord .Color .red (), description = f'{ mention } is already going to be mentioned.' ))
220+
221+ mentions .append (mention )
222+ await self .bot .config .update ()
223+
224+ em = discord .Embed (color = discord .Color .green ())
225+ em .description = f'{ mention } will be mentioned on the next message received.'
226+ await ctx .send (embed = em )
227+
228+ @commands .command (aliases = ['sub' ])
229+ async def subscribe (self , ctx , * , role = None ):
230+ """Subscribes yourself or a given role to be notified when thread messages are received.
231+ You will be pinged for every thread message recieved until you unsubscribe.
232+ """
233+ thread = await self .bot .threads .find (channel = ctx .channel )
234+ if thread is None :
235+ return
236+
237+ if not role :
238+ mention = ctx .author .mention
239+ elif role .lower () in ('here' , 'everyone' ):
240+ mention = '@' + role
241+ else :
242+ converter = commands .RoleConverter ()
243+ role = await converter .convert (ctx , role )
244+ mention = role .mention
245+
246+ if str (thread .id ) not in self .bot .config ['subscriptions' ]:
247+ self .bot .config ['subscriptions' ][str (thread .id )] = []
248+
249+ mentions = self .bot .config ['subscriptions' ][str (thread .id )]
250+
251+ if mention in mentions :
252+ return await ctx .send (embed = discord .Embed (color = discord .Color .red (), description = f'{ mention } is already subscribed to this thread.' ))
253+
254+ mentions .append (mention )
255+ await self .bot .config .update ()
256+
257+ em = discord .Embed (color = discord .Color .green ())
258+ em .description = f'{ mention } is now subscribed to be notified of all messages received.'
259+ await ctx .send (embed = em )
260+
261+ @commands .command (aliases = ['unsub' ])
262+ async def unsubscribe (self , ctx , * , role = None ):
263+ """Unsubscribes a given role or yourself from a thread."""
264+ thread = await self .bot .threads .find (channel = ctx .channel )
265+ if thread is None :
266+ return
267+
268+ if not role :
269+ mention = ctx .author .mention
270+ elif role .lower () in ('here' , 'everyone' ):
271+ mention = '@' + role
272+ else :
273+ converter = commands .RoleConverter ()
274+ role = await converter .convert (ctx , role )
275+ mention = role .mention
276+
277+ if str (thread .id ) not in self .bot .config ['subscriptions' ]:
278+ self .bot .config ['subscriptions' ][str (thread .id )] = []
279+
280+ mentions = self .bot .config ['subscriptions' ][str (thread .id )]
281+
282+ if mention not in mentions :
283+ return await ctx .send (embed = discord .Embed (color = discord .Color .red (), description = f'{ mention } is not already subscribed to this thread.' ))
284+
285+ mentions .remove (mention )
286+ await self .bot .config .update ()
287+
288+ em = discord .Embed (color = discord .Color .green ())
289+ em .description = f'{ mention } is now unsubscribed to this thread.'
290+ await ctx .send (embed = em )
291+
180292
181293 @commands .command ()
182294 async def nsfw (self , ctx ):
@@ -205,7 +317,7 @@ async def logs(self, ctx, *, member: Union[discord.Member, discord.User, obj]=No
205317 logs = await self .bot .modmail_api .get_user_logs (user .id )
206318
207319 if not any (not e ['open' ] for e in logs ):
208- return await ctx .send ('This user has no previous logs.' )
320+ return await ctx .send (embed = discord . Embed ( color = discord . Color . red (), description = 'This user does not have any previous logs' ) )
209321
210322 em = discord .Embed (color = discord .Color .green ())
211323 em .set_author (name = 'Previous Logs' , icon_url = icon_url )
@@ -306,7 +418,7 @@ async def contact(self, ctx, *, user: Union[discord.Member, discord.User]):
306418
307419 exists = await self .bot .threads .find (recipient = user )
308420 if exists :
309- return await ctx .send ('Thread already exists.' )
421+ return await ctx .send (embed = discord . Embed ( color = discord . Color . red (), description = 'A thread for this user already exists.') )
310422 else :
311423 thread = await self .bot .threads .create (user , creator = ctx .author )
312424
0 commit comments