concord 2.3.5

A terminal user interface client for Discord
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
use std::{
    io,
    path::{Path, PathBuf},
};

use crate::discord::ids::{
    Id,
    marker::{ChannelMarker, EmojiMarker, ForumTagMarker, GuildMarker, MessageMarker, UserMarker},
};

use super::application_commands::ApplicationCommandInvocation;
use super::message::MessageInfo;
use super::{ActivityInfo, PresenceStatus, VoiceScope};

pub const MAX_UPLOAD_ATTACHMENT_COUNT: usize = 10;
pub const MAX_PROFILE_AVATAR_BYTES: u64 = 10 * 1024 * 1024;

/// Memory bound for decoding a local attachment preview thumbnail, kept
/// separate from the upload limit (now up to 500 MiB) so a preview of a huge
/// file is skipped rather than loaded into RAM. The upload still proceeds.
pub const MAX_UPLOAD_PREVIEW_BYTES: u64 = 10 * 1024 * 1024;

#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct AttachmentDownloadId(u64);

impl AttachmentDownloadId {
    pub fn new(value: u64) -> Self {
        Self(value)
    }

    pub fn get(self) -> u64 {
        self.0
    }
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MessageAttachmentUpload {
    source: UploadSource,
    pub filename: String,
    pub size_bytes: u64,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ForumPostCreate {
    pub channel_id: Id<ChannelMarker>,
    pub title: String,
    pub content: String,
    pub applied_tags: Vec<Id<ForumTagMarker>>,
    pub attachments: Vec<MessageAttachmentUpload>,
}

#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct GlobalUserProfileUpdate {
    pub display_name: Option<String>,
    pub pronouns: Option<String>,
    pub avatar: Option<ProfileAvatarUpload>,
}

impl GlobalUserProfileUpdate {
    pub fn is_empty(&self) -> bool {
        self.display_name.is_none() && self.pronouns.is_none() && self.avatar.is_none()
    }
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ProfileAvatarUpload {
    source: UploadSource,
    pub filename: String,
    pub size_bytes: u64,
}

#[derive(Clone, Debug, Eq, PartialEq)]
enum UploadSource {
    File(PathBuf),
    Bytes(Vec<u8>),
}

impl UploadSource {
    fn path(&self) -> Option<&Path> {
        match self {
            Self::File(path) => Some(path),
            Self::Bytes(_) => None,
        }
    }

    fn bytes(&self) -> Option<&[u8]> {
        match self {
            Self::File(_) => None,
            Self::Bytes(bytes) => Some(bytes),
        }
    }
}

impl ProfileAvatarUpload {
    pub fn from_path(path: PathBuf) -> Self {
        let filename = path
            .file_name()
            .and_then(|name| name.to_str())
            .unwrap_or("avatar")
            .to_owned();
        Self {
            source: UploadSource::File(path),
            filename,
            size_bytes: 0,
        }
    }

    pub fn from_bytes(filename: String, bytes: Vec<u8>) -> Self {
        Self {
            size_bytes: bytes.len() as u64,
            source: UploadSource::Bytes(bytes),
            filename,
        }
    }

    pub fn from_message_attachment(upload: MessageAttachmentUpload) -> Self {
        Self {
            source: upload.source,
            filename: upload.filename,
            size_bytes: upload.size_bytes,
        }
    }

    pub fn path(&self) -> Option<&Path> {
        self.source.path()
    }

    pub fn bytes(&self) -> Option<&[u8]> {
        self.source.bytes()
    }
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct GuildUserProfileUpdate {
    pub guild_id: Id<GuildMarker>,
    pub nickname: Option<String>,
    pub pronouns: Option<String>,
}

impl GuildUserProfileUpdate {
    pub fn is_empty(&self) -> bool {
        self.nickname.is_none() && self.pronouns.is_none()
    }
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct UserProfileUpdate {
    pub user_id: Id<UserMarker>,
    pub guild_id: Option<Id<GuildMarker>>,
    pub global: GlobalUserProfileUpdate,
    pub guild: Option<GuildUserProfileUpdate>,
}

impl UserProfileUpdate {
    pub fn is_empty(&self) -> bool {
        self.global.is_empty()
            && self
                .guild
                .as_ref()
                .is_none_or(GuildUserProfileUpdate::is_empty)
    }
}

impl MessageAttachmentUpload {
    pub fn from_path(path: PathBuf, filename: String, size_bytes: u64) -> Self {
        Self {
            source: UploadSource::File(path),
            filename,
            size_bytes,
        }
    }

