Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env_example
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ MOD_LOGGING_CHANNEL_ID ="<YOUR_MODDING_LOG_CHANNEL_HERE>"
# NOTIFY_CHANNEL_ID = <NOTIFY_CHANNEL_ID>
# PTC_EVENT_FORUM_ID = "<PTC_EVENT_FORUM_ID>" # Set for PTC event
# PTC_EVENT_FORUM_DURATION = "<PTC_EVENT_FORUM_DURATION(DAYS)>" # Set for PTC event
# EVENT_BOT_ID = "<RAID_HELPER_BOT_ID>" # Set for PTC event
# EVENT_BOT_ID = "<RAID_HELPER_BOT_ID>" # Set for PTC event
# BAN_APPEAL_CHANNEL_ID="<YOUR_BAN_APPEAL_CHANNEL_HERE>" # Set for unique channel for ban appeal pings
4 changes: 4 additions & 0 deletions moddingway/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class Role(StrEnum):
MOD = "Mod"


class RoleIDs(IntEnum):
MOD = 1239623392676548740


class ExileStatus(IntEnum):
TIMED_EXILED = 1
UNEXILED = 2
Expand Down
7 changes: 7 additions & 0 deletions moddingway/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down
45 changes: 43 additions & 2 deletions moddingway_api/routes/banforms_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(),
}
],
}
Comment on lines +77 to +104
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel like this body is too big to be in this function. and honestly i think we can probably benefit a lot if we make this into a class since i would expect we would making a lot more api calls later... although now that i'm thinking about it more, discord.py should be able to send all of this data without doing all of headers and body stuff (see how we make the logging embed)


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("")
Expand Down