diff --git a/.env_example b/.env_example index 31fdb0b5..ba7c86c1 100644 --- a/.env_example +++ b/.env_example @@ -12,4 +12,5 @@ MOD_LOGGING_CHANNEL_ID ="" # NOTIFY_CHANNEL_ID = # PTC_EVENT_FORUM_ID = "" # Set for PTC event # PTC_EVENT_FORUM_DURATION = "" # Set for PTC event -# EVENT_BOT_ID = "" # Set for PTC event \ No newline at end of file +# EVENT_BOT_ID = "" # Set for PTC event +# BAN_APPEAL_CHANNEL_ID="" # Set for unique channel for ban appeal pings \ No newline at end of file diff --git a/moddingway/constants.py b/moddingway/constants.py index dfd05258..152a9f3e 100644 --- a/moddingway/constants.py +++ b/moddingway/constants.py @@ -9,6 +9,10 @@ class Role(StrEnum): MOD = "Mod" +class RoleIDs(IntEnum): + MOD = 1239623392676548740 + + class ExileStatus(IntEnum): TIMED_EXILED = 1 UNEXILED = 2 diff --git a/moddingway/settings.py b/moddingway/settings.py index 3e62e03c..023276b4 100644 --- a/moddingway/settings.py +++ b/moddingway/settings.py @@ -14,6 +14,7 @@ class Settings(BaseModel): discord_token: str = os.environ.get("DISCORD_TOKEN") log_level: int = logging.INFO logging_channel_id: int + ban_appeal_channel_id: int notify_channel_id: int postgres_host: str postgres_port: str @@ -33,6 +34,7 @@ def prod() -> Settings: return Settings( guild_id=1172230157776466050, logging_channel_id=1172324840947056681, # mod-reports + ban_appeal_channel_id=1427894869929758811, notify_channel_id=1279952544235524269, # bot-channel log_level=logging.INFO, postgres_host=os.environ.get("POSTGRES_HOST"), @@ -66,9 +68,14 @@ def local() -> Settings: if notify_channel_id == "": notify_channel_id = os.environ.get("MOD_LOGGING_CHANNEL_ID", 0) + ban_appeal_channel_id = os.environ.get("BAN_APPEAL_CHANNEL_ID", "") + if ban_appeal_channel_id == "": + ban_appeal_channel_id = os.environ.get("MOD_LOGGING_CHANNEL_ID", 0) + return Settings( guild_id=int(os.environ.get("GUILD_ID", 0)), logging_channel_id=int(os.environ.get("MOD_LOGGING_CHANNEL_ID", 0)), + ban_appeal_channel_id=ban_appeal_channel_id, log_level=logging.DEBUG, postgres_host=os.environ.get("POSTGRES_HOST", "localhost"), postgres_port=os.environ.get("POSTGRES_PORT", "5432"), diff --git a/moddingway_api/routes/banforms_routes.py b/moddingway_api/routes/banforms_routes.py index b06e7c09..0593327c 100644 --- a/moddingway_api/routes/banforms_routes.py +++ b/moddingway_api/routes/banforms_routes.py @@ -11,6 +11,7 @@ from moddingway.database import banforms_database, users_database from moddingway.database.models import BanForm from moddingway.util import get_log_channel, create_interaction_embed_context +from moddingway.constants import RoleIDs from moddingway_api.schemas.ban_form_schema import FormRequest, UpdateRequest from moddingway_api.routes.banneduser_routes import unban_user @@ -69,14 +70,54 @@ async def submit_form(request: FormRequest): ) result = banforms_database.add_form(form) - if result: - # TODO: logging to moddingway + # Set variables for use in HTTPX + url = f"https://discord.com/api/v10/channels/{settings.ban_appeal_channel_id}/messages" + headers = authHeader + body = { + "content": f"<@&{RoleIDs.MOD}> ", + "allowed_mentions": {"parse": ["roles"]}, + "embeds": [ + { + "title": "Ban Appeal Submitted", + "description": ( + f"Ban appeal form submitted by <@{request.user_id}> " + f"(form ID: {result})." + ), + "fields": [ + { + # TODO: Add character limiting; fails to send on more than 1024 characters + "name": "Reason", + "value": request.reason, + "inline": False, + }, + { + "name": "Submission", + "value": f"To view request details, please refer to the [mod portal](https://naurffxiv.com/mod-portal/unban-appeals/).", # add {result} to end of link when forms are functioning to link directly to requested form + "inline": False, + }, + ], + "footer": {"text": f"ID: {request.user_id}"}, + "timestamp": datetime.now(timezone.utc).isoformat(), + } + ], + } + + try: + async with httpx.AsyncClient() as client: + await client.post(url, headers=headers, json=body) + + except Exception as e: + # Log but do not block the API response + logger.error( + f"Failed to send banform notification for form {result}: {e}" + ) return {"detail": f"User {request.user_id}'s form has been submitted"} return { "detail": "There was an issue with the form submission, please try again" } + return {"detail": "User ID not found or isn't valid"} @router.patch("")