imdb plugin added

This commit is contained in:
2026-04-30 22:07:19 -05:00
parent 868b2b7e32
commit c24893e141
4 changed files with 437 additions and 4 deletions
+42 -3
View File
@@ -4,11 +4,13 @@ Plugin for welcoming new users to the room.
Features:
* Automatically greets users when they 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.
Restricted to room: !NXdVjDXPxXowPkrJJY:matrix.org
"""
import logging
import time
import simplematrixbotlib as botlib
import nio
@@ -18,6 +20,32 @@ import nio
ALLOWED_ROOM_ID = "!NXdVjDXPxXowPkrJJY:matrix.org"
# How many seconds must pass before a user can receive another auto-welcome.
# Default: 10 minutes. Raise this if you still see abuse.
WELCOME_COOLDOWN_SECONDS = 600
# ---------------------------------------------------------------------------
# Cooldown state
# Maps Matrix user ID → monotonic timestamp of last auto-welcome sent.
# Resets on bot restart, which is fine — a fresh start is a clean slate.
# ---------------------------------------------------------------------------
_last_welcomed: dict[str, float] = {}
def _is_on_cooldown(user_id: str) -> bool:
"""Return True if the user was welcomed recently and should be skipped."""
last = _last_welcomed.get(user_id)
if last is None:
return False
return (time.monotonic() - last) < WELCOME_COOLDOWN_SECONDS
def _record_welcome(user_id: str) -> None:
"""Mark that this user was just welcomed."""
_last_welcomed[user_id] = time.monotonic()
# ---------------------------------------------------------------------------
# Internal helpers
# ---------------------------------------------------------------------------
@@ -46,8 +74,7 @@ def setup(bot):
Register the member-join listener.
funguy.py must call plugin_module.setup(self.bot) for each loaded plugin
(after self.bot is created) for this listener to fire. See the note in
funguy.py's run() method.
(after self.bot is created) for this listener to fire.
"""
@bot.listener.on_custom_event(nio.RoomMemberEvent)
@@ -70,6 +97,17 @@ def setup(bot):
logging.debug("Ignoring bot's own join event")
return
# --- Cooldown check ---
if _is_on_cooldown(event.sender):
remaining = WELCOME_COOLDOWN_SECONDS - (
time.monotonic() - _last_welcomed[event.sender]
)
logging.info(
"Skipping welcome for %s cooldown active (%.0fs remaining)",
event.sender, remaining,
)
return
# Derive a friendly display name from the Matrix ID (@name:server → name)
display_name = event.sender.split(":")[0].lstrip("@")
@@ -80,6 +118,7 @@ def setup(bot):
await bot.api.send_markdown_message(
room.room_id, _build_welcome_message(display_name)
)
_record_welcome(event.sender) # Only recorded after a successful send
logging.info("Welcome message sent successfully to %s", display_name)
except Exception as exc:
logging.error("Failed to send welcome message: %s", exc)
@@ -92,7 +131,7 @@ def setup(bot):
# ---------------------------------------------------------------------------
async def handle_command(room, message, bot, prefix, config):
"""Handle the !welcome command."""
"""Handle the !welcome command (not subject to the auto-welcome cooldown)."""
match = botlib.MessageMatch(room, message, bot, prefix)