Skip to content

Commit a93790a

Browse files
committed
Improve logs format
1 parent 61125d4 commit a93790a

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

bot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ async def get_context(self, message, *, cls=commands.Context):
259259
ctx.command = self.all_commands.get(invoker)
260260

261261
if ctx.command is self.get_command('eval') and hasattr(ctx, '_alias_invoked'):
262-
ctx.command.checks = None # Let anyone use the command.
262+
# ctx.command.checks = None # Let anyone use the command.
263+
pass
263264

264265
return ctx
265266

cogs/modmail.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ class Modmail:
1313

1414
def __init__(self, bot):
1515
self.bot = bot
16+
17+
def obj(arg):
18+
return discord.Object(int(arg))
1619

1720
@commands.command()
1821
@trigger_typing
@@ -171,7 +174,7 @@ async def nsfw(self, ctx):
171174
@commands.command()
172175
@commands.has_permissions(manage_messages=True)
173176
@trigger_typing
174-
async def logs(self, ctx, *, member: Union[discord.Member, discord.User]=None):
177+
async def logs(self, ctx, *, member: Union[discord.Member, discord.User, obj]=None):
175178
"""Shows a list of previous modmail thread logs of a member."""
176179

177180
if not member:
@@ -181,13 +184,15 @@ async def logs(self, ctx, *, member: Union[discord.Member, discord.User]=None):
181184

182185
user = member or thread.recipient
183186

187+
icon_url = getattr(user, 'avatar_url', 'https://cdn.discordapp.com/embed/avatars/0.png')
188+
184189
logs = await self.bot.modmail_api.get_user_logs(user.id)
185190

186191
if not any(not e['open'] for e in logs):
187192
return await ctx.send('This user has no previous logs.')
188193

189194
em = discord.Embed(color=discord.Color.green())
190-
em.set_author(name='Previous Logs', icon_url=user.avatar_url)
195+
em.set_author(name='Previous Logs', icon_url=icon_url)
191196

192197
embeds = [em]
193198

@@ -200,20 +205,31 @@ async def logs(self, ctx, *, member: Union[discord.Member, discord.User]=None):
200205
for index, entry in enumerate(closed_logs):
201206
if len(embeds[-1].fields) == 3:
202207
em = discord.Embed(color=discord.Color.green())
203-
em.set_author(name='Previous Logs', icon_url=user.avatar_url)
208+
em.set_author(name='Previous Logs', icon_url=icon_url)
204209
embeds.append(em)
205210

206211
date = dateutil.parser.parse(entry['created_at'])
212+
207213
new_day = date.strftime(r'%d %b %Y')
214+
time = date.strftime(r'%H:%M')
208215

209216
key = entry['key']
210217
user_id = entry['user_id']
211218
log_url = f"https://logs.modmail.tk/{user_id}/{key}"
212219

213-
fmt += f"[`{key}`]({log_url})\n"
220+
truncate = lambda c: c[:47] + '...' if len(c) > 50 else c
221+
222+
if entry['messages']:
223+
short_desc = truncate(entry['messages'][0]['content']) or 'No content'
224+
else:
225+
short_desc = 'No content'
226+
227+
fmt += f"[`[{time}]{key}`]({log_url}) - {short_desc}\n"
228+
229+
print(fmt)
214230

215231
if current_day != new_day or index == len(closed_logs) - 1:
216-
embeds[-1].add_field(name=current_day, value=fmt)
232+
embeds[-1].add_field(name=current_day, value=fmt, inline=False)
217233
current_day = new_day
218234
fmt = ''
219235

@@ -286,9 +302,6 @@ async def contact(self, ctx, *, user: Union[discord.Member, discord.User]):
286302

287303
await ctx.send(embed=em)
288304

289-
def obj(arg):
290-
return discord.Object(int(arg))
291-
292305
@commands.command()
293306
@trigger_typing
294307
@commands.has_permissions(manage_channels=True)

0 commit comments

Comments
 (0)