EveCogs/wormhole/ui/modals.py

86 lines
3.2 KiB
Python
Raw Permalink Normal View History

refactor: Wormhole v4.0.0 — full modular architecture with hierarchical staff BREAKING: Complete cog restructure from monolithic wormhole.py into modular architecture. ## Architecture - models/permissions.py — Role IntEnum (MEMBER→OWNER), requires_role() decorator - models/config.py — DEFAULT_NETWORK/DEFAULT_GLOBAL with 80+ config keys - models/message_map.py — MessageMap class (extracted from _MessageMap) - services/emoji.py — Foreign emoji resolution and relay - ui/views.py — Reply jump button view - ui/modals.py — Report modal - core.py — Main Wormhole class, helpers, background loops, context menus - commands/ — 13 command modules as mixin classes - listeners/ — relay pipeline, edit/delete/reaction sync, typing/pin sync ## Staff System (new) Per-network hierarchical roles replacing flat owner/staff: Bot Owner (Red built-in) — global override └─ Network Owner → Admin → Moderator → Helper → Member Each role assigned per-network. Higher roles can assign lower. Legacy staff_ids auto-migrated to ADMIN role. ## Enhanced Moderation - Server-level ban/mute (not just user-level) - Allowlist mode (only whitelisted servers can send) - Mod edit and nuke (delete N messages by user) - Anti-raid detector with auto-freeze - Expanded automod: anti-zalgo, anti-emote-spam, anti-newline-spam ## Commands (100+) network, settings, staff, moderation, filters, social, dm, mentions, tos, reports, bridge, advanced (polls/afk/auto-responses/scheduled/ analytics/quiet-hours/colours/invites/announcements/blackout/portal), debug (health/trace/testsend/relaydebug/backup/restore/version) ## Files - 30 Python files, 5,274 lines total (was 4,782 in monolith) - Original wormhole.py preserved for reference - utils.py unchanged (all helpers reused)
2026-05-14 19:07:49 +00:00
"""Discord UI modals for Wormhole (e.g. report form)."""
from __future__ import annotations
from datetime import datetime, timezone
from typing import TYPE_CHECKING
import discord
Re-enable Report/Delete/Profile context menus, remove Bookmark, fix reports Re-enabled the "Report to Wormhole", "Delete from Network", and "Wormhole Profile" context menus (previously disabled entirely). Removed "Bookmark (Wormhole)" per request — the prefix `wh bm list`/`clear` commands are untouched, but note this was the only way to *add* a bookmark, so that feature is now list/clear-only for existing entries. Wormhole Profile is now considerably richer: account creation date, total cross-network message count, global-ban status, and per-network karma/ server-count/muted/banned status, sorted busiest-network-first. Fixed both report-creation paths (the "Report to Wormhole" context menu's modal, and `wh report msg`): report_counter was read before the config lock and written after, so concurrent reports could collide on the same id with the counter never advancing. Now computed and saved atomically inside the lock. Also gave both paths full parity — message id, jump link, and a real content preview (the context-menu path previously stored `hash()` of the content, which is randomized per-process in Python 3 and useless for anything; the prefix-command path never even recorded who wrote the message). `wh report view` now surfaces all of it. Also added the "Find Origin" context menu (right-click a message -> find its true source server/channel/author across the network) as a separate, complementary feature to Profile — not a replacement. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-29 00:02:49 +01:00
from ..utils import ok_embed, truncate, warn_embed
refactor: Wormhole v4.0.0 — full modular architecture with hierarchical staff BREAKING: Complete cog restructure from monolithic wormhole.py into modular architecture. ## Architecture - models/permissions.py — Role IntEnum (MEMBER→OWNER), requires_role() decorator - models/config.py — DEFAULT_NETWORK/DEFAULT_GLOBAL with 80+ config keys - models/message_map.py — MessageMap class (extracted from _MessageMap) - services/emoji.py — Foreign emoji resolution and relay - ui/views.py — Reply jump button view - ui/modals.py — Report modal - core.py — Main Wormhole class, helpers, background loops, context menus - commands/ — 13 command modules as mixin classes - listeners/ — relay pipeline, edit/delete/reaction sync, typing/pin sync ## Staff System (new) Per-network hierarchical roles replacing flat owner/staff: Bot Owner (Red built-in) — global override └─ Network Owner → Admin → Moderator → Helper → Member Each role assigned per-network. Higher roles can assign lower. Legacy staff_ids auto-migrated to ADMIN role. ## Enhanced Moderation - Server-level ban/mute (not just user-level) - Allowlist mode (only whitelisted servers can send) - Mod edit and nuke (delete N messages by user) - Anti-raid detector with auto-freeze - Expanded automod: anti-zalgo, anti-emote-spam, anti-newline-spam ## Commands (100+) network, settings, staff, moderation, filters, social, dm, mentions, tos, reports, bridge, advanced (polls/afk/auto-responses/scheduled/ analytics/quiet-hours/colours/invites/announcements/blackout/portal), debug (health/trace/testsend/relaydebug/backup/restore/version) ## Files - 30 Python files, 5,274 lines total (was 4,782 in monolith) - Original wormhole.py preserved for reference - utils.py unchanged (all helpers reused)
2026-05-14 19:07:49 +00:00
if TYPE_CHECKING:
from ..core import Wormhole
class ReportModal(discord.ui.Modal, title="Report Message"):
reason = discord.ui.TextInput(
label="Reason",
style=discord.TextStyle.paragraph,
placeholder="Describe why you're reporting this message...",
required=True,
max_length=1000,
)
def __init__(self, cog: Wormhole, net_name: str, message: discord.Message) -> None:
super().__init__()
self.cog = cog
self.net_name = net_name
self.message = message
async def on_submit(self, interaction: discord.Interaction) -> None:
Re-enable Report/Delete/Profile context menus, remove Bookmark, fix reports Re-enabled the "Report to Wormhole", "Delete from Network", and "Wormhole Profile" context menus (previously disabled entirely). Removed "Bookmark (Wormhole)" per request — the prefix `wh bm list`/`clear` commands are untouched, but note this was the only way to *add* a bookmark, so that feature is now list/clear-only for existing entries. Wormhole Profile is now considerably richer: account creation date, total cross-network message count, global-ban status, and per-network karma/ server-count/muted/banned status, sorted busiest-network-first. Fixed both report-creation paths (the "Report to Wormhole" context menu's modal, and `wh report msg`): report_counter was read before the config lock and written after, so concurrent reports could collide on the same id with the counter never advancing. Now computed and saved atomically inside the lock. Also gave both paths full parity — message id, jump link, and a real content preview (the context-menu path previously stored `hash()` of the content, which is randomized per-process in Python 3 and useless for anything; the prefix-command path never even recorded who wrote the message). `wh report view` now surfaces all of it. Also added the "Find Origin" context menu (right-click a message -> find its true source server/channel/author across the network) as a separate, complementary feature to Profile — not a replacement. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-29 00:02:49 +01:00
# report_id must be computed and written inside the same locked
# section — reading report_counter beforehand let two concurrent
# reports land on the same id and left the counter not advanced.
refactor: Wormhole v4.0.0 — full modular architecture with hierarchical staff BREAKING: Complete cog restructure from monolithic wormhole.py into modular architecture. ## Architecture - models/permissions.py — Role IntEnum (MEMBER→OWNER), requires_role() decorator - models/config.py — DEFAULT_NETWORK/DEFAULT_GLOBAL with 80+ config keys - models/message_map.py — MessageMap class (extracted from _MessageMap) - services/emoji.py — Foreign emoji resolution and relay - ui/views.py — Reply jump button view - ui/modals.py — Report modal - core.py — Main Wormhole class, helpers, background loops, context menus - commands/ — 13 command modules as mixin classes - listeners/ — relay pipeline, edit/delete/reaction sync, typing/pin sync ## Staff System (new) Per-network hierarchical roles replacing flat owner/staff: Bot Owner (Red built-in) — global override └─ Network Owner → Admin → Moderator → Helper → Member Each role assigned per-network. Higher roles can assign lower. Legacy staff_ids auto-migrated to ADMIN role. ## Enhanced Moderation - Server-level ban/mute (not just user-level) - Allowlist mode (only whitelisted servers can send) - Mod edit and nuke (delete N messages by user) - Anti-raid detector with auto-freeze - Expanded automod: anti-zalgo, anti-emote-spam, anti-newline-spam ## Commands (100+) network, settings, staff, moderation, filters, social, dm, mentions, tos, reports, bridge, advanced (polls/afk/auto-responses/scheduled/ analytics/quiet-hours/colours/invites/announcements/blackout/portal), debug (health/trace/testsend/relaydebug/backup/restore/version) ## Files - 30 Python files, 5,274 lines total (was 4,782 in monolith) - Original wormhole.py preserved for reference - utils.py unchanged (all helpers reused)
2026-05-14 19:07:49 +00:00
async with self.cog.config.networks() as ns:
Re-enable Report/Delete/Profile context menus, remove Bookmark, fix reports Re-enabled the "Report to Wormhole", "Delete from Network", and "Wormhole Profile" context menus (previously disabled entirely). Removed "Bookmark (Wormhole)" per request — the prefix `wh bm list`/`clear` commands are untouched, but note this was the only way to *add* a bookmark, so that feature is now list/clear-only for existing entries. Wormhole Profile is now considerably richer: account creation date, total cross-network message count, global-ban status, and per-network karma/ server-count/muted/banned status, sorted busiest-network-first. Fixed both report-creation paths (the "Report to Wormhole" context menu's modal, and `wh report msg`): report_counter was read before the config lock and written after, so concurrent reports could collide on the same id with the counter never advancing. Now computed and saved atomically inside the lock. Also gave both paths full parity — message id, jump link, and a real content preview (the context-menu path previously stored `hash()` of the content, which is randomized per-process in Python 3 and useless for anything; the prefix-command path never even recorded who wrote the message). `wh report view` now surfaces all of it. Also added the "Find Origin" context menu (right-click a message -> find its true source server/channel/author across the network) as a separate, complementary feature to Profile — not a replacement. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-29 00:02:49 +01:00
nd = ns.get(self.net_name)
if not nd:
await interaction.response.send_message("Network not found.", ephemeral=True)
return
report_id = nd.get("report_counter", 0) + 1
report = {
"id": report_id,
"reporter_id": interaction.user.id,
"author_id": self.message.author.id,
"message_id": self.message.id,
"channel_id": self.message.channel.id,
"guild_id": self.message.guild.id if self.message.guild else None,
"content_preview": truncate(self.message.content or "*[no text]*", 300),
"jump_url": self.message.jump_url,
"reason": self.reason.value,
"timestamp": datetime.now(timezone.utc).isoformat(),
"resolved": False,
"resolved_by": None,
"resolution": None,
}
nd.setdefault("reports", []).append(report)
nd["report_counter"] = report_id
refactor: Wormhole v4.0.0 — full modular architecture with hierarchical staff BREAKING: Complete cog restructure from monolithic wormhole.py into modular architecture. ## Architecture - models/permissions.py — Role IntEnum (MEMBER→OWNER), requires_role() decorator - models/config.py — DEFAULT_NETWORK/DEFAULT_GLOBAL with 80+ config keys - models/message_map.py — MessageMap class (extracted from _MessageMap) - services/emoji.py — Foreign emoji resolution and relay - ui/views.py — Reply jump button view - ui/modals.py — Report modal - core.py — Main Wormhole class, helpers, background loops, context menus - commands/ — 13 command modules as mixin classes - listeners/ — relay pipeline, edit/delete/reaction sync, typing/pin sync ## Staff System (new) Per-network hierarchical roles replacing flat owner/staff: Bot Owner (Red built-in) — global override └─ Network Owner → Admin → Moderator → Helper → Member Each role assigned per-network. Higher roles can assign lower. Legacy staff_ids auto-migrated to ADMIN role. ## Enhanced Moderation - Server-level ban/mute (not just user-level) - Allowlist mode (only whitelisted servers can send) - Mod edit and nuke (delete N messages by user) - Anti-raid detector with auto-freeze - Expanded automod: anti-zalgo, anti-emote-spam, anti-newline-spam ## Commands (100+) network, settings, staff, moderation, filters, social, dm, mentions, tos, reports, bridge, advanced (polls/afk/auto-responses/scheduled/ analytics/quiet-hours/colours/invites/announcements/blackout/portal), debug (health/trace/testsend/relaydebug/backup/restore/version) ## Files - 30 Python files, 5,274 lines total (was 4,782 in monolith) - Original wormhole.py preserved for reference - utils.py unchanged (all helpers reused)
2026-05-14 19:07:49 +00:00
owner = self.cog.bot.get_user(nd.get("owner_id"))
if owner:
try:
await owner.send(
embed=warn_embed(
f"**Report #{report_id}** in `{self.net_name}`\n"
f"Reporter: {interaction.user} (`{interaction.user.id}`)\n"
f"Author: {self.message.author} (`{self.message.author.id}`)\n"
f"Reason: {self.reason.value}",
title="🚩 New Report",
)
)
except discord.Forbidden:
pass
# Notify configured report channel with action buttons
try:
nd_full = await self.cog._net(self.net_name)
await self.cog._notify_report_channel(nd_full, self.net_name, report)
except Exception:
pass
refactor: Wormhole v4.0.0 — full modular architecture with hierarchical staff BREAKING: Complete cog restructure from monolithic wormhole.py into modular architecture. ## Architecture - models/permissions.py — Role IntEnum (MEMBER→OWNER), requires_role() decorator - models/config.py — DEFAULT_NETWORK/DEFAULT_GLOBAL with 80+ config keys - models/message_map.py — MessageMap class (extracted from _MessageMap) - services/emoji.py — Foreign emoji resolution and relay - ui/views.py — Reply jump button view - ui/modals.py — Report modal - core.py — Main Wormhole class, helpers, background loops, context menus - commands/ — 13 command modules as mixin classes - listeners/ — relay pipeline, edit/delete/reaction sync, typing/pin sync ## Staff System (new) Per-network hierarchical roles replacing flat owner/staff: Bot Owner (Red built-in) — global override └─ Network Owner → Admin → Moderator → Helper → Member Each role assigned per-network. Higher roles can assign lower. Legacy staff_ids auto-migrated to ADMIN role. ## Enhanced Moderation - Server-level ban/mute (not just user-level) - Allowlist mode (only whitelisted servers can send) - Mod edit and nuke (delete N messages by user) - Anti-raid detector with auto-freeze - Expanded automod: anti-zalgo, anti-emote-spam, anti-newline-spam ## Commands (100+) network, settings, staff, moderation, filters, social, dm, mentions, tos, reports, bridge, advanced (polls/afk/auto-responses/scheduled/ analytics/quiet-hours/colours/invites/announcements/blackout/portal), debug (health/trace/testsend/relaydebug/backup/restore/version) ## Files - 30 Python files, 5,274 lines total (was 4,782 in monolith) - Original wormhole.py preserved for reference - utils.py unchanged (all helpers reused)
2026-05-14 19:07:49 +00:00
await interaction.response.send_message(
embed=ok_embed(f"Report #{report_id} submitted. Staff will review it."),
ephemeral=True,
)