[bot-base] Get-role en plus joli pour permettre de faire des recherche de roles avec plus de critères
This commit is contained in:
parent
cc4704c90c
commit
b5947176a8
35
main.py
35
main.py
@ -400,32 +400,29 @@ class ClientById:
|
|||||||
channel = self.client.get_channel(id_)
|
channel = self.client.get_channel(id_)
|
||||||
return channel.send(*args, **kwargs)
|
return channel.send(*args, **kwargs)
|
||||||
|
|
||||||
async def get_role(self, id_=None, name=None, guild=None, case_sensitive=True):
|
async def get_role(self, id_=None, name=None, check=None, guilds=None):
|
||||||
guilds = self.client.guilds
|
"""Get role by id or with custom check"""
|
||||||
if guild is not None:
|
if guilds is None:
|
||||||
guilds = [guild]
|
guilds = self.client.guilds
|
||||||
if id_ is not None:
|
if id_ is not None:
|
||||||
for guild in guilds:
|
for guild in guilds:
|
||||||
role = discord.utils.get(guild.roles, id=id_)
|
role = discord.utils.get(guild.roles, id=id_)
|
||||||
if role:
|
if role:
|
||||||
return role
|
return role
|
||||||
if name is not None:
|
if name is not None:
|
||||||
if case_sensitive:
|
for guild in guilds:
|
||||||
for guild in guilds:
|
role = discord.utils.get(guild.roles, name=name)
|
||||||
role = discord.utils.get(guild.roles, name=name)
|
if role:
|
||||||
if role:
|
return role
|
||||||
return role
|
if check is not None:
|
||||||
else:
|
role = None
|
||||||
name = name.lower()
|
for guild in guilds:
|
||||||
role = None
|
for role_ in guild.roles:
|
||||||
|
if check(role_):
|
||||||
for guild in guilds:
|
role = role_
|
||||||
for role_ in guild.roles:
|
|
||||||
if role_.name.lower() == name:
|
|
||||||
role = role_
|
|
||||||
break
|
|
||||||
if role is not None:
|
|
||||||
break
|
break
|
||||||
|
if role is not None:
|
||||||
|
break
|
||||||
return role
|
return role
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -19,12 +19,13 @@ class MainClass(BaseClassPython):
|
|||||||
for i, member in enumerate(guild.members):
|
for i, member in enumerate(guild.members):
|
||||||
if len(member.roles) == 1:
|
if len(member.roles) == 1:
|
||||||
await member.add_roles(await self.client.id.get_role(id_=self.config.new_role,
|
await member.add_roles(await self.client.id.get_role(id_=self.config.new_role,
|
||||||
guild=self.client.config.main_guild))
|
guilds=[self.client.get_guild(
|
||||||
|
self.client.config.main_guild)]))
|
||||||
if i % 50 == 0:
|
if i % 50 == 0:
|
||||||
self.client.log(f"Attribution des roles automatique manqués... {i}/{len(guild.members)}")
|
self.client.log(f"Attribution des roles automatique manqués... {i}/{len(guild.members)}")
|
||||||
|
|
||||||
async def on_member_join(self, member):
|
async def on_member_join(self, member):
|
||||||
await member.add_roles(await self.client.id.get_role(id_=self.config.new_role,
|
await member.add_roles(await self.client.id.get_role(id_=self.config.new_role,
|
||||||
guild=self.client.get_guild(
|
guilds=[self.client.get_guild(
|
||||||
self.client.config.main_guild)))
|
self.client.config.main_guild)]))
|
||||||
await member.send(self.config.motd)
|
await member.send(self.config.motd)
|
||||||
|
@ -26,11 +26,11 @@ class MainClass(BaseClassPython):
|
|||||||
return
|
return
|
||||||
if message.channel.id == self.config.listen_chan:
|
if message.channel.id == self.config.listen_chan:
|
||||||
if message.content.lower() in self.config.passwords:
|
if message.content.lower() in self.config.passwords:
|
||||||
new_role = await self.client.id.get_role(id_=self.config.new_role, guild=message.channel.guild)
|
new_role = await self.client.id.get_role(id_=self.config.new_role, guilds=[message.channel.guild])
|
||||||
if new_role in message.author.roles:
|
if new_role in message.author.roles:
|
||||||
await message.author.remove_roles(new_role)
|
await message.author.remove_roles(new_role)
|
||||||
await message.author.add_roles(await self.client.id.get_role(id_=self.config.accepted_role,
|
await message.author.add_roles(await self.client.id.get_role(id_=self.config.accepted_role,
|
||||||
guild=message.channel.guild))
|
guild=[message.channel.guild]))
|
||||||
await message.author.send(self.config.succes_pm)
|
await message.author.send(self.config.succes_pm)
|
||||||
await message.channel.guild.get_channel(self.config.log_chan).send(
|
await message.channel.guild.get_channel(self.config.log_chan).send(
|
||||||
self.config.succes.format(user=message.author.mention))
|
self.config.succes.format(user=message.author.mention))
|
||||||
|
@ -23,7 +23,7 @@ class MainClass(BaseClassPython):
|
|||||||
async def com_list(self, message, args, kwargs):
|
async def com_list(self, message, args, kwargs):
|
||||||
response = discord.Embed(title="Roles disponibles", color=self.config.color)
|
response = discord.Embed(title="Roles disponibles", color=self.config.color)
|
||||||
for id_ in self.config.roles.keys():
|
for id_ in self.config.roles.keys():
|
||||||
role = message.guild.get_role(int(id_))
|
role = message.guild.get_role(id_=int(id_))
|
||||||
if role is not None:
|
if role is not None:
|
||||||
response.add_field(name=role.name, value=f"-> `{self.config.roles[id_]}`", inline=True)
|
response.add_field(name=role.name, value=f"-> `{self.config.roles[id_]}`", inline=True)
|
||||||
await message.channel.send(embed=response)
|
await message.channel.send(embed=response)
|
||||||
@ -34,7 +34,8 @@ class MainClass(BaseClassPython):
|
|||||||
if len(args) <= 1:
|
if len(args) <= 1:
|
||||||
await message.channel.send("Il manque des arguments à la commande")
|
await message.channel.send("Il manque des arguments à la commande")
|
||||||
for role_ in args[1:]:
|
for role_ in args[1:]:
|
||||||
role = await self.client.id.get_role(name=role_, guild=guild, case_sensitive=False)
|
role = await self.client.id.get_role(name=role_, guilds=[guild],
|
||||||
|
check=lambda x: x.name.lower() == role_.lower())
|
||||||
if role is None or str(role.id) not in self.config.roles.keys():
|
if role is None or str(role.id) not in self.config.roles.keys():
|
||||||
await message.channel.send(f"Le role {role_} n'est pas disponible.")
|
await message.channel.send(f"Le role {role_} n'est pas disponible.")
|
||||||
else:
|
else:
|
||||||
@ -46,7 +47,8 @@ class MainClass(BaseClassPython):
|
|||||||
if len(args) <= 1:
|
if len(args) <= 1:
|
||||||
await message.channel.send("Il manque des arguments à la commande")
|
await message.channel.send("Il manque des arguments à la commande")
|
||||||
for role_ in args[1:]:
|
for role_ in args[1:]:
|
||||||
role = await self.client.id.get_role(name=role_, guild=guild, case_sensitive=False)
|
role = await self.client.id.get_role(name=role_, guilds=[guild],
|
||||||
|
check=lambda x: x.name.lower() == role_.lower())
|
||||||
if role is None or str(role.id) not in self.config.roles.keys():
|
if role is None or str(role.id) not in self.config.roles.keys():
|
||||||
await message.channel.send(f"Le role {role_} n'est pas disponible.")
|
await message.channel.send(f"Le role {role_} n'est pas disponible.")
|
||||||
else:
|
else:
|
||||||
@ -58,7 +60,8 @@ class MainClass(BaseClassPython):
|
|||||||
if len(args) <= 1:
|
if len(args) <= 1:
|
||||||
await message.channel.send("Il manque des arguments à la commande")
|
await message.channel.send("Il manque des arguments à la commande")
|
||||||
for role_ in args[1:]:
|
for role_ in args[1:]:
|
||||||
role = await self.client.id.get_role(name=role_, guild=guild, case_sensitive=False)
|
role = await self.client.id.get_role(name=role_, guilds=[guild],
|
||||||
|
check=lambda x: x.name.lower() == role_.lower())
|
||||||
if role is None or str(role.id) not in self.config.roles.keys():
|
if role is None or str(role.id) not in self.config.roles.keys():
|
||||||
await message.channel.send(f"Le role {role_} n'est pas disponible.")
|
await message.channel.send(f"Le role {role_} n'est pas disponible.")
|
||||||
else:
|
else:
|
||||||
@ -70,7 +73,8 @@ class MainClass(BaseClassPython):
|
|||||||
if len(args) < 1:
|
if len(args) < 1:
|
||||||
await message.channel.send("Il manque des arguments à la commande")
|
await message.channel.send("Il manque des arguments à la commande")
|
||||||
for role_ in args:
|
for role_ in args:
|
||||||
role = await self.client.id.get_role(name=role_, guild=guild, case_sensitive=False)
|
role = await self.client.id.get_role(name=role_, guilds=[guild],
|
||||||
|
check=lambda x: x.name.lower() == role_.lower())
|
||||||
if role is None or str(role.id) not in self.config.roles.keys():
|
if role is None or str(role.id) not in self.config.roles.keys():
|
||||||
await message.channel.send(f"Le role {role_} n'est pas disponible.")
|
await message.channel.send(f"Le role {role_} n'est pas disponible.")
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user