mirror of
https://github.com/p08dev/cogs.git
synced 2026-06-17 12:43:51 +02:00
try removing only exclusive roles
This commit is contained in:
@ -1,8 +1,8 @@
|
|||||||
from .exclusiverole import ExclusiveRole
|
from .exclusiveroles import ExclusiveRoles
|
||||||
|
|
||||||
|
|
||||||
async def setup(bot):
|
async def setup(bot):
|
||||||
cog = ExclusiveRole(bot)
|
cog = ExclusiveRoles(bot)
|
||||||
r = bot.add_cog(cog)
|
r = bot.add_cog(cog)
|
||||||
if r is not None:
|
if r is not None:
|
||||||
await r
|
await r
|
||||||
@ -5,7 +5,7 @@ from redbot.core import Config, checks, commands
|
|||||||
from redbot.core.commands import Cog
|
from redbot.core.commands import Cog
|
||||||
|
|
||||||
|
|
||||||
class ExclusiveRole(Cog):
|
class ExclusiveRoles(Cog):
|
||||||
"""
|
"""
|
||||||
Create roles that prevent all other exclusive roles from being added
|
Create roles that prevent all other exclusive roles from being added
|
||||||
"""
|
"""
|
||||||
@ -40,7 +40,7 @@ class ExclusiveRole(Cog):
|
|||||||
async with self.config.guild(ctx.guild).role_list() as rl:
|
async with self.config.guild(ctx.guild).role_list() as rl:
|
||||||
rl.append(role.id)
|
rl.append(role.id)
|
||||||
|
|
||||||
await self.check_guild(ctx.guild)
|
#await self.check_guild(ctx.guild)
|
||||||
|
|
||||||
await ctx.send("Exclusive role added")
|
await ctx.send("Exclusive role added")
|
||||||
|
|
||||||
@ -85,28 +85,11 @@ class ExclusiveRole(Cog):
|
|||||||
role_set = set(await self.config.guild(member.guild).role_list())
|
role_set = set(await self.config.guild(member.guild).role_list())
|
||||||
|
|
||||||
member_set = {role.id for role in member.roles}
|
member_set = {role.id for role in member.roles}
|
||||||
|
to_remove = (member_set - role_set) - {member.guild.default_role.id}
|
||||||
|
|
||||||
# Rolle für exklusive Rollen
|
if to_remove and member_set & role_set:
|
||||||
exclusive_roles = {role.id for role in role_set if role.is_exclusive} # Beispiel, du kannst dies je nach Implementierung anpassen
|
to_remove = [discord.utils.get(member.guild.roles, id=r_id) for r_id in to_remove]
|
||||||
|
await member.remove_roles(*to_remove, reason="Exclusive roles")
|
||||||
# Prüfen, ob bereits eine exklusive Rolle gesetzt ist
|
|
||||||
existing_exclusive_roles = member_set & exclusive_roles
|
|
||||||
|
|
||||||
if existing_exclusive_roles:
|
|
||||||
# Entferne alle exklusiven Rollen, wenn eine andere exklusive Rolle gesetzt wird
|
|
||||||
to_remove = [discord.utils.get(member.guild.roles, id=r_id) for r_id in existing_exclusive_roles]
|
|
||||||
await member.remove_roles(*to_remove, reason="Exclusive role replaced")
|
|
||||||
|
|
||||||
# Jetzt die neue exklusive Rolle hinzufügen, falls sie gesetzt ist
|
|
||||||
new_exclusive_role = next((role for role in role_set if role.id not in member_set), None)
|
|
||||||
if new_exclusive_role:
|
|
||||||
await member.add_roles(new_exclusive_role, reason="Exclusive role added")
|
|
||||||
|
|
||||||
# Entferne alle nicht-exklusiven Rollen, die gesetzt sind
|
|
||||||
to_remove_non_exclusive = (member_set - role_set) - {member.guild.default_role.id} - exclusive_roles
|
|
||||||
if to_remove_non_exclusive:
|
|
||||||
to_remove_non_exclusive = [discord.utils.get(member.guild.roles, id=r_id) for r_id in to_remove_non_exclusive]
|
|
||||||
await member.remove_roles(*to_remove_non_exclusive, reason="Non-exclusive roles removed")
|
|
||||||
|
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
@ -120,10 +103,14 @@ class ExclusiveRole(Cog):
|
|||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
role_set = set(await self.config.guild(after.guild).role_list())
|
role_set = set(await self.config.guild(after.guild).role_list())
|
||||||
member_set = {role.id for role in after.roles}
|
new_exclusive_roles = [role for role in after.roles if role.id in role_set]
|
||||||
|
|
||||||
|
if len(new_exclusive_roles) > 1:
|
||||||
|
added_roles = [role for role in new_exclusive_roles if role not in before.roles]
|
||||||
|
keep_role = added_roles[-1] if added_roles else new_exclusive_roles[-1]
|
||||||
|
roles_to_remove = [role for role in new_exclusive_roles if role != keep_role]
|
||||||
|
|
||||||
if role_set & member_set:
|
|
||||||
try:
|
try:
|
||||||
await self.remove_non_exclusive_roles(after, role_set=role_set)
|
await after.remove_roles(*roles_to_remove)
|
||||||
except discord.Forbidden:
|
except discord.Forbidden:
|
||||||
pass
|
pass
|
||||||
@ -6,7 +6,7 @@
|
|||||||
"min_bot_version": "3.4.0",
|
"min_bot_version": "3.4.0",
|
||||||
"description": "Assign roles to be exclusive, preventing other exclusive roles from being added. Normal roles are unaffected.",
|
"description": "Assign roles to be exclusive, preventing other exclusive roles from being added. Normal roles are unaffected.",
|
||||||
"hidden": false,
|
"hidden": false,
|
||||||
"install_msg": "Thank you for installing ExclusiveRole. Get started with `[p]load exclusiverole` and `[p]help ExclusiveRole`",
|
"install_msg": "Thank you for installing ExclusiveRoles. Get started with `[p]load exclusiverole` and `[p]help ExclusiveRole`",
|
||||||
"short": "Set roles to be exclusive",
|
"short": "Set roles to be exclusive",
|
||||||
"end_user_data_statement": "This cog does not store any End User Data",
|
"end_user_data_statement": "This cog does not store any End User Data",
|
||||||
"tags": [
|
"tags": [
|
||||||
|
|||||||
Reference in New Issue
Block a user