Skip to content

Commit 5ed556d

Browse files
robinmahieuTaaku18
authored andcommitted
Delete notes, "?logs delete", linked alias (#402)
* Add ability to delete notes * Add wipe command * Add option to add existing aliases in new aliases * Fix typo in presence docstring * Update changelog and bump dev version
1 parent 320fa67 commit 5ed556d

File tree

8 files changed

+81
-30
lines changed

8 files changed

+81
-30
lines changed

.lint.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if __name__ == '__main__':
1+
if __name__ == "__main__":
22
import sys
33
from os import listdir
44
from os.path import join

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.
77
however, insignificant breaking changes does not guarantee a major version bump, see the reasoning [here](https://github.com/kyb3r/modmail/issues/319).
88

99

10-
# v3.3.0-dev5
10+
# v3.3.0-dev6
1111

1212

1313
### Important
@@ -39,6 +39,8 @@ however, insignificant breaking changes does not guarantee a major version bump,
3939
- `disabled_current_thread_title`
4040
- `disabled_current_thread_response`
4141
- `disabled_current_thread_footer`
42+
- Ability to delete notes when providing their ID. (Thanks to papiersnipper PR#402)
43+
- Ability to delete log entries. (Thanks to papiersnipper PR#402)
4244

4345
### Changed
4446

@@ -62,6 +64,7 @@ however, insignificant breaking changes does not guarantee a major version bump,
6264
- Eval commands are logged in debug logs.
6365
- Presence updates 30 minutes instead of 45 now.
6466
- Fixed an assortment of problems to do with block.
67+
- Existing aliases can be used when creating new aliases. (Thanks to papiersnipper PR#402)
6568

6669
### Internal
6770

bot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "3.3.0-dev5"
1+
__version__ = "3.3.0-dev6"
22

33
import asyncio
44
import logging

cogs/modmail.py

+28-1
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,31 @@ async def logs_closed_by(self, ctx, *, user: User = None):
722722
session = EmbedPaginatorSession(ctx, *embeds)
723723
await session.run()
724724

725+
@logs.command(name="delete", aliases=["wipe"])
726+
@checks.has_permissions(PermissionLevel.OWNER)
727+
async def logs_delete(self, ctx, key_or_link: str):
728+
"""
729+
Wipe a log entry from the database.
730+
"""
731+
key = key_or_link.split("/")[-1]
732+
733+
success = await self.bot.api.delete_log_entry(key)
734+
735+
if not success:
736+
embed = discord.Embed(
737+
title="Error",
738+
description=f"Log entry `{key}` not found.",
739+
color=self.bot.error_color,
740+
)
741+
else:
742+
embed = discord.Embed(
743+
title="Success",
744+
description=f"Log entry `{key}` successfully deleted.",
745+
color=self.bot.main_color,
746+
)
747+
748+
await ctx.send(embed=embed)
749+
725750
@logs.command(name="responded")
726751
@checks.has_permissions(PermissionLevel.SUPPORTER)
727752
async def logs_responded(self, ctx, *, user: User = None):
@@ -1167,10 +1192,12 @@ async def unblock(self, ctx, *, user: User = None):
11671192
@checks.thread_only()
11681193
async def delete(self, ctx, message_id: Optional[int] = None):
11691194
"""
1170-
Delete a message that was sent using the reply command.
1195+
Delete a message that was sent using the reply command or a note.
11711196
11721197
Deletes the previous message, unless a message ID is provided,
11731198
which in that case, deletes the message with that message ID.
1199+
1200+
Notes can only be deleted when a note ID is provided.
11741201
"""
11751202
thread = ctx.thread
11761203

cogs/plugins.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ async def load_plugin(self, plugin):
226226

227227
try:
228228
self.bot.load_extension(plugin.ext_string)
229-
logger.info("Loaded plugin: %s", plugin.ext_string.split('.')[-1])
229+
logger.info("Loaded plugin: %s", plugin.ext_string.split(".")[-1])
230230
self.loaded_plugins.add(plugin)
231231

232232
except commands.ExtensionError as exc:

cogs/utility.py

+41-21
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,12 @@ async def about(self, ctx):
305305
latest = changelog.latest_version
306306

307307
if self.bot.version.is_prerelease:
308-
stable = next(filter(lambda v: not parse_version(v.version).is_prerelease, changelog.versions))
308+
stable = next(
309+
filter(
310+
lambda v: not parse_version(v.version).is_prerelease,
311+
changelog.versions,
312+
)
313+
)
309314
footer = f"You are on the prerelease version • the latest version is v{stable.version}."
310315
elif self.bot.version < parse_version(latest.version):
311316
footer = f"A newer version is available v{latest.version}."
@@ -509,7 +514,9 @@ async def activity(self, ctx, activity_type: str.lower, *, message: str = ""):
509514
except KeyError:
510515
raise commands.MissingRequiredArgument(SimpleNamespace(name="activity"))
511516

512-
activity, _ = await self.set_presence(activity_type=activity_type, activity_message=message)
517+
activity, _ = await self.set_presence(
518+
activity_type=activity_type, activity_message=message
519+
)
513520

514521
self.bot.config["activity_type"] = activity.type.value
515522
self.bot.config["activity_message"] = activity.name
@@ -565,7 +572,9 @@ async def status(self, ctx, *, status_type: str.lower):
565572
)
566573
return await ctx.send(embed=embed)
567574

568-
async def set_presence(self, *, status=None, activity_type=None, activity_message=None):
575+
async def set_presence(
576+
self, *, status=None, activity_type=None, activity_message=None
577+
):
569578

570579
if status is None:
571580
status = self.bot.config.get("status")
@@ -574,9 +583,13 @@ async def set_presence(self, *, status=None, activity_type=None, activity_messag
574583
activity_type = self.bot.config.get("activity_type")
575584

576585
url = None
577-
activity_message = (activity_message or self.bot.config["activity_message"]).strip()
586+
activity_message = (
587+
activity_message or self.bot.config["activity_message"]
588+
).strip()
578589
if activity_type is not None and not activity_message:
579-
logger.warning("No activity message found whilst activity is provided, defaults to \"Modmail\".")
590+
logger.warning(
591+
'No activity message found whilst activity is provided, defaults to "Modmail".'
592+
)
580593
activity_message = "Modmail"
581594

582595
if activity_type == ActivityType.listening:
@@ -599,14 +612,14 @@ async def set_presence(self, *, status=None, activity_type=None, activity_messag
599612

600613
@tasks.loop(minutes=30)
601614
async def loop_presence(self):
602-
"""Set presence to the configured value every 45 minutes."""
615+
"""Set presence to the configured value every 30 minutes."""
603616
logger.debug("Resetting presence.")
604617
await self.set_presence()
605618

606619
@loop_presence.before_loop
607620
async def before_loop_presence(self):
608621
await self.bot.wait_for_connected()
609-
logger.line('debug')
622+
logger.line("debug")
610623
activity, status = await self.set_presence()
611624

612625
if activity is not None:
@@ -1044,13 +1057,16 @@ async def alias_add(self, ctx, name: str.lower, *, value):
10441057
if len(values) == 1:
10451058
linked_command = values[0].split()[0].lower()
10461059
if not self.bot.get_command(linked_command):
1047-
embed = discord.Embed(
1048-
title="Error",
1049-
color=self.bot.error_color,
1050-
description="The command you are attempting to point "
1051-
f"to does not exist: `{linked_command}`.",
1052-
)
1053-
return await ctx.send(embed=embed)
1060+
if linked_command in self.bot.aliases:
1061+
values = [self.bot.aliases.get(linked_command)]
1062+
else:
1063+
embed = discord.Embed(
1064+
title="Error",
1065+
color=self.bot.error_color,
1066+
description="The command you are attempting to point "
1067+
f"to does not exist: `{linked_command}`.",
1068+
)
1069+
return await ctx.send(embed=embed)
10541070

10551071
embed = discord.Embed(
10561072
title="Added alias",
@@ -1068,13 +1084,17 @@ async def alias_add(self, ctx, name: str.lower, *, value):
10681084
for i, val in enumerate(values, start=1):
10691085
linked_command = val.split()[0]
10701086
if not self.bot.get_command(linked_command):
1071-
embed = discord.Embed(
1072-
title="Error",
1073-
color=self.bot.error_color,
1074-
description="The command you are attempting to point "
1075-
f"to on step {i} does not exist: `{linked_command}`.",
1076-
)
1077-
return await ctx.send(embed=embed)
1087+
if linked_command in self.bot.aliases:
1088+
index = values.index(linked_command)
1089+
values[index] = self.bot.aliases.get(linked_command)
1090+
else:
1091+
embed = discord.Embed(
1092+
title="Error",
1093+
color=self.bot.error_color,
1094+
description="The command you are attempting to point "
1095+
f"to on step {i} does not exist: `{linked_command}`.",
1096+
)
1097+
return await ctx.send(embed=embed)
10781098
embed.description += f"\n{i}: {val}"
10791099

10801100
self.bot.aliases[name] = " && ".join(values)

core/clients.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ async def get_responded_logs(self, user_id: Union[str, int]) -> list:
106106
return await self.logs.find(query).to_list(None)
107107

108108
async def get_open_logs(self) -> list:
109-
query = {
110-
"open": True
111-
}
109+
query = {"open": True}
112110
return await self.logs.find(query).to_list(None)
113111

114112
async def get_log(self, channel_id: Union[str, int]) -> dict:
@@ -162,6 +160,10 @@ async def create_log_entry(
162160
prefix = ""
163161
return f"{self.bot.config['log_url'].strip('/')}{'/' + prefix if prefix else ''}/{key}"
164162

163+
async def delete_log_entry(self, key: str) -> bool:
164+
result = await self.logs.delete_one({"key": key})
165+
return result.deleted_count == 1
166+
165167
async def get_config(self) -> dict:
166168
conf = await self.db.config.find_one({"bot_id": self.bot.user.id})
167169
if conf is None:

core/thread.py

-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,6 @@ async def _fetch_timeout(
439439
"""
440440
This grabs the timeout value for closing threads automatically
441441
from the ConfigManager and parses it for use internally.
442-
443442
:returns: None if no timeout is set.
444443
"""
445444
timeout = self.bot.config.get("thread_auto_close")

0 commit comments

Comments
 (0)