    pub fn from_existing_path(path: PathBuf) -> io::Result<Self> {
        let metadata = path.metadata()?;
        let filename = path
            .file_name()
            .and_then(|name| name.to_str())
            .unwrap_or("attachment")
            .to_owned();
        Ok(Self::from_path(path, filename, metadata.len()))
    }

    pub fn from_bytes(filename: String, bytes: Vec<u8>) -> Self {
        Self {
            size_bytes: bytes.len() as u64,
            source: UploadSource::Bytes(bytes),
            filename,
        }
    }

    pub fn path(&self) -> Option<&Path> {
        self.source.path()
    }

    pub fn bytes(&self) -> Option<&[u8]> {
        self.source.bytes()
    }
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ReactionEmoji {
    Unicode(String),
    Custom {
        id: Id<EmojiMarker>,
        name: Option<String>,
        animated: bool,
    },
}

#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum ForumPostArchiveState {
    #[default]
    Active,
    Archived,
}

impl ForumPostArchiveState {
    pub fn as_query_value(self) -> &'static str {
        match self {
            Self::Active => "false",
            Self::Archived => "true",
        }
    }

    pub fn as_log_label(self) -> &'static str {
        match self {
            Self::Active => "active",
            Self::Archived => "archived",
        }
    }
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum MuteDuration {
    Minutes(u64),
    Permanent,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum MessageSearchHas {
    Link,
    Embed,
    File,
    Video,
    Image,
    Sound,
    Sticker,
}

impl MessageSearchHas {
    pub fn from_input(value: &str) -> Option<Self> {
        match normalized_search_token(value).as_str() {
            "link" | "links" => Some(Self::Link),
            "embed" | "embeds" => Some(Self::Embed),
            "file" | "files" | "attachment" | "attachments" => Some(Self::File),
            "video" | "videos" => Some(Self::Video),
            "image" | "images" | "img" => Some(Self::Image),
            "sound" | "sounds" | "audio" => Some(Self::Sound),
            "sticker" | "stickers" => Some(Self::Sticker),
            _ => None,
        }
    }

    pub fn as_query_value(self) -> &'static str {
        match self {
            Self::Link => "link",
            Self::Embed => "embed",
            Self::File => "file",
            Self::Video => "video",
            Self::Image => "image",
            Self::Sound => "sound",
            Self::Sticker => "sticker",
        }
    }
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum MessageSearchAuthorType {
    User,
    Bot,
    Webhook,
}

impl MessageSearchAuthorType {
    pub fn from_input(value: &str) -> Option<Self> {
        match normalized_search_token(value).as_str() {
            "user" | "person" | "people" => Some(Self::User),
            "bot" | "bots" => Some(Self::Bot),
            "webhook" | "webhooks" => Some(Self::Webhook),
            _ => None,
        }
    }

    pub fn as_query_value(self) -> &'static str {
        match self {
            Self::User => "user",
            Self::Bot => "bot",
            Self::Webhook => "webhook",
        }
    }
}

#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct MessageSearchQuery {
    pub guild_id: Option<Id<GuildMarker>>,
    pub channel_id: Option<Id<ChannelMarker>>,
    pub author_id: Option<Id<UserMarker>>,
    pub mentions_user_id: Option<Id<UserMarker>>,
    pub content: Option<String>,
    pub has: Vec<MessageSearchHas>,
    pub date: Option<String>,
    pub author_type: Vec<MessageSearchAuthorType>,
    pub pinned: Option<bool>,
    pub offset: usize,
}

impl MessageSearchQuery {
    pub fn is_empty(&self) -> bool {
        self.channel_id.is_none()
            && self.author_id.is_none()
            && self.mentions_user_id.is_none()
            && self.content.as_deref().is_none_or(str::is_empty)
            && self.has.is_empty()
            && self.date.as_deref().is_none_or(str::is_empty)
            && self.author_type.is_empty()
            && self.pinned.is_none()
    }
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MessageSearchPage {
    pub query: MessageSearchQuery,
    pub messages: Vec<MessageInfo>,
    pub total_results: Option<usize>,
    pub has_more: bool,
}

impl MuteDuration {
    pub fn minutes(self) -> Option<u64> {
        match self {
            Self::Minutes(minutes) => Some(minutes),
            Self::Permanent => None,
        }
    }

    pub fn selected_time_window_seconds(self) -> i64 {
        match self {
            Self::Minutes(minutes) => i64::try_from(minutes.saturating_mul(60)).unwrap_or(i64::MAX),
            Self::Permanent => -1,
        }
    }
}

impl ReactionEmoji {
    pub fn status_label(&self) -> String {
        match self {
            Self::Unicode(emoji) => emoji.clone(),
            Self::Custom { name, .. } => name
                .as_deref()
                .map(|name| format!(":{name}:"))
                .unwrap_or_else(|| ":custom:".to_owned()),
        }
    }

    pub fn custom_image_url(&self) -> Option<String> {
        let Self::Custom { id, animated, .. } = self else {
            return None;
        };
        let extension = if *animated { "gif" } else { "png" };
        Some(format!(
            "https://cdn.discordapp.com/emojis/{}.{}",
            id.get(),
            extension
        ))
    }

    pub(crate) fn route_component(&self) -> String {
        match self {
            Self::Unicode(name) => percent_encode_path_segment(name),
            Self::Custom { id, name, .. } => percent_encode_path_segment(&format!(
                "{}:{id}",
                name.as_deref().unwrap_or_default()
            )),
        }
    }
}

fn percent_encode_path_segment(value: &str) -> String {
    let mut encoded = String::new();
    for byte in value.bytes() {
        match byte {
            b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'.' | b'_' | b'~' => {
                encoded.push(char::from(byte));
            }
            _ => encoded.push_str(&format!("%{byte:02X}")),
        }
    }
    encoded
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum MessageHistoryAfterMode {
    GapFill,
    CatchUp,
}

impl MessageHistoryAfterMode {
    pub(crate) fn exhausts_on_empty(self) -> bool {
        matches!(self, Self::GapFill)
    }

    pub(crate) fn is_catch_up(self) -> bool {
        matches!(self, Self::CatchUp)
    }
}

/// A reply target paired with whether it should ping the referenced author.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ReplyReference {
    pub message_id: Id<MessageMarker>,
    pub mention_author: bool,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum AppCommand {
    SignOut,
    LoadMessageHistory {
        channel_id: Id<ChannelMarker>,
        before: Option<Id<MessageMarker>>,
    },
    RefreshMessageHistory {
        channel_id: Id<ChannelMarker>,
    },
    LoadMessageHistoryAfter {
        channel_id: Id<ChannelMarker>,
        after: Id<MessageMarker>,
        mode: MessageHistoryAfterMode,
    },
    LoadMessageHistoryAround {
        channel_id: Id<ChannelMarker>,
        message_id: Id<MessageMarker>,
    },
    LoadThreadPreview {
        channel_id: Id<ChannelMarker>,
        message_id: Id<MessageMarker>,
    },
    LoadForumPosts {
        guild_id: Id<GuildMarker>,
        channel_id: Id<ChannelMarker>,
        archive_state: ForumPostArchiveState,
        offset: usize,
    },
    SearchMessages {
        query: MessageSearchQuery,
    },
    LoadGuildMembers {
        guild_id: Id<GuildMarker>,
    },
    LoadGuildMembersByIds {
        guild_id: Id<GuildMarker>,
        user_ids: Vec<Id<UserMarker>>,
    },
    SearchGuildMembers {
        guild_id: Id<GuildMarker>,
        query: String,
    },
    SetSelectedGuild {
        guild_id: Option<Id<GuildMarker>>,
    },
    LeaveGuild {
        guild_id: Id<GuildMarker>,
        label: String,
    },
    SetSelectedMessageChannel {
        channel_id: Option<Id<ChannelMarker>>,
    },
    TriggerTyping {
        channel_id: Id<ChannelMarker>,
    },
    SubscribeDirectMessage {
        channel_id: Id<ChannelMarker>,
    },
    SubscribeGuildChannel {
        guild_id: Id<GuildMarker>,
        channel_id: Id<ChannelMarker>,
    },
    /// Resubscribe an active op-37 channel subscription with a wider set of
    /// member-list ranges as the user scrolls through the member sidebar.
    UpdateMemberListSubscription {
        guild_id: Id<GuildMarker>,
        channel_id: Id<ChannelMarker>,
        ranges: Vec<(u32, u32)>,
    },
    JoinVoiceChannel {
        scope: VoiceScope,
        channel_id: Id<ChannelMarker>,
        self_mute: bool,
        self_deaf: bool,
        allow_microphone_transmit: bool,
        microphone_sensitivity: crate::discord::MicrophoneSensitivityDb,
        microphone_volume: crate::discord::VoiceVolumePercent,
        voice_output_volume: crate::discord::VoiceVolumePercent,
    },
    UpdateVoiceState {
        scope: VoiceScope,
        channel_id: Id<ChannelMarker>,
        self_mute: bool,
        self_deaf: bool,
    },
    UpdateVoiceCapturePermission {
        scope: VoiceScope,
        channel_id: Id<ChannelMarker>,
        allow_microphone_transmit: bool,
        microphone_sensitivity: crate::discord::MicrophoneSensitivityDb,
        microphone_volume: crate::discord::VoiceVolumePercent,
        voice_output_volume: crate::discord::VoiceVolumePercent,
    },
    LeaveVoiceChannel {
        scope: VoiceScope,
        self_mute: bool,
        self_deaf: bool,
    },
    LoadAttachmentPreview {
        url: String,
    },
    LoadProfileAvatarPreview {
        key: String,
        upload: ProfileAvatarUpload,
    },
    SendMessage {
        channel_id: Id<ChannelMarker>,
        content: String,
        reply_to: Option<ReplyReference>,
        attachments: Vec<MessageAttachmentUpload>,
    },
    CreateForumPost {
        post: ForumPostCreate,
    },
    SendTtsMessage {
        channel_id: Id<ChannelMarker>,
        content: String,
    },
    LoadApplicationCommands {
        guild_id: Option<Id<GuildMarker>>,
    },
    RunApplicationCommand {
        invocation: ApplicationCommandInvocation,
    },
    EditMessage {
        channel_id: Id<ChannelMarker>,
        message_id: Id<MessageMarker>,
        content: String,
    },
    DeleteMessage {
        channel_id: Id<ChannelMarker>,
        message_id: Id<MessageMarker>,
    },
    RemoveMessageEmbeds {
        channel_id: Id<ChannelMarker>,
        message_id: Id<MessageMarker>,
    },
    OpenUrl {
        url: String,
    },
    PlayMedia {
        target: MediaPlaybackTarget,
        request_id: Option<MediaPlaybackRequestId>,
    },
    DownloadAttachment {
        id: AttachmentDownloadId,
        url: String,
        filename: String,
        source: DownloadAttachmentSource,
    },
    AddReaction {
        channel_id: Id<ChannelMarker>,
        message_id: Id<MessageMarker>,
        emoji: ReactionEmoji,
    },
    RemoveReaction {
        channel_id: Id<ChannelMarker>,
        message_id: Id<MessageMarker>,
        emoji: ReactionEmoji,
    },
    LoadReactionUsers {
        channel_id: Id<ChannelMarker>,
        message_id: Id<MessageMarker>,
        emoji: ReactionEmoji,
        after: Option<Id<UserMarker>>,
    },
    LoadPinnedMessages {
        channel_id: Id<ChannelMarker>,
    },
    SetMessagePinned {
        channel_id: Id<ChannelMarker>,
        message_id: Id<MessageMarker>,
        pinned: bool,
    },
    VotePoll {
        channel_id: Id<ChannelMarker>,
        message_id: Id<MessageMarker>,
        answer_ids: Vec<u8>,
    },
    LoadUserProfile {
        user_id: Id<UserMarker>,
        guild_id: Option<Id<GuildMarker>>,
    },
    LoadUserNote {
        user_id: Id<UserMarker>,
    },
    UpdateUserProfile {
        update: UserProfileUpdate,
    },
    UpdateCurrentUserStatus {
        status: PresenceStatus,
    },
    UpdateGuildFolderSettings {
        folder_id: u64,
        name: Option<String>,
        color: Option<u32>,
    },
    UpdateCurrentUserActivity {
        status: PresenceStatus,
        activities: Vec<ActivityInfo>,
        /// RPC `client_id` whose live activity this is, so the RPC server keeps
        /// re-broadcasting it. `None` for a manual activity, which RPC must not override.
        track_client_id: Option<String>,
    },
    AckChannel {
        channel_id: Id<ChannelMarker>,
        message_id: Id<MessageMarker>,
    },
    ScheduleAckChannel {
        channel_id: Id<ChannelMarker>,
        message_id: Id<MessageMarker>,
    },
    SetGuildMuted {
        guild_id: Id<GuildMarker>,
        muted: bool,
        duration: Option<MuteDuration>,
        label: String,
    },
    SetChannelMuted {
        guild_id: Option<Id<GuildMarker>>,
        channel_id: Id<ChannelMarker>,
        muted: bool,
        duration: Option<MuteDuration>,
        label: String,
    },
    /// Mute a forum post (thread). Uses the thread-member settings endpoint
    /// rather than the guild `channel_overrides`, which rejects thread types.
    SetThreadMuted {
        guild_id: Option<Id<GuildMarker>>,
        channel_id: Id<ChannelMarker>,
        muted: bool,
        duration: Option<MuteDuration>,
        label: String,
    },
    /// Follow (join) or unfollow (leave) a forum post thread.
    SetThreadFollowed {
        channel_id: Id<ChannelMarker>,
        followed: bool,
        label: String,
    },
    /// Set the notification level for a thread. Flags: 2 = All messages,
    /// 4 = Only @mentions (Discord default), 8 = Nothing.
    SetThreadNotificationLevel {
        channel_id: Id<ChannelMarker>,
        flags: u64,
        label: String,
    },
    /// Archive ("close") or reopen a thread (regular thread or forum post).
    SetThreadArchived {
        channel_id: Id<ChannelMarker>,
        archived: bool,
        label: String,
    },
    /// Lock or unlock a thread.
    SetThreadLocked {
        channel_id: Id<ChannelMarker>,
        locked: bool,
        label: String,
    },
    /// Pin or unpin a forum post within its parent forum (pinning is forum-only).
    /// `current_flags` is the thread's present channel flags so the handler can
    /// flip just the PINNED bit without clobbering the others.
    SetThreadPinned {
        channel_id: Id<ChannelMarker>,
        pinned: bool,
        current_flags: u64,
        label: String,
    },
    /// Permanently delete a thread (its channel).
    DeleteThread {
        channel_id: Id<ChannelMarker>,
        label: String,
    },
    /// Edit a thread's general settings (title, applied tags for forum posts,
    /// slow-mode cooldown, auto-archive duration) in one PATCH. The result
    /// arrives over the gateway THREAD_UPDATE, so there is no optimistic event.
    EditThread {
        channel_id: Id<ChannelMarker>,
        name: String,
        applied_tags: Vec<Id<ForumTagMarker>>,
        rate_limit_per_user: u64,
        auto_archive_duration: u64,
        label: String,
    },
    AckChannels {
        targets: Vec<(Id<ChannelMarker>, Id<MessageMarker>)>,
    },
    /// Fetch recent mentions for the inbox Mentions tab in one request.
    LoadInboxMentions {
        request_id: u64,
    },
    /// Fetch a small slice of a channel's latest messages for the inbox Unreads tab.
    LoadInboxChannelHistory {
        channel_id: Id<ChannelMarker>,
        request_id: u64,
    },
}

fn normalized_search_token(value: &str) -> String {
    value.trim().trim_start_matches(':').to_ascii_lowercase()
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum DownloadAttachmentSource {
    AttachmentViewer,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum MediaPlaybackSource {
    Message,
    AttachmentViewer,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct MediaPlaybackRequestId(u64);

impl MediaPlaybackRequestId {
    pub const fn new(value: u64) -> Self {
        Self(value)
    }
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MediaPlaybackTarget {
    pub url: String,
    pub label: String,
    pub source: MediaPlaybackSource,
}