Skip to content

Commit 97beb74

Browse files
authored
Merge pull request #388 from papiersnipper/anon_reply_without_command
Add ?logs response command and anon_reply_without_command config var
2 parents 06c8f78 + ed8ee39 commit 97beb74

File tree

7 files changed

+75
-8
lines changed

7 files changed

+75
-8
lines changed

bot.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ async def _process_blocked(self, message: discord.Message) -> bool:
652652
self.blocked_users.pop(str(message.author.id))
653653
else:
654654
reaction = blocked_emoji
655-
end_time = re.search(r"%(.+?)%$", reason)
655+
end_time = re.search(r"%(.+?)%", reason)
656656
if end_time is not None:
657657
logger.debug("No longer blocked, user %s.", message.author.name)
658658
after = (
@@ -829,7 +829,9 @@ async def process_commands(self, message):
829829

830830
thread = await self.threads.find(channel=ctx.channel)
831831
if thread is not None:
832-
if self.config.get("reply_without_command"):
832+
if self.config.get("anon_reply_without_command"):
833+
await thread.reply(message, anonymous=True)
834+
elif self.config.get("reply_without_command"):
833835
await thread.reply(message)
834836
else:
835837
await self.api.append_log(message, type_="internal")

cogs/modmail.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616
from core.models import PermissionLevel
1717
from core.paginator import EmbedPaginatorSession
1818
from core.time import UserFriendlyTime, human_timedelta
19-
from core.utils import format_preview, User, create_not_found_embed, format_description, trigger_typing
19+
from core.utils import (
20+
format_preview,
21+
User,
22+
create_not_found_embed,
23+
format_description,
24+
trigger_typing,
25+
)
2026

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

@@ -704,6 +710,31 @@ async def logs_closed_by(self, ctx, *, user: User = None):
704710
session = EmbedPaginatorSession(ctx, *embeds)
705711
await session.run()
706712

713+
@logs.command(name="responded")
714+
@checks.has_permissions(PermissionLevel.SUPPORTER)
715+
async def logs_responded(self, ctx, *, user: User = None):
716+
"""
717+
Get all logs where the specified user has responded at least once.
718+
719+
If no `user` is provided, the user will be the person who sent this command.
720+
`user` may be a user ID, mention, or name.
721+
"""
722+
user = user if user is not None else ctx.author
723+
724+
entries = await self.bot.api.get_responded_logs(user.id)
725+
726+
embeds = self.format_log_embeds(entries, avatar_url=self.bot.guild.icon_url)
727+
728+
if not embeds:
729+
embed = discord.Embed(
730+
color=self.bot.error_color,
731+
description=f"{getattr(user, 'mention', user.id)} has not responded to any threads.",
732+
)
733+
return await ctx.send(embed=embed)
734+
735+
session = EmbedPaginatorSession(ctx, *embeds)
736+
await session.run()
737+
707738
@logs.command(name="search", aliases=["find"])
708739
@checks.has_permissions(PermissionLevel.SUPPORTER)
709740
async def logs_search(self, ctx, limit: Optional[int] = None, *, query):

cogs/plugins.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,9 @@ async def plugins_remove(self, ctx, *, plugin_name: str):
399399
await self.bot.config.update()
400400
shutil.rmtree(
401401
plugin.abs_path,
402-
onerror=lambda *args: logger.warning('Failed to remove plugin files %s: %s', plugin, str(args[2]))
402+
onerror=lambda *args: logger.warning(
403+
"Failed to remove plugin files %s: %s", plugin, str(args[2])
404+
),
403405
)
404406
try:
405407
plugin.abs_path.parent.rmdir()

core/clients.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ async def get_user_logs(self, user_id: Union[str, int]) -> list:
9292

9393
return await self.logs.find(query, projection).to_list(None)
9494

95+
async def get_responded_logs(self, user_id: Union[str, int]) -> list:
96+
entries = []
97+
async for l in self.bot.db.logs.find(
98+
{
99+
"open": False,
100+
"messages": {
101+
"$elemMatch": {
102+
"author.id": str(user_id),
103+
"author.mod": True,
104+
"type": {"$in": ["anonymous", "thread_message"]},
105+
}
106+
},
107+
}
108+
):
109+
entries.append(l)
110+
return entries
111+
95112
async def get_log(self, channel_id: Union[str, int]) -> dict:
96113
logger.debug("Retrieving channel %s logs.", channel_id)
97114
return await self.logs.find_one({"channel_id": str(channel_id)})

core/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ConfigManager:
3737
"account_age": None,
3838
"guild_age": None,
3939
"reply_without_command": False,
40+
"anon_reply_without_command": False,
4041
# logging
4142
"log_channel_id": None,
4243
# threads
@@ -112,6 +113,7 @@ class ConfigManager:
112113
"user_typing",
113114
"mod_typing",
114115
"reply_without_command",
116+
"anon_reply_without_command",
115117
"recipient_thread_close",
116118
"thread_auto_close_silently",
117119
"thread_move_notify",

core/config_help.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,18 @@
126126
"`{prefix}config set reply_without_command no`"
127127
],
128128
"notes": [
129-
"Unfortunately, anonymous `reply_without_command` is currently not possible."
129+
"See also: `anon_reply_without_command`."
130+
]
131+
},
132+
"anon_reply_without_command": {
133+
"default": "Disabled",
134+
"description": "Setting this configuration will make all non-command messages sent in the thread channel to be anonymously forwarded to the recipient without the need of `{prefix}reply`.",
135+
"examples": [
136+
"`{prefix}config set anon_reply_without_command yes`",
137+
"`{prefix}config set anon_reply_without_command no`"
138+
],
139+
"notes": [
140+
"See also: `reply_without_command`."
130141
]
131142
},
132143
"log_channel_id": {

core/decorators.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55

66
def trigger_typing(func):
7-
warnings.warn("trigger_typing has been moved to core.utils.trigger_typing, this will be removed.",
8-
DeprecationWarning,
9-
stacklevel=2)
7+
warnings.warn(
8+
"trigger_typing has been moved to core.utils.trigger_typing, this will be removed.",
9+
DeprecationWarning,
10+
stacklevel=2,
11+
)
1012
return _trigger_typing(func)

0 commit comments

Comments
 (0)