Add automatic role assignment on member join for rules acknowledgment
- Introduced a new function `assign_rules_arrival_on_join` to assign the arrival role to members upon joining, based on configuration settings. - Updated the `on_member_join` event to call the new function, enhancing the user experience by providing immediate role assignment. - Modified configuration options in the web application to allow enabling or disabling this feature. - Updated the configurations template to reflect the new role assignment behavior, ensuring clarity for users.
This commit is contained in:
@@ -33,7 +33,7 @@ from discordbot.moderation import (
|
||||
moderation_slash_say,
|
||||
)
|
||||
from discordbot.welcome import sendWelcomeMessage, sendLeaveMessage, updateInviteCache
|
||||
from discordbot.rules_ack import register_persistent_rules_view, on_presentation_message
|
||||
from discordbot.rules_ack import assign_rules_arrival_on_join, register_persistent_rules_view, on_presentation_message
|
||||
from discordbot.patreon import checkPatreonPosts
|
||||
from discordbot.youtube import checkYouTubeVideos
|
||||
from discordbot.auto_rooms import on_voice_state_update_auto_rooms, on_raw_reaction_add_auto_rooms, on_message_auto_rooms, cleanup_orphaned_auto_rooms
|
||||
@@ -254,6 +254,7 @@ async def on_raw_reaction_add(payload: discord.RawReactionActionEvent):
|
||||
|
||||
@bot.event
|
||||
async def on_member_join(member: Member):
|
||||
await assign_rules_arrival_on_join(bot, member)
|
||||
await sendWelcomeMessage(bot, member)
|
||||
|
||||
@bot.event
|
||||
|
||||
@@ -174,6 +174,46 @@ def publish_rules_embed_sync(bot: discord.Client) -> tuple[bool, str]:
|
||||
return False, str(e)
|
||||
|
||||
|
||||
async def assign_rules_arrival_on_join(bot: discord.Client, member: discord.Member) -> None:
|
||||
"""Si activé dans la config, attribue le rôle d'arrivée dès le join (sans attendre le bouton)."""
|
||||
with webapp.app_context():
|
||||
config = ConfigurationHelper()
|
||||
if not config.getValue("rules_ack_enable"):
|
||||
return
|
||||
if not config.getValue("rules_arrival_on_join_enable"):
|
||||
return
|
||||
arrival_id = config.getIntValue("rules_arrival_role_id")
|
||||
validated_id = config.getIntValue("rules_validated_role_id")
|
||||
|
||||
if not arrival_id:
|
||||
return
|
||||
|
||||
guild = member.guild
|
||||
arrival_role = guild.get_role(arrival_id)
|
||||
if not arrival_role:
|
||||
logging.warning("assign_rules_arrival_on_join: rôle d'arrivée %s introuvable sur %s", arrival_id, guild.id)
|
||||
return
|
||||
|
||||
if validated_id:
|
||||
validated_role = guild.get_role(validated_id)
|
||||
if validated_role and validated_role in member.roles:
|
||||
return
|
||||
|
||||
if arrival_role in member.roles:
|
||||
return
|
||||
|
||||
try:
|
||||
await member.add_roles(arrival_role, reason="Règlement : rôle d'arrivée à la connexion")
|
||||
except discord.Forbidden:
|
||||
logging.warning(
|
||||
"assign_rules_arrival_on_join: permission refusée pour %s sur %s (hiérarchie des rôles ?)",
|
||||
member.id,
|
||||
guild.id,
|
||||
)
|
||||
except discord.HTTPException as e:
|
||||
logging.warning("assign_rules_arrival_on_join: %s", e)
|
||||
|
||||
|
||||
async def on_presentation_message(bot: discord.Client, message: discord.Message) -> None:
|
||||
if message.author.bot:
|
||||
return
|
||||
|
||||
@@ -50,6 +50,7 @@ def updateConfiguration():
|
||||
'auto_rooms_enable': 'auto_rooms_channel_id',
|
||||
'twitch_commands_enable': 'twitch_channel',
|
||||
'rules_ack_enable': 'rules_channel_id',
|
||||
'rules_arrival_on_join_enable': 'rules_ack_section_in_form',
|
||||
}
|
||||
|
||||
# Ne mettre à jour les rôles staff que si la liste a été rendue dans le formulaire.
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
<div class="bg-gray-50 dark:bg-gray-700/50 rounded-lg p-4 space-y-4">
|
||||
<h3 class="font-medium text-gray-800 dark:text-gray-200">Règlement (embed + bouton)</h3>
|
||||
<p class="text-sm text-gray-600 dark:text-gray-400">
|
||||
Publie un message fixe dans un canal avec un embed et un bouton « J'ai lu le règlement ». Au clic, le membre reçoit le rôle d'arrivée. Si un canal « présentation » est configuré, le premier message du membre dans ce canal lui attribue le rôle membre validé et retire le rôle d'arrivée.
|
||||
Publie un message fixe dans un canal avec un embed et un bouton « J'ai lu le règlement ». Par défaut, le <strong>rôle d'arrivée</strong> n'est donné qu'au <strong>clic sur le bouton</strong> (pas automatiquement en rejoignant le serveur). Tu peux cocher l'option ci-dessous pour l'attribuer aussi dès le join. Si un canal « présentation » est configuré, le premier message du membre (avec le rôle d'arrivée) dans ce canal lui attribue le rôle membre validé et retire le rôle d'arrivée — utilise un canal où les nouveaux peuvent écrire (souvent différent du salon charte en lecture seule).
|
||||
</p>
|
||||
<input type="hidden" name="rules_ack_section_in_form" value="1">
|
||||
<label class="flex items-center gap-2 cursor-pointer">
|
||||
@@ -84,6 +84,11 @@
|
||||
class="w-5 h-5 rounded border-gray-300 dark:border-gray-600 text-indigo-600 focus:ring-indigo-500 dark:bg-gray-700">
|
||||
<span class="text-sm text-gray-700 dark:text-gray-300">Activer le règlement avec bouton</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-2 cursor-pointer">
|
||||
<input type="checkbox" name="rules_arrival_on_join_enable" {% if configuration.getValue('rules_arrival_on_join_enable') %}checked{% endif %}
|
||||
class="w-5 h-5 rounded border-gray-300 dark:border-gray-600 text-indigo-600 focus:ring-indigo-500 dark:bg-gray-700">
|
||||
<span class="text-sm text-gray-700 dark:text-gray-300">Donner le rôle d'arrivée dès qu'un membre rejoint le serveur (en plus du bouton)</span>
|
||||
</label>
|
||||
<div>
|
||||
<label for="rules_channel_id" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Canal du règlement (message + bouton)</label>
|
||||
<select name="rules_channel_id" id="rules_channel_id"
|
||||
@@ -116,7 +121,7 @@
|
||||
</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label for="rules_arrival_role_id" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Rôle d'arrivée (au clic sur le bouton)</label>
|
||||
<label for="rules_arrival_role_id" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">Rôle d'arrivée (bouton, et à la connexion si l'option ci-dessus est cochée)</label>
|
||||
<select name="rules_arrival_role_id" id="rules_arrival_role_id"
|
||||
class="w-full px-4 py-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:ring-2 focus:ring-indigo-500 focus:border-transparent transition-all">
|
||||
<option value="">— Aucun —</option>
|
||||
|
||||
Reference in New Issue
Block a user