[V3 Mod/Filter] Fix #1202 (#1327)

* Fix #1326

Checks to see if `author` is a `valid_user` (of `Member` class) before checking to see if the bot `is_mod_or_superior` to the `author`.

* Fix #1202

Raises `TypeError` when `User` objects are passed into `is_mod_or_superior` or `is_admin_or_superior`, as only `Member` objects have a `guild` attribute.

* Fixes #1202

Checks to see if `author` is a `valid_user` (of `Member` class) before checking to see if the bot `is_mod_or_superior` to the `author`.
This commit is contained in:
Sebass13 2018-02-21 17:36:13 -06:00 committed by Will
parent d20724d7b2
commit b5c71bc59c
3 changed files with 16 additions and 9 deletions

View File

@ -249,10 +249,12 @@ class Filter:
return return
author = message.author author = message.author
valid_user = isinstance(author, discord.Member) and not author.bot valid_user = isinstance(author, discord.Member) and not author.bot
if not valid_user:
return
# Bots and mods or superior are ignored from the filter # Bots and mods or superior are ignored from the filter
mod_or_superior = await is_mod_or_superior(self.bot, obj=author) mod_or_superior = await is_mod_or_superior(self.bot, obj=author)
if not valid_user or mod_or_superior: if mod_or_superior:
return return
await self.check_filter(message) await self.check_filter(message)
@ -261,10 +263,13 @@ class Filter:
author = message.author author = message.author
if message.guild is None or self.bot.user == author: if message.guild is None or self.bot.user == author:
return return
valid_user = isinstance(author, discord.Member) and not author.bot valid_user = isinstance(author, discord.Member) and not author.bot
if not valid_user:
return
# Bots and mods or superior are ignored from the filter
mod_or_superior = await is_mod_or_superior(self.bot, obj=author) mod_or_superior = await is_mod_or_superior(self.bot, obj=author)
if not valid_user or mod_or_superior: if mod_or_superior:
return return
await self.check_filter(message) await self.check_filter(message)

View File

@ -1241,10 +1241,12 @@ class Mod:
if message.guild is None or self.bot.user == author: if message.guild is None or self.bot.user == author:
return return
valid_user = isinstance(author, discord.Member) and not author.bot valid_user = isinstance(author, discord.Member) and not author.bot
if not valid_user:
return
# Bots and mods or superior are ignored from the filter # Bots and mods or superior are ignored from the filter
mod_or_superior = await is_mod_or_superior(self.bot, obj=author) mod_or_superior = await is_mod_or_superior(self.bot, obj=author)
if not valid_user or mod_or_superior: if mod_or_superior:
return return
deleted = await self.check_duplicates(message) deleted = await self.check_duplicates(message)
if not deleted: if not deleted:

View File

@ -124,7 +124,7 @@ async def is_mod_or_superior(
user = None user = None
if isinstance(obj, discord.Message): if isinstance(obj, discord.Message):
user = obj.author user = obj.author
elif isinstance(obj, discord.Member) or isinstance(obj, discord.User): elif isinstance(obj, discord.Member):
user = obj user = obj
elif isinstance(obj, discord.Role): elif isinstance(obj, discord.Role):
pass pass
@ -214,7 +214,7 @@ async def is_admin_or_superior(
user = None user = None
if isinstance(obj, discord.Message): if isinstance(obj, discord.Message):
user = obj.author user = obj.author
elif isinstance(obj, discord.Member) or isinstance(obj, discord.User): elif isinstance(obj, discord.Member):
user = obj user = obj
elif isinstance(obj, discord.Role): elif isinstance(obj, discord.Role):
pass pass