User Profiles
Relevant source files
The following files were used as context for generating this wiki page:The User Profile system provides a way for Discord users to create and customize a personal profile within the Amina bot. This profile can store a variety of information, including pronouns, age, region, bio, interests, and social media links. The system is designed to be interactive, using Discord modals and buttons for a user-friendly editing experience.
Users can manage their own profile through the /profile command, which opens a management hub. Other users can view a user's public profile information using the /info profile command. The system includes privacy controls, allowing users to decide which pieces of information, such as age and region, are publicly visible. All profile data is stored within the User collection in the database.
Data Schema
The user profile data is stored as a sub-document within the main User schema. The structure is defined in ProfileSchema.
Sources: src/database/schemas/User.ts:16-36, types/schemas.d.ts:133-154
ER Diagram
This diagram illustrates the relationship between the user entity and its embedded profile and privacy documents.
Profile Schema Fields
The following table details the fields available in a user's profile.
| Field | Type | Description | Default Value |
|---|---|---|---|
pronouns | String | The user's pronouns. | null |
birthdate | Date | The user's date of birth. | null |
age | Number | The user's calculated age. | null |
region | String | The user's geographical region. | null |
languages | Array of String | Languages spoken by the user. | [] |
timezone | String | The user's timezone. | null |
bio | String | A short biography of the user (max 1000 characters). | null |
interests | Array of String | The user's interests. | [] |
socials | Map<String, String> | A map of social media platforms to usernames/handles. | new Map() |
favorites | Map<String, String> | A map of favorite categories to items (e.g., color: blue). | new Map() |
goals | Array of String | The user's personal goals. | [] |
privacy | Object | An object containing privacy settings for specific fields. | See below |
lastUpdated | Date | Timestamp of the last profile update. | Date.now |
createdAt | Date | Timestamp of profile creation. | Date.now |
Sources: src/database/schemas/User.ts:17-36
Privacy Schema Fields
The privacy object controls the visibility of certain profile fields to other users.
| Field | Type | Description | Default Value |
|---|---|---|---|
showAge | Boolean | If true, the user's age is public. | true |
showRegion | Boolean | If true, the user's region is public. | true |
showBirthdate | Boolean | If true, the user's birthdate is public. | false |
showPronouns | Boolean | If true, the user's pronouns are public. | true |
Sources: src/database/schemas/User.ts:29-34
Core Commands
The profile system is accessed through two primary slash commands.
Profile Management: /profile
This command is the entry point for creating and managing a user's own profile. It is a DM-enabled command that opens an interactive profile hub.
- Command:
profile - Description:
customize your bio, pronouns (allows me not to mispronoun you), and more - Functionality: When executed, it calls the
showProfileHubhandler, which is responsible for displaying the main profile management interface.
This diagram shows the flow when a user initiates the /profile command.
Sources: src/commands/utility/profile.ts:8-29
Profile Viewing: /info profile
This command allows any user to view their own or another user's profile.
- Command:
info profile - Description:
view your or someone else's profile - Options:
user(Optional): The user whose profile to view. Defaults to the command executor.
- Functionality: It invokes the
profileViewhandler to fetch and display the target user's profile information in an embed, respecting their privacy settings.
*Sources: src/commands/info/info.ts:82-89, src/commands/info/shared/profile.ts
Profile Editing Flow
When a user decides to edit their profile, they are guided through a series of menus and modals. This flow is managed by handlers in src/handlers/profile/edit.ts.
Sequence Diagram
The following diagram illustrates the sequence of events from selecting the "edit" option in the profile hub to successfully updating the profile data in the database.
This diagram shows the user interaction flow for editing the 'basic' profile information.
Sources: src/handlers/profile/edit.ts, src/database/schemas/User.ts:255-271
Editing Modals
The editing process is split into two categories, each with its own modal for data entry.
Basic Info Modal
This modal is for fundamental personal details. It is created by the createBasicModal function.
| Field | Label | Type | Required | Max Length |
|---|---|---|---|---|
birthdate | when's your special day? | Short | Yes | 10 |
pronouns | how should we refer to you? | Short | No | 50 |
region | where do you call home? | Short | No | 100 |
languages | what languages do you speak? | Short | No | 100 |
timezone | what's your timezone? | Short | No | 30 |
Sources: src/commands/utility/profile.ts:32-88
Miscellaneous Info Modal
This modal is for more descriptive and personal information. It is created by the createMiscModal function.
| Field | Label | Type | Required | Max Length |
|---|---|---|---|---|
bio | paint us a picture of who you are! | Paragraph | No | 1000 |
interests | what makes your heart skip a beat? | Short | No | 200 |
socials | where else can we find you? | Short | No | 200 |
favorites | what are your absolute favorites? | Short | No | 200 |
goals | what dreams are you chasing? | Short | No | 200 |
Sources: src/commands/utility/profile.ts:90-136
Profile Viewing Flow
The profileView function in src/commands/info/shared/profile.ts handles the logic for displaying a user's profile. It fetches the data, checks for content and privacy, and constructs an embed.
Flowchart
This flowchart outlines the logic for viewing a profile.
This diagram shows the logic for fetching, processing, and displaying a user profile.
Sources: src/commands/info/shared/profile.ts
Key Functions
hasContent(profile): Checks if any of the core profile fields have been filled out or if thesocialsorfavoritesmaps contain entries. This determines if a profile is considered "set up".
Sources: src/commands/utility/profile.ts:200-219formatValue(value): A generic formatter that handlesnull, arrays, and maps to ensure they are displayed cleanly.
Sources: src/commands/utility/profile.ts:140-147formatSocialLinks(socials): Takes thesocialsmap and transforms it into a formatted string with clickable hyperlinks for supported platforms (YouTube, Twitter, GitHub, etc.).
Sources: src/commands/utility/profile.ts:165-184formatFavorites(favorites): Takes thefavoritesmap and formats it into a multi-line string.
Sources: src/commands/utility/profile.ts:186-195
Database Interaction
All profile data is managed through functions in src/database/schemas/User.ts.
getUser(user): Retrieves a user's document from the database. If the user doesn't exist, a new document is created and saved. It utilizes an LRU cache to reduce database queries.
Sources: src/database/schemas/User.ts:91-108updateProfile(userId, profileData): The primary function for saving profile changes. It takes an object with profile data and uses$setto update the corresponding fields in theprofilesub-document. It also automatically calculates the user's age from the birthdate and sets thelastUpdatedtimestamp.
Sources: src/database/schemas/User.ts:255-271clearProfile(userId): Resets a user's profile to its default, empty state.
Sources: src/database/schemas/User.ts:273-294calculateAge(birthdate): A helper function that computes a person's age based on their birthdate.
Sources: src/database/schemas/User.ts:228-239