Skip to content

Commit 421d3ee

Browse files
committed
Add ability to take notes resolves #128
1 parent 602a185 commit 421d3ee

File tree

5 files changed

+54
-24
lines changed

5 files changed

+54
-24
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
# v2.9.0
8+
9+
### Added
10+
- New command `note` will add a system message to your thread logs. This is useful for noting the context of a conversation.
711

812
# v2.8.1
913
### Fixed

bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
SOFTWARE.
2323
"""
2424

25-
__version__ = '2.8.1'
25+
__version__ = '2.9.0'
2626

2727
import asyncio
2828
import textwrap

cogs/modmail.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,15 @@ async def reply(self, ctx, *, msg=''):
377377
thread = await self.bot.threads.find(channel=ctx.channel)
378378
if thread:
379379
await thread.reply(ctx.message)
380+
381+
@commands.command()
382+
@trigger_typing
383+
async def note(self, ctx, *, msg=''):
384+
"""Take a note about the current thread, useful for noting context."""
385+
ctx.message.content = msg
386+
thread = await self.bot.threads.find(channel=ctx.channel)
387+
if thread:
388+
await thread.note(ctx.message)
380389

381390
@commands.command()
382391
async def edit(self, ctx, message_id: Optional[int]=None, *, new_message):

core/clients.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def get_log_url(self, recipient, channel, creator):
151151
}
152152
})
153153

154-
def append_log(self, message, channel_id=''):
154+
def append_log(self, message, channel_id='', type='thread_message'):
155155
channel_id = str(channel_id) or str(message.channel.id)
156156
payload = {
157157
'payload': {
@@ -167,7 +167,8 @@ def append_log(self, message, channel_id=''):
167167
},
168168
# message properties
169169
'content': message.content,
170-
'attachments': [i.url for i in message.attachments]
170+
'attachments': [i.url for i in message.attachments],
171+
'type': type
171172
}
172173
}
173174
return self.request(self.logs + f'/{channel_id}', method='PATCH', payload=payload)
@@ -247,7 +248,7 @@ async def update_config(self, data):
247248
data = {k: v for k, v in data.items() if k in valid_keys}
248249
return await self.db.config.update_one({'bot_id': self.app.user.id}, {'$set': data})
249250

250-
async def append_log(self, message, channel_id=''):
251+
async def append_log(self, message, channel_id='', type='thread_message'):
251252
channel_id = str(channel_id) or str(message.channel.id)
252253
payload = {
253254
'timestamp': str(message.created_at),
@@ -262,7 +263,8 @@ async def append_log(self, message, channel_id=''):
262263
},
263264
# message properties
264265
'content': message.content,
265-
'attachments': [i.url for i in message.attachments]
266+
'attachments': [i.url for i in message.attachments],
267+
'type': type
266268
}
267269

268270
return await self.logs.find_one_and_update(

core/thread.py

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ async def _close(self, closer, silent=False, delete_channel=True,
8989
log_data = await self.bot.modmail_api.post_log(self.channel.id, {
9090
'open': False,
9191
'closed_at': str(datetime.datetime.utcnow()),
92+
'close_message': message,
9293
'closer': {
9394
'id': str(closer.id),
9495
'name': closer.name,
@@ -98,24 +99,23 @@ async def _close(self, closer, silent=False, delete_channel=True,
9899
}
99100
})
100101

101-
if isinstance(log_data, str):
102-
print(log_data) # errored somehow on server
103-
return
104-
105-
if self.bot.selfhosted:
106-
log_url = f"{self.bot.config.log_url.strip('/')}/logs/{log_data['key']}"
107-
else:
108-
log_url = f"https://logs.modmail.tk/{log_data['key']}"
102+
if not isinstance(log_data, str) or log_data is not None:
103+
if self.bot.selfhosted:
104+
log_url = f"{self.bot.config.log_url.strip('/')}/logs/{log_data['key']}"
105+
else:
106+
log_url = f"https://logs.modmail.tk/{log_data['key']}"
109107

110-
user = self.recipient.mention if self.recipient else f'`{self.id}`'
108+
user = self.recipient.mention if self.recipient else f'`{self.id}`'
111109

112-
if log_data['messages']:
113-
msg = str(log_data['messages'][0]['content'])
114-
sneak_peak = msg if len(msg) < 50 else msg[:48] + '...'
110+
if log_data['messages']:
111+
msg = str(log_data['messages'][0]['content'])
112+
sneak_peak = msg if len(msg) < 50 else msg[:48] + '...'
113+
else:
114+
sneak_peak = 'No content'
115+
116+
desc = f"{user} [`{log_data['key']}`]({log_url}): {sneak_peak}"
115117
else:
116-
sneak_peak = 'No content'
117-
118-
desc = f"{user} [`{log_data['key']}`]({log_url}): {sneak_peak}"
118+
desc = "Could not resolve log url."
119119

120120
em = discord.Embed(description=desc, color=discord.Color.red())
121121

@@ -172,6 +172,16 @@ def edit_message(self, message_id, message):
172172
self._edit_thread_message(self.recipient, message_id, message),
173173
self._edit_thread_message(self.channel, message_id, message)
174174
)
175+
176+
async def note(self, message):
177+
if not message.content and not message.attachments:
178+
raise commands.UserInputError
179+
180+
await asyncio.gather(
181+
self.bot.modmail_api.append_log(message, self.channel.id, type='system'),
182+
self.send(message, self.channel, note=True)
183+
)
184+
175185

176186
async def reply(self, message):
177187
if not message.content and not message.attachments:
@@ -204,15 +214,15 @@ async def reply(self, message):
204214

205215
await asyncio.gather(*tasks)
206216

207-
async def send(self, message, destination=None, from_mod=False):
217+
async def send(self, message, destination=None, from_mod=False, note=False):
208218
if self.close_task is not None:
209219
# cancel closing if a thread message is sent.
210220
await self.cancel_closure()
211221
await self.channel.send(embed=discord.Embed(
212222
color=discord.Color.red(),
213223
description='Scheduled close has been cancelled.'))
214224

215-
if not from_mod:
225+
if not from_mod and not note:
216226
self.bot.loop.create_task(
217227
self.bot.modmail_api.append_log(message, self.channel.id)
218228
)
@@ -229,9 +239,11 @@ async def send(self, message, destination=None, from_mod=False):
229239
timestamp=message.created_at
230240
)
231241

242+
system_avatar_url = 'https://discordapp.com/assets/f78426a064bc9dd24847519259bc42af.png'
243+
232244
# store message id in hidden url
233-
em.set_author(name=str(author),
234-
icon_url=author.avatar_url,
245+
em.set_author(name=str(author) if not note else 'Note',
246+
icon_url=author.avatar_url if not note else system_avatar_url,
235247
url=message.jump_url)
236248

237249
image_types = ['.png', '.jpg', '.gif', '.jpeg', '.webp']
@@ -282,6 +294,9 @@ def is_image_url(u, _):
282294
if from_mod:
283295
em.color = discord.Color.green()
284296
em.set_footer(text=f'Moderator')
297+
elif note:
298+
em.color = discord.Color.blurple()
299+
em.set_footer(text=f'System ({author.name})')
285300
else:
286301
em.color = discord.Color.gold()
287302
em.set_footer(text=f'User')

0 commit comments

Comments
 (0)