[base-auth] Réparation de l'auth, ajout de la possibilité de limiter l'authentification à un seul server, casse la config "owner" maintenant c'est "admin_roles" et "admin_users"
This commit is contained in:
parent
c6868d7977
commit
da0cde7800
2
main.py
2
main.py
@ -236,7 +236,7 @@ class LBI(discord.Client):
|
|||||||
# Content: {"module_name": {"module": imported module, "class": initialized class}}
|
# Content: {"module_name": {"module": imported module, "class": initialized class}}
|
||||||
self.modules = {}
|
self.modules = {}
|
||||||
self.config = config
|
self.config = config
|
||||||
self.config.init({"modules": ["modules", "errors"], "prefix": "%", "owners": []})
|
self.config.init({"modules": ["modules", "errors"], "prefix": "%", "admin_roles": [], "admin_users": []})
|
||||||
self.load_modules()
|
self.load_modules()
|
||||||
|
|
||||||
@modules_edit
|
@modules_edit
|
||||||
|
@ -51,28 +51,31 @@ class BaseClass:
|
|||||||
inline=False)
|
inline=False)
|
||||||
await channel.send(embed=embed)
|
await channel.send(embed=embed)
|
||||||
|
|
||||||
async def auth(self, user: discord.User, role_list: List[int] = None, user_list: List[int] = None):
|
async def auth(self, user: discord.User, role_list: List[int] = None, user_list: List[int] = None,
|
||||||
|
guild: int = None):
|
||||||
"""
|
"""
|
||||||
Return True if user is an owner of the bot or in authorized_users or he have a role in authorized_roles.
|
Return True if user is an owner of the bot or in authorized_users or he have a role in authorized_roles.
|
||||||
|
|
||||||
|
:param user: User to check
|
||||||
:param user_list: List of authorized users, if not specified use self.authorized_users
|
:param user_list: List of authorized users, if not specified use self.authorized_users
|
||||||
:param role_list: list of authorized roles, if not specified use self.authorized_roles
|
:param role_list: list of authorized roles, if not specified use self.authorized_roles
|
||||||
|
:param guild: Specific guild to search role
|
||||||
:type user_list: List[Int]
|
:type user_list: List[Int]
|
||||||
:type role_list: List[Int]
|
:type role_list: List[Int]
|
||||||
|
:type guild: Int
|
||||||
:type user: discord.User
|
:type user: discord.User
|
||||||
"""
|
"""
|
||||||
if role_list is None:
|
|
||||||
role_list = self.config["authorized_roles"]
|
|
||||||
if user_list is None:
|
if user_list is None:
|
||||||
user_list = self.config["authorized_users"]
|
user_list = self.config.authorized_users + self.client.config.admin_users
|
||||||
if len(role_list) == 0 and len(user_list) == 0:
|
|
||||||
# Everyone can use this command
|
|
||||||
return True
|
|
||||||
if user.id in self.client.config["owners"]:
|
|
||||||
return True
|
|
||||||
if user.id in user_list:
|
if user.id in user_list:
|
||||||
return True
|
return True
|
||||||
for guild in self.client.guilds:
|
if role_list is None:
|
||||||
|
role_list = self.config.authorized_roles + self.client.config.admin_roles
|
||||||
|
if guild is None:
|
||||||
|
guilds = self.client.guilds
|
||||||
|
else:
|
||||||
|
guilds = [guild]
|
||||||
|
for guild in guilds:
|
||||||
if guild.get_member(user.id):
|
if guild.get_member(user.id):
|
||||||
for role_id in role_list:
|
for role_id in role_list:
|
||||||
if role_id in [r.id for r in guild.get_member(user.id).roles]:
|
if role_id in [r.id for r in guild.get_member(user.id).roles]:
|
||||||
|
Loading…
Reference in New Issue
Block a user