Skip to content

Commit 9c77931

Browse files
committed
Add ?logs responded command (#338)
1 parent 1c36d8a commit 9c77931

File tree

4 files changed

+59
-11
lines changed

4 files changed

+59
-11
lines changed

cogs/modmail.py

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717
from core.models import PermissionLevel
1818
from core.paginator import EmbedPaginatorSession
1919
from core.time import UserFriendlyTime, human_timedelta
20-
from core.utils import format_preview, User, create_not_found_embed, format_description, strtobool
20+
from core.utils import (
21+
format_preview,
22+
User,
23+
create_not_found_embed,
24+
format_description,
25+
strtobool,
26+
)
2127

2228
logger = logging.getLogger("Modmail")
2329

@@ -286,7 +292,9 @@ async def snippet_edit(self, ctx, name: str.lower, *, value):
286292
@commands.command()
287293
@checks.has_permissions(PermissionLevel.MODERATOR)
288294
@checks.thread_only()
289-
async def move(self, ctx, category: discord.CategoryChannel, *, specifics: str = None):
295+
async def move(
296+
self, ctx, category: discord.CategoryChannel, *, specifics: str = None
297+
):
290298
"""
291299
Move a thread to another category.
292300
@@ -297,7 +305,7 @@ async def move(self, ctx, category: discord.CategoryChannel, *, specifics: str =
297305
silent = False
298306

299307
if specifics:
300-
silent_words = ['silent', 'silently']
308+
silent_words = ["silent", "silently"]
301309
silent = any(word in silent_words for word in specifics.split())
302310

303311
await thread.channel.edit(category=category, sync_permissions=True)
@@ -311,7 +319,7 @@ async def move(self, ctx, category: discord.CategoryChannel, *, specifics: str =
311319
embed = discord.Embed(
312320
title="Thread Moved",
313321
description=self.bot.config["thread_move_response"],
314-
color=self.bot.main_color
322+
color=self.bot.main_color,
315323
)
316324
await thread.recipient.send(embed=embed)
317325

@@ -718,6 +726,43 @@ async def logs_closed_by(self, ctx, *, user: User = None):
718726
session = EmbedPaginatorSession(ctx, *embeds)
719727
await session.run()
720728

729+
@logs.command(name="responded")
730+
@checks.has_permissions(PermissionLevel.SUPPORTER)
731+
async def logs_responded(self, ctx, *, user: User = None):
732+
"""
733+
Get all logs where the specified user has responded at least once.
734+
735+
If no `user` is provided, the user will be the person who sent this command.
736+
`user` may be a user ID, mention, or name.
737+
"""
738+
user = user if user is not None else ctx.author
739+
740+
entries = []
741+
async for l in self.bot.db.logs.find(
742+
{
743+
"messages": {
744+
"$elemMatch": {
745+
"author.id": str(user.id),
746+
"author.mod": True,
747+
"type": {"$in": ["anonymous", "thread_message"]},
748+
}
749+
}
750+
}
751+
):
752+
entries.append(l)
753+
754+
embeds = self.format_log_embeds(entries, avatar_url=self.bot.guild.icon_url)
755+
756+
if not embeds:
757+
embed = discord.Embed(
758+
color=discord.Color.red(),
759+
description="No log entries have been found for that query",
760+
)
761+
return await ctx.send(embed=embed)
762+
763+
session = EmbedPaginatorSession(ctx, *embeds)
764+
await session.run()
765+
721766
@logs.command(name="search", aliases=["find"])
722767
@checks.has_permissions(PermissionLevel.SUPPORTER)
723768
async def logs_search(self, ctx, limit: Optional[int] = None, *, query):

core/_color_data.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@
3939
"light gray": "#979c9f",
4040
"dark gray": "#607d8b",
4141
"blurple": "#7289da",
42-
"grayple": "#99aab5"
42+
"grayple": "#99aab5",
4343
}
4444

4545
# Normalize name to "discord:<name>" to avoid name collisions.
46-
DISCORD_COLORS_NORM = {"discord:" + name: value for name, value in DISCORD_COLORS.items()}
46+
DISCORD_COLORS_NORM = {
47+
"discord:" + name: value for name, value in DISCORD_COLORS.items()
48+
}
4749

4850

4951
# These colors are from Tableau

core/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ class _Default:
9090

9191

9292
class SafeFormatter(Formatter):
93-
9493
def get_field(self, field_name, args, kwargs):
9594
first, rest = _string.formatter_field_name_split(field_name)
9695

@@ -107,7 +106,7 @@ def get_field(self, field_name, args, kwargs):
107106
if n >= 2:
108107
break
109108
if is_attr:
110-
if str(i).startswith('_'):
109+
if str(i).startswith("_"):
111110
break
112111
obj = getattr(obj, i)
113112
else:

core/thread.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,10 @@ async def _close(
394394
message = self.bot.config["thread_close_response"]
395395

396396
message = self.bot.formatter.format(
397-
message, closer=closer, loglink=log_url, logkey=log_data["key"] if log_data else None
397+
message,
398+
closer=closer,
399+
loglink=log_url,
400+
logkey=log_data["key"] if log_data else None,
398401
)
399402

400403
embed.description = message
@@ -493,8 +496,7 @@ async def _restart_close_timer(self):
493496

494497
# Grab message
495498
close_message = self.bot.formatter.format(
496-
self.bot.config["thread_auto_close_response"],
497-
timeout=human_time
499+
self.bot.config["thread_auto_close_response"], timeout=human_time
498500
)
499501

500502
time_marker_regex = "%t"

0 commit comments

Comments
 (0)