welcome.py fixed to greet only new users. timezone plugin added.
This commit is contained in:
+24
-12
@@ -2,7 +2,7 @@
|
||||
Plugin for welcoming new users to the room.
|
||||
|
||||
Features:
|
||||
* Automatically greets users when they join the target room.
|
||||
* Automatically greets users when they first join the target room.
|
||||
* !welcome command – manually trigger the welcome message for yourself.
|
||||
* Per-user cooldown to prevent welcome spam on repeated part/join cycles.
|
||||
|
||||
@@ -52,17 +52,7 @@ def _record_welcome(user_id: str) -> None:
|
||||
|
||||
def _build_welcome_message(display_name: str) -> str:
|
||||
"""Return the Markdown welcome message for a given display name."""
|
||||
return (
|
||||
f"Welcome to the room, **{display_name}**! 🎉\n\n"
|
||||
"We're glad to have you here in "
|
||||
"**Self‑hosting | Security | Sysadmin | Homelab | Programming**!\n\n"
|
||||
"To help us get to know you better:\n"
|
||||
"• 🔧 **What do you self‑host?** Got any cool services running?\n"
|
||||
"• 🔐 **Are you into cybersecurity?** What areas interest you most?\n"
|
||||
"• 💻 **What programming languages do you use?**\n"
|
||||
"• 🏠 **Tell us about your homelab setup!**\n\n"
|
||||
"Feel free to introduce yourself and jump into the conversation! 🍄"
|
||||
)
|
||||
return f"Hey **{display_name}**, welcome in — so glad to have you here! 🎉 Feel free to tell us a bit about what you're into (self‑hosting, security, homelabs, programming… or just lurk and say hi whenever 🍄)"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -97,6 +87,28 @@ def setup(bot):
|
||||
logging.debug("Ignoring bot's own join event")
|
||||
return
|
||||
|
||||
# Check if this is a genuine first join by looking for previous membership
|
||||
is_first_join = True
|
||||
|
||||
# Check prev_content directly on the event
|
||||
if hasattr(event, 'prev_content') and event.prev_content:
|
||||
prev_membership = event.prev_content.get('membership')
|
||||
if prev_membership is not None:
|
||||
is_first_join = False
|
||||
logging.debug(f"User {event.sender} had previous membership '{prev_membership}' in prev_content")
|
||||
|
||||
# Check unsigned field (some events store prev_content there)
|
||||
if is_first_join and hasattr(event, 'unsigned') and event.unsigned:
|
||||
prev_content = event.unsigned.get('prev_content', {})
|
||||
prev_membership = prev_content.get('membership')
|
||||
if prev_membership is not None:
|
||||
is_first_join = False
|
||||
logging.debug(f"User {event.sender} had previous membership '{prev_membership}' in unsigned")
|
||||
|
||||
if not is_first_join:
|
||||
logging.info(f"Skipping welcome for {event.sender} - not a first join (name change or rejoin)")
|
||||
return
|
||||
|
||||
# --- Cooldown check ---
|
||||
if _is_on_cooldown(event.sender):
|
||||
remaining = WELCOME_COOLDOWN_SECONDS - (
|
||||
|
||||
Reference in New Issue
Block a user