|
1 | 1 | //! Models relating to Discord channels. |
2 | 2 |
|
3 | 3 | use std::borrow::Cow; |
4 | | -#[cfg(feature = "model")] |
5 | | -use std::fmt::Display; |
6 | 4 |
|
7 | 5 | use nonmax::NonMaxU64; |
8 | 6 |
|
@@ -449,83 +447,43 @@ impl Message { |
449 | 447 |
|
450 | 448 | /// Uses Discord's inline reply to a user without pinging them. |
451 | 449 | /// |
452 | | - /// User mentions are generally around 20 or 21 characters long. |
453 | | - /// |
454 | | - /// **Note**: Requires the [Send Messages] permission. |
455 | | - /// |
456 | | - /// **Note**: Message contents must be under 2000 unicode code points. |
| 450 | + /// Refer to the documentation for [`CreateMessage`] for information regarding content |
| 451 | + /// restrictions and requirements. |
457 | 452 | /// |
458 | 453 | /// # Errors |
459 | 454 | /// |
460 | | - /// Returns a [`ModelError::TooLarge`] if the content of the message is over the above |
461 | | - /// limit, containing the number of unicode code points over the limit. |
462 | | - /// |
463 | | - /// [Send Messages]: Permissions::SEND_MESSAGES |
| 455 | + /// See the documentation of [`CreateMessage::execute`] for possible errors. |
464 | 456 | pub async fn reply(&self, http: &Http, content: impl Into<Cow<'_, str>>) -> Result<Message> { |
465 | | - self._reply(http, content, Some(false)).await |
| 457 | + self._reply(http, content.into(), false).await |
466 | 458 | } |
467 | 459 |
|
468 | 460 | /// Uses Discord's inline reply to a user with a ping. |
469 | 461 | /// |
470 | | - /// **Note**: Requires the [Send Messages] permission. |
471 | | - /// |
472 | | - /// **Note**: Message contents must be under 2000 unicode code points. |
| 462 | + /// Refer to the documentation for [`CreateMessage`] for information regarding content |
| 463 | + /// restrictions and requirements. |
473 | 464 | /// |
474 | 465 | /// # Errors |
475 | 466 | /// |
476 | | - /// Returns [`Error::Http`] if the current user lacks permission or if invalid data is given. |
477 | | - /// |
478 | | - /// Returns a [`ModelError::TooLarge`] if the content of the message is over the above |
479 | | - /// limit, containing the number of unicode code points over the limit. |
480 | | - /// |
481 | | - /// [Send Messages]: Permissions::SEND_MESSAGES |
| 467 | + /// See the documentation of [`CreateMessage::execute`] for possible errors. |
482 | 468 | pub async fn reply_ping( |
483 | 469 | &self, |
484 | 470 | http: &Http, |
485 | 471 | content: impl Into<Cow<'_, str>>, |
486 | 472 | ) -> Result<Message> { |
487 | | - self._reply(http, content, Some(true)).await |
| 473 | + self._reply(http, content.into(), true).await |
488 | 474 | } |
489 | 475 |
|
490 | | - /// Replies to the user, mentioning them prior to the content in the form of: `@<USER_ID> |
491 | | - /// YOUR_CONTENT`. |
492 | | - /// |
493 | | - /// User mentions are generally around 20 or 21 characters long. |
494 | | - /// |
495 | | - /// **Note**: Requires the [Send Messages] permission. |
496 | | - /// |
497 | | - /// **Note**: Message contents must be under 2000 unicode code points. |
498 | | - /// |
499 | | - /// # Errors |
500 | | - /// |
501 | | - /// Returns [`Error::Http`] if the current user lacks permission or if invalid data is given. |
502 | | - /// |
503 | | - /// Returns a [`ModelError::TooLarge`] if the content of the message is over the above |
504 | | - /// limit, containing the number of unicode code points over the limit. |
505 | | - /// |
506 | | - /// [Send Messages]: Permissions::SEND_MESSAGES |
507 | | - pub async fn reply_mention(&self, http: &Http, content: impl Display) -> Result<Message> { |
508 | | - self._reply(http, format!("{} {content}", self.author.mention()), None).await |
509 | | - } |
| 476 | + async fn _reply(&self, http: &Http, content: Cow<'_, str>, ping_user: bool) -> Result<Message> { |
| 477 | + let default_allowed_mentions = http.default_allowed_mentions.clone(); |
| 478 | + let allowed_mentions = default_allowed_mentions.unwrap_or_else(|| { |
| 479 | + CreateAllowedMentions::new().everyone(true).all_users(true).all_roles(true) |
| 480 | + }); |
| 481 | + |
| 482 | + let builder = CreateMessage::new() |
| 483 | + .content(content) |
| 484 | + .reference_message(self) |
| 485 | + .allowed_mentions(allowed_mentions.replied_user(ping_user)); |
510 | 486 |
|
511 | | - /// `inlined` decides whether this reply is inlined and whether it pings. |
512 | | - async fn _reply( |
513 | | - &self, |
514 | | - http: &Http, |
515 | | - content: impl Into<Cow<'_, str>>, |
516 | | - inlined: Option<bool>, |
517 | | - ) -> Result<Message> { |
518 | | - let mut builder = CreateMessage::new().content(content); |
519 | | - if let Some(ping_user) = inlined { |
520 | | - let allowed_mentions = CreateAllowedMentions::new() |
521 | | - .replied_user(ping_user) |
522 | | - // By providing allowed_mentions, Discord disabled _all_ pings by default so we |
523 | | - // need to re-enable them |
524 | | - .everyone(true) |
525 | | - .all_users(true) |
526 | | - .all_roles(true); |
527 | | - builder = builder.reference_message(self).allowed_mentions(allowed_mentions); |
528 | | - } |
529 | 487 | self.channel_id.send_message(http, builder).await |
530 | 488 | } |
531 | 489 |
|
|
0 commit comments