3
3
from discord .ext import commands
4
4
import datetime
5
5
import dateutil .parser
6
+ import re
7
+ from typing import Optional
6
8
from core .decorators import trigger_typing
7
9
from core .paginator import PaginatorSession
8
10
@@ -104,6 +106,17 @@ async def __del(self, ctx, *, name: str.lower):
104
106
105
107
await ctx .send (embed = em )
106
108
109
+ @commands .command ()
110
+ @commands .has_permissions (manage_channels = True )
111
+ async def move (self , ctx , * , category : discord .CategoryChannel ):
112
+ '''Moves a thread to a specified cateogry.'''
113
+ thread = await self .bot .threads .find (channel = ctx .channel )
114
+ if not thread :
115
+ return await ctx .send ('This is not a modmail thread.' )
116
+
117
+ await thread .channel .edit (category = category )
118
+ await ctx .message .add_reaction ('✅' )
119
+
107
120
@commands .command (name = 'close' )
108
121
@commands .has_permissions (manage_channels = True )
109
122
async def _close (self , ctx ):
@@ -126,7 +139,7 @@ async def _close(self, ctx):
126
139
127
140
# Logging
128
141
categ = self .bot .main_category
129
- log_channel = categ .channels [1 ]
142
+ log_channel = categ .channels [0 ]
130
143
131
144
log_data = await self .bot .modmail_api .post_log (ctx .channel .id , {
132
145
'open' : False , 'closed_at' : str (datetime .datetime .utcnow ()), 'closer' : {
@@ -219,16 +232,35 @@ async def reply(self, ctx, *, msg=''):
219
232
await thread .reply (ctx .message )
220
233
221
234
@commands .command ()
222
- async def edit (self , ctx , message_id : int , * , new_message ):
235
+ async def edit (self , ctx , message_id : Optional [ int ] = None , * , new_message ):
223
236
'''Edit a message that was sent using the reply command.
224
237
225
238
`<message_id>` is the id shown in the footer of thread messages.
226
239
`<new_message>` is the new message that will be edited in.
227
240
'''
228
- thread = self .bot .threads .find (channel = ctx .channel )
229
- if thread and thread .category .name == 'Mod Mail' :
230
- await thread .edit_message (message_id , new_message )
241
+ thread = await self .bot .threads .find (channel = ctx .channel )
242
+ print (message_id , new_message )
243
+ if thread and thread .channel .category .name == 'Mod Mail' :
244
+ linked_message_id = None
245
+
246
+ async for msg in ctx .channel .history ():
247
+ if message_id is None and msg .embeds :
248
+ em = msg .embeds [0 ]
249
+ if 'Moderator' not in str (em .footer .text ):
250
+ continue
251
+ linked_message_id = int (re .findall (r'\d+' , em .author .url )[0 ])
252
+ break
253
+ elif message_id and msg .id == message_id :
254
+ url = msg .embeds [0 ].author .url
255
+ linked_message_id = int (re .findall (r'\d+' , url )[0 ])
256
+ break
231
257
258
+ if not linked_message_id :
259
+ raise commands .UserInputError
260
+
261
+ await thread .edit_message (linked_message_id , new_message )
262
+ await ctx .message .add_reaction ('✅' )
263
+
232
264
@commands .command ()
233
265
@trigger_typing
234
266
@commands .has_permissions (manage_channels = True )
0 commit comments