diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b2a6ec..1e18b11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [4.11.1] - 2021-06-29 +### Tweaks +- Made tweaks to the audit log behaviour for booster roles. +- Performed maintenance on server logs. +- Message events now also respond to message edits, presuming they were not already responded to. + ## [4.11.0] - 2021-06-22 ### Message Events (Beta Testing) - Message events can be added/listed/deleted. diff --git a/README.md b/README.md index c05cb04..e5c3cb7 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ ![Migaga](https://dobercorgi.fra1.cdn.digitaloceanspaces.com/discord/Assets/Migaga.webp) # Migaga (Version 4) -[![Discord](https://img.shields.io/discord/750683930549551164)](https://discord.gg/QEwYcsKSrs) ![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/LewisHobden/migaga) ---- + ## What's this? This is the repo for my passion project Discord bot. I don't know exactly how many servers it is in - nor how many users it interacts with on a regular basis. I would estimate that it's in the 1000s. It was primarily built as a helper for some of the servers I was in personally. This was before bots were as accessible as they are now, or before the mobile app was as advanced as it is currently. I figured I would make the source code public as exposure therapy for my fear of "imperfect" code being made public with my name against it. We're all progressing professionally and personally, chronicling that only helps accelerate the process.. I hope! @@ -20,4 +19,5 @@ I figured I would make the source code public as exposure therapy for my fear of To get started contributing, copy `example_config.ini` to `config.ini` and update the ClientId and token to your test bot and you're good to go! Schema can be imported from the `storage` directory. I'm working on making that easier. -![Ecologi (Trees)](https://img.shields.io/ecologi/trees/lewis) \ No newline at end of file +![Ecologi (Trees)](https://img.shields.io/ecologi/trees/lewis) +[![Discord](https://img.shields.io/discord/750683930549551164)](https://discord.gg/QEwYcsKSrs) \ No newline at end of file diff --git a/cogs/booster.py b/cogs/booster.py index fa76787..301a8b0 100644 --- a/cogs/booster.py +++ b/cogs/booster.py @@ -108,8 +108,11 @@ async def _on_member_updated(member_before: Member, member_after: Member): if assigned_role is None: return - await member_after.remove_roles(assigned_role) - await assigned_role.delete() + reason = "This person is no longer boosting the server. Role name: {}. Colour: {}".format(assigned_role.name, + assigned_role.colour) + + await member_after.remove_roles(assigned_role, reason=reason) + await assigned_role.delete(reason=reason) class BoosterRoleCog(commands.Cog, name="Booster Roles"): diff --git a/cogs/message_events.py b/cogs/message_events.py index 16b8c7a..800796b 100644 --- a/cogs/message_events.py +++ b/cogs/message_events.py @@ -55,6 +55,7 @@ def __init__(self, client: commands.Bot): self._events = dict() self.client.add_listener(self._on_message, "on_message") + self.client.add_listener(self._on_message_edit, "on_message_edit") self._cache_events.start() def cog_unload(self): @@ -68,6 +69,27 @@ async def _cache_events(self): for event in MessageEvent.select(): self.add_event(event) + async def _on_message_edit(self, message_before: Message, message_after: Message): + # Ignore ourselves, bots, etc. + if message_after.author.bot: + return + + for event in self.get_events(message_after.guild): + controller = MessageMatchingController(event.contains, event.is_strict) + + # If the message matched before, then we shouldn't reply to it a second time. + if controller.check_match(message_before.clean_content): + continue + + # Todo, should we keep track of our messages and delete a reply if the user edits it to no longer match? + if not controller.check_match(message_after.clean_content): + continue + + if event.response is None: + await message_after.delete() + else: + await message_after.reply(event.response) + async def _on_message(self, message: Message): # Ignore ourselves, bots, etc. if message.author.bot: diff --git a/cogs/serverlogs.py b/cogs/serverlogs.py index 99d893f..42239cf 100644 --- a/cogs/serverlogs.py +++ b/cogs/serverlogs.py @@ -41,7 +41,7 @@ def __init__(self, client): client.add_listener(self._on_message_delete, "on_message_delete") client.add_listener(self._on_message_edit, "on_message_edit") client.add_listener(self._on_member_join, "on_member_join") - client.add_listener(self._on_member_leave, "on_member_leave") + client.add_listener(self._on_member_leave, "on_member_remove") client.add_listener(self._on_member_banned, "on_member_ban") client.add_listener(self._on_member_unbanned, "on_member_unban") client.add_listener(self._on_member_updated, "on_member_update") @@ -139,6 +139,9 @@ async def _on_user_updated(self, before: discord.User, after: discord.User): except discord.errors.NotFound: return + if len(e.fields) == 0: + return + for guild in self.client.guilds: member = discord.utils.find(lambda m: m.id == after.id, guild.members)