Repository: Cog-Creators/Red-DiscordBot

Issue:
[Mod] Mention spam accounting for roles
# Feature request

After finalizing https://github.com/Cog-Creators/Red-DiscordBot/pull/4359 (allowing for duplicate mentions). A small discussion was brought up (I forgot with whom), to possibly make something that would / could account for role mentions as well. 

#### Select the type of feature you are requesting:

<!-- To check a box, replace the space between the [] with a x -->

- [ ] Cog
- [x] Command
- [ ] API functionality

#### Describe your requested feature

This could either be it's own count system (separate from total user mentions. So user mentions could be set to 7, while role mentions could be set to 3), or it would take both user mentions and role mentions into the same context. (each would account for 7 in this example). 

I wanted to make this issue to gather feedback, I am more than willing to work on this myself, though, I want to make 100% sure that this is something worth working on, getting proper feedback on how to set this up and how it should action.

The reason why I believe this should be something for Core Mod is because while it can 100% be used as a third party cog, I figured this would give us and any user who uses core mod better advantages and control over antimentionspam we offer.



Discussion:
I don't see any reason to not include role mentions in anti-mention-spam filtering, it seems like a perfect addition.

It would be neat if it could be exclusive, as well as inclusive with member mentions - for maximum flexibility. 
Realized how long ago this was, I'll start working on this starting this week.

Resolving patch:
diff --git a/redbot/cogs/mod/events.py b/redbot/cogs/mod/events.py
--- a/redbot/cogs/mod/events.py
+++ b/redbot/cogs/mod/events.py
@@ -46,12 +46,12 @@ async def check_mention_spam(self, message):
         mention_spam = await self.config.guild(guild).mention_spam.all()
 
         if mention_spam["strict"]:  # if strict is enabled
-            mentions = message.raw_mentions
+            mentions = len(message.raw_mentions) + len(message.raw_role_mentions)
         else:  # if not enabled
-            mentions = set(message.mentions)
+            mentions = len(set(message.mentions)) + len(set(message.role_mentions))
 
         if mention_spam["ban"]:
-            if len(mentions) >= mention_spam["ban"]:
+            if mentions >= mention_spam["ban"]:
                 try:
                     await guild.ban(author, reason=_("Mention spam (Autoban)"))
                 except discord.HTTPException:
@@ -75,7 +75,7 @@ async def check_mention_spam(self, message):
                     return True
 
         if mention_spam["kick"]:
-            if len(mentions) >= mention_spam["kick"]:
+            if mentions >= mention_spam["kick"]:
                 try:
                     await guild.kick(author, reason=_("Mention Spam (Autokick)"))
                 except discord.HTTPException:
@@ -99,7 +99,7 @@ async def check_mention_spam(self, message):
                     return True
 
         if mention_spam["warn"]:
-            if len(mentions) >= mention_spam["warn"]:
+            if mentions >= mention_spam["warn"]:
                 try:
                     await author.send(_("Please do not mass mention people!"))
                 except (discord.HTTPException, discord.Forbidden):


Test patch: