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)
83 lines
3.6 KiB
Python
83 lines
3.6 KiB
Python
"""ToS / Rules acceptance gate commands."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime, timezone
|
|
|
|
import discord
|
|
from redbot.core import commands
|
|
|
|
from ..models.permissions import Role, requires_role
|
|
from ..utils import ok_embed, err_embed, info_embed, COLOUR_INFO
|
|
|
|
|
|
class ToSCommands:
|
|
"""Mixin — Terms of Service / rules acceptance gate."""
|
|
|
|
@commands.group(name="wh-rules", aliases=["whrules"], invoke_without_command=True)
|
|
async def wh_rules(self, ctx: commands.Context) -> None:
|
|
"""Network rules / Terms of Service."""
|
|
await ctx.send_help(ctx.command)
|
|
|
|
@wh_rules.command(name="set")
|
|
@requires_role(Role.ADMIN)
|
|
async def wh_rules_set(self, ctx: commands.Context, name: str, *, text: str) -> None:
|
|
"""Set the rules / ToS text."""
|
|
async with self.config.networks() as ns:
|
|
ns[name]["rules_text"] = text
|
|
await ctx.send(embed=ok_embed(f"Rules updated for `{name}`."))
|
|
|
|
@wh_rules.command(name="require")
|
|
@requires_role(Role.ADMIN)
|
|
async def wh_rules_require(self, ctx: commands.Context, name: str, enabled: bool = True) -> None:
|
|
"""Toggle mandatory rules acceptance before using the network."""
|
|
async with self.config.networks() as ns:
|
|
ns[name]["rules_required"] = enabled
|
|
await ctx.send(embed=ok_embed(
|
|
f"Rules acceptance {'required' if enabled else 'not required'} for `{name}`."
|
|
))
|
|
|
|
@wh_rules.command(name="view")
|
|
async def wh_rules_view(self, ctx: commands.Context, name: str) -> None:
|
|
"""View the network rules."""
|
|
nd = await self._net(name)
|
|
if not nd:
|
|
return await ctx.send(embed=err_embed(f"Network `{name}` not found."))
|
|
text = nd.get("rules_text") or nd.get("rules") or "No rules set."
|
|
em = discord.Embed(
|
|
title=f"📜 Rules — {name}",
|
|
description=text[:4000],
|
|
colour=COLOUR_INFO,
|
|
)
|
|
accepted = nd.get("rules_accepted", {}).get(str(ctx.author.id))
|
|
if accepted:
|
|
em.set_footer(text=f"You accepted on {accepted[:10]}")
|
|
else:
|
|
em.set_footer(text="⚠️ You haven't accepted these rules yet. Use `wh accept` or `wh agree`.")
|
|
await ctx.send(embed=em)
|
|
|
|
@commands.hybrid_command(name="wh-accept")
|
|
async def wh_accept(self, ctx: commands.Context, name: str) -> None:
|
|
"""Accept the network rules / ToS."""
|
|
nd = await self._net(name)
|
|
if not nd:
|
|
return await ctx.send(embed=err_embed(f"Network `{name}` not found."))
|
|
if not nd.get("rules_required"):
|
|
return await ctx.send(embed=info_embed("This network doesn't require rules acceptance."))
|
|
async with self.config.networks() as ns:
|
|
ns[name].setdefault("rules_accepted", {})[str(ctx.author.id)] = datetime.now(timezone.utc).isoformat()
|
|
await ctx.send(embed=ok_embed(f"You've accepted the rules for `{name}`. You can now use the relay."))
|
|
|
|
@commands.hybrid_command(name="wh-agree")
|
|
async def wh_agree(self, ctx: commands.Context, name: str) -> None:
|
|
"""Alias for ``wh accept``."""
|
|
await self.wh_accept(ctx, name)
|
|
|
|
@wh_rules.command(name="reset")
|
|
@requires_role(Role.ADMIN)
|
|
async def wh_rules_reset(self, ctx: commands.Context, name: str) -> None:
|
|
"""Reset all acceptances (force everyone to re-accept)."""
|
|
async with self.config.networks() as ns:
|
|
ns[name]["rules_accepted"] = {}
|
|
await ctx.send(embed=ok_embed(f"All acceptances reset for `{name}`. Users must re-accept."))
|
|
await self._audit(name, "rules_reset", str(ctx.author))
|