From 39d3a777cd89c560ccc964648ca78e0f8545e0dd Mon Sep 17 00:00:00 2001 From: mbaruh Date: Sat, 1 Oct 2022 20:54:08 +0300 Subject: Add a warning if an added filter has content identicalto others --- bot/exts/filtering/filtering.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/bot/exts/filtering/filtering.py b/bot/exts/filtering/filtering.py index 8d9c62ce3..b6153487c 100644 --- a/bot/exts/filtering/filtering.py +++ b/bot/exts/filtering/filtering.py @@ -683,6 +683,17 @@ class Filtering(Cog): ) await ctx.send(embed=embed, reference=ctx.message, view=view) + @staticmethod + def _identical_filters_message(content: str, filter_list: FilterList, list_type: ListType) -> str: + """Returns all the filters in the list with content identical to the content supplied.""" + duplicates = [f for f in filter_list.filter_lists.get(list_type, {}).values() if f.content == content] + msg = "" + if duplicates: + msg = f"\n:warning: The filter(s) #{', #'.join(str(dup.id) for dup in duplicates)} have the same content. " + msg += "Please make sure this is intentional." + + return msg + @staticmethod async def _post_new_filter( msg: Message, @@ -706,8 +717,9 @@ class Filtering(Cog): "additional_field": json.dumps(filter_settings), **settings } response = await bot.instance.api_client.post('bot/filter/filters', json=payload) + extra_msg = Filtering._identical_filters_message(content, filter_list, list_type) new_filter = filter_list.add_filter(response, list_type) - await msg.reply(f"✅ Added filter: {new_filter}") + await msg.reply(f"✅ Added filter: {new_filter}" + extra_msg) @staticmethod async def _patch_filter( @@ -739,8 +751,9 @@ class Filtering(Cog): "additional_field": json.dumps(filter_settings), **settings } response = await bot.instance.api_client.patch(f'bot/filter/filters/{filter_.id}', json=payload) + extra_msg = Filtering._identical_filters_message(content, filter_list, list_type) edited_filter = filter_list.add_filter(response, list_type) - await msg.reply(f"✅ Edited filter: {edited_filter}") + await msg.reply(f"✅ Edited filter: {edited_filter}" + extra_msg) # endregion -- cgit v1.2.3