titanium_model/
lib.rs

1//! Titan Model - Core types and models for Discord API
2#![deny(unsafe_code)]
3//!
4//! This crate provides zero-copy deserialization support for Discord API entities.
5//! All types follow Discord API v10/11 specifications.
6//!
7//!
8//! # Modules
9//!
10
11//! - [`automod`] - AutoMod rules and actions
12//! - [`audit`] - Audit log entries
13//! - [`integration`] - Integrations and webhooks
14//! - [`invite`] - Guild invites
15//! - [`member`] - Guild members, roles, emoji, stickers
16//! - [`monetization`] - Entitlements, subscriptions, SKUs
17//! - [`reaction`] - Message reactions
18//! - [`scheduled`] - Scheduled events
19//! - [`soundboard`] - Soundboard sounds
20//! - [`stage`] - Stage instances
21//! - [`thread`] - Thread channels and members
22
23pub mod audit;
24pub mod automod;
25pub mod builder;
26pub mod cdn_tests;
27pub mod command;
28pub mod component;
29pub mod create_message;
30pub mod file;
31pub mod integration;
32pub mod intents;
33pub mod interaction;
34pub mod invite;
35pub mod json;
36pub mod member;
37pub mod monetization;
38pub mod permissions;
39pub mod poll;
40pub mod reaction;
41pub mod scheduled;
42pub mod snowflake;
43pub mod soundboard;
44pub mod stage;
45pub mod string;
46pub mod thread;
47pub mod ui;
48pub mod voice;
49pub mod voice_state;
50
51// New modules
52pub mod channel;
53pub mod guild;
54pub mod message;
55pub mod user;
56
57// Re-exports from submodules
58pub use audit::{AuditLogChange, AuditLogEntry, AuditLogEvent, AuditLogOptions};
59pub use automod::{
60    AutoModAction, AutoModActionExecution, AutoModActionMetadata, AutoModActionType,
61    AutoModEventType, AutoModKeywordPresetType, AutoModRule, AutoModTriggerMetadata,
62    AutoModTriggerType,
63};
64pub use builder::{
65    ActionRowBuilder, AutoModRuleBuilder, ButtonBuilder, CommandBuilder, CreateChannelBuilder,
66    CreateEmojiBuilder, CreateGuildBuilder, CreateInviteBuilder, CreateRoleBuilder,
67    CreateStickerBuilder, EmbedBuilder, InteractionResponseBuilder, MessageBuilder,
68    ModifyEmojiBuilder, ModifyGuildBuilder, ModifyMemberBuilder, PollBuilder,
69    ScheduledEventBuilder, SelectMenuBuilder, StageInstanceBuilder, StartThreadBuilder,
70    WebhookExecuteBuilder,
71};
72pub use command::{ApplicationCommand, CommandOption, CommandType};
73pub use component::{ActionRow, Button, Component, ComponentType, SelectMenu};
74pub use create_message::CreateMessage;
75pub use integration::{
76    GuildIntegrationsUpdateEvent, Integration, IntegrationAccount, IntegrationApplication,
77    IntegrationDeleteEvent, Webhook, WebhooksUpdateEvent,
78};
79pub use intents::Intents;
80pub use interaction::{
81    Interaction, InteractionCallbackData, InteractionCallbackType, InteractionResponse,
82    InteractionType,
83};
84pub use invite::{InviteCreateEvent, InviteDeleteEvent};
85pub use member::{Emoji, GuildMember, Role, RoleTags, Sticker};
86pub use monetization::{
87    Entitlement, EntitlementType, Sku, SkuType, Subscription, SubscriptionStatus,
88};
89pub use permissions::Permissions;
90pub use poll::{Poll, PollAnswer, PollMedia, PollResults};
91pub use reaction::{
92    MessageReactionAddEvent, MessageReactionRemoveAllEvent, MessageReactionRemoveEmojiEvent,
93    MessageReactionRemoveEvent, ReactionEmoji,
94};
95pub use scheduled::{
96    ScheduledEvent, ScheduledEventEntityMetadata, ScheduledEventEntityType,
97    ScheduledEventPrivacyLevel, ScheduledEventStatus, ScheduledEventUserEvent,
98};
99pub use snowflake::Snowflake;
100pub use soundboard::{
101    GuildSoundboardSoundsUpdateEvent, SoundboardSound, SoundboardSoundDeleteEvent,
102    SoundboardSoundsUpdateEvent,
103};
104pub use stage::{StageInstance, StagePrivacyLevel};
105pub use string::TitanString;
106pub use thread::{
107    DefaultReaction, ForumTag, ThreadDeleteEvent, ThreadListSyncEvent, ThreadMember,
108    ThreadMemberUpdateEvent, ThreadMembersUpdateEvent, ThreadMetadata,
109};
110pub use voice_state::PartialVoiceState;
111
112// Re-exports from new modules
113pub use channel::{Channel, ChannelMention, ChannelPinsUpdateEvent, PermissionOverwrite};
114pub use guild::{
115    Application, Guild, GuildBanEvent, GuildEmojisUpdateEvent, GuildMemberAddEvent,
116    GuildMemberRemoveEvent, GuildMemberUpdateEvent, GuildMembersChunkEvent, GuildRoleDeleteEvent,
117    GuildRoleEvent, GuildStickersUpdateEvent, ReadyEventData, UnavailableGuild,
118};
119pub use message::{
120    Attachment, Embed, EmbedAuthor, EmbedField, EmbedFooter, EmbedMedia, EmbedProvider, Message,
121    MessageDeleteBulkEvent, MessageDeleteEvent, MessageReference, MessageUpdateEvent, Reaction,
122    ReactionCountDetails, StickerItem, TypingStartEvent,
123};
124pub use user::{ClientStatus, PartialUser, PresenceUpdateEvent, User};
125
126// ============================================================================
127// Builder Ergonomics (From Implementations)
128// ============================================================================
129
130impl<'a> From<EmbedBuilder<'a>> for Embed<'a> {
131    fn from(builder: EmbedBuilder<'a>) -> Self {
132        builder.build()
133    }
134}
135
136impl<'a> From<MessageBuilder<'a>> for CreateMessage<'a> {
137    fn from(builder: MessageBuilder<'a>) -> Self {
138        builder.build()
139    }
140}
141
142impl<'a> From<ButtonBuilder<'a>> for Component<'a> {
143    fn from(builder: ButtonBuilder<'a>) -> Self {
144        builder.build()
145    }
146}
147
148impl<'a> From<SelectMenuBuilder<'a>> for Component<'a> {
149    fn from(builder: SelectMenuBuilder<'a>) -> Self {
150        builder.build()
151    }
152}
153
154impl<'a> From<ActionRowBuilder<'a>> for Component<'a> {
155    fn from(builder: ActionRowBuilder<'a>) -> Self {
156        builder.build()
157    }
158}
159
160impl<'a> From<InteractionResponseBuilder<'a>> for crate::interaction::InteractionResponse<'a> {
161    fn from(builder: InteractionResponseBuilder<'a>) -> Self {
162        builder.build()
163    }
164}
165
166/// Trait for items that can be mentioned in Discord.
167pub trait Mention {
168    /// Returns the mention string for this item (e.g., <@123>).
169    fn mention(&self) -> String;
170}
171
172impl Mention for GuildMember<'_> {
173    fn mention(&self) -> String {
174        if let Some(user) = &self.user {
175            format!("<@{}>", user.id.0)
176        } else {
177            String::new() // Should not happen for valid members
178        }
179    }
180}
181
182impl Mention for Role<'_> {
183    fn mention(&self) -> String {
184        format!("<@&{}>", self.id.0)
185    }
186}