[base] mise à jour des autorisation
This commit is contained in:
parent
8be784d6c4
commit
1556746010
5
main.py
5
main.py
@ -232,8 +232,8 @@ class LBI(discord.Client):
|
|||||||
self.config = {
|
self.config = {
|
||||||
"modules": ["modules"],
|
"modules": ["modules"],
|
||||||
"prefix": "%",
|
"prefix": "%",
|
||||||
|
"owners": [],
|
||||||
}
|
}
|
||||||
self.owners = [281166473102098433, 318866596502306816]
|
|
||||||
self.load_config()
|
self.load_config()
|
||||||
self.load_modules()
|
self.load_modules()
|
||||||
|
|
||||||
@ -289,7 +289,8 @@ class LBI(discord.Client):
|
|||||||
deps = MODULES[module].dependencies
|
deps = MODULES[module].dependencies
|
||||||
for dep in deps.keys():
|
for dep in deps.keys():
|
||||||
if dep not in self.modules.keys():
|
if dep not in self.modules.keys():
|
||||||
self.load_module(dep)
|
if dep != "base":
|
||||||
|
self.load_module(dep)
|
||||||
if MODULES[module].type == "python":
|
if MODULES[module].type == "python":
|
||||||
try:
|
try:
|
||||||
self.info("Start loading module {module}...".format(module=module))
|
self.info("Start loading module {module}...".format(module=module))
|
||||||
|
@ -3,6 +3,7 @@ import asyncio
|
|||||||
import sys
|
import sys
|
||||||
import pickle
|
import pickle
|
||||||
import traceback
|
import traceback
|
||||||
|
from typing import List
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ class BaseClass:
|
|||||||
help_active = False
|
help_active = False
|
||||||
color = 0x000000
|
color = 0x000000
|
||||||
command_text = None
|
command_text = None
|
||||||
super_users = []
|
authorized_users = []
|
||||||
authorized_roles = []
|
authorized_roles = []
|
||||||
|
|
||||||
def __init__(self, client):
|
def __init__(self, client):
|
||||||
@ -51,34 +52,33 @@ class BaseClass:
|
|||||||
inline=False)
|
inline=False)
|
||||||
await channel.send(embed=embed)
|
await channel.send(embed=embed)
|
||||||
|
|
||||||
async def auth(self, user, role_list=None):
|
async def auth(self, user: discord.User, role_list: List[int] = None, user_list: List[int] = None):
|
||||||
|
"""
|
||||||
|
Return True if user is an owner of the bot or in authorized_users or he have a role in authorized_roles.
|
||||||
|
|
||||||
|
: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
|
||||||
|
:type user_list: List[Int]
|
||||||
|
:type role_list: List[int]
|
||||||
|
:type user: discord.User
|
||||||
|
"""
|
||||||
if role_list is None:
|
if role_list is None:
|
||||||
role_list = self.authorized_roles
|
role_list = self.authorized_roles
|
||||||
if len(role_list) == 0:
|
if user_list is None:
|
||||||
# Everyone can use this command
|
user_list = self.authorized_users
|
||||||
return True
|
if len(role_list) == 0 and len(user_list) == 0:
|
||||||
if type(role_list) == list:
|
# Everyone can use this command
|
||||||
if user.id in self.client.owners:
|
return True
|
||||||
return True
|
if user.id in self.client.config["owners"]:
|
||||||
for guild in self.client.guilds:
|
return True
|
||||||
if guild.get_member(user.id):
|
if user.id in user_list:
|
||||||
for role_id in role_list:
|
return True
|
||||||
if role_id in [r.id for r in guild.get_member(user.id).roles]:
|
for guild in self.client.guilds:
|
||||||
return True
|
if guild.get_member(user.id):
|
||||||
elif type(role_list) == str:
|
for role_id in role_list:
|
||||||
module_name = role_list
|
if role_id in [r.id for r in guild.get_member(user.id).roles]:
|
||||||
if user.id in self.client.owners:
|
return True
|
||||||
return True
|
return False
|
||||||
authorized_roles = self.client.modules[module_name]["class"].authorized_roles
|
|
||||||
if len(authorized_roles):
|
|
||||||
for guild in self.client.guilds:
|
|
||||||
if guild.get_member(user.id):
|
|
||||||
for role_id in authorized_roles:
|
|
||||||
if role_id in [r.id for r in guild.get_member(user.id).roles]:
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
async def parse_command(self, message):
|
async def parse_command(self, message):
|
||||||
"""Parse a command_text from received message and execute function
|
"""Parse a command_text from received message and execute function
|
||||||
@ -100,7 +100,7 @@ class BaseClass:
|
|||||||
else:
|
else:
|
||||||
await self.command(message, [sub_command[4:]] + args, kwargs)
|
await self.command(message, [sub_command[4:]] + args, kwargs)
|
||||||
else:
|
else:
|
||||||
await self.unauthorized(message, [sub_command[4:]] + args, kwargs)
|
await self.unauthorized(message)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_command_content(content):
|
def _parse_command_content(content):
|
||||||
|
@ -25,8 +25,9 @@ class BaseClassLua(BaseClass):
|
|||||||
help_active = False
|
help_active = False
|
||||||
color = 0x000000
|
color = 0x000000
|
||||||
command_text = None
|
command_text = None
|
||||||
super_users = []
|
authorized_users = []
|
||||||
authorized_roles = []
|
authorized_roles = []
|
||||||
|
command_text = "lua"
|
||||||
|
|
||||||
def __init__(self, client, path):
|
def __init__(self, client, path):
|
||||||
"""Initialize module class
|
"""Initialize module class
|
||||||
@ -72,7 +73,7 @@ class BaseClassLua(BaseClass):
|
|||||||
self.client.config["prefix"] + (self.command_text if self.command_text else ""))
|
self.client.config["prefix"] + (self.command_text if self.command_text else ""))
|
||||||
sub_command, args, kwargs = self._parse_command_content(content)
|
sub_command, args, kwargs = self._parse_command_content(content)
|
||||||
sub_command = "com_" + sub_command
|
sub_command = "com_" + sub_command
|
||||||
if await self.auth(message.user):
|
if await self.auth(message.author):
|
||||||
self.call(sub_command, args, kwargs)
|
self.call(sub_command, args, kwargs)
|
||||||
else:
|
else:
|
||||||
await self.unauthorized(message)
|
await self.unauthorized(message)
|
||||||
|
@ -12,7 +12,8 @@ class MainClass(BaseClassPython):
|
|||||||
name = "errors"
|
name = "errors"
|
||||||
description = "Error handling"
|
description = "Error handling"
|
||||||
interactive = True
|
interactive = True
|
||||||
super_users_list = [431043517217898496]
|
authorized_users = [431043517217898496]
|
||||||
|
authorized_roles = []
|
||||||
color = 0xdb1348
|
color = 0xdb1348
|
||||||
help = {
|
help = {
|
||||||
"description": "Montre toutes les erreurs du bot dans discord.",
|
"description": "Montre toutes les erreurs du bot dans discord.",
|
||||||
|
Loading…
Reference in New Issue
Block a user