-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Mentions, fix MessageBuilder
Remove the obsolete Mention struct as well as related methods, improve the way mentioning works, fix the message builder, add a test for all this.
- Loading branch information
Showing
7 changed files
with
101 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
extern crate serenity; | ||
|
||
use serenity::utils::MessageBuilder; | ||
use serenity::model::Emoji; | ||
use serenity::model::EmojiId; | ||
use serenity::model::UserId; | ||
|
||
#[test] | ||
fn code_blocks() { | ||
let content = MessageBuilder::new() | ||
.push_codeblock("test", Some("rb")) | ||
.build(); | ||
assert_eq!(content, "```rb\ntest\n```"); | ||
} | ||
|
||
|
||
#[test] | ||
fn safe_content() { | ||
let content = MessageBuilder::new() | ||
.push_safe("@everyone discord.gg/discord-api") | ||
.build(); | ||
assert!(content != "@everyone discord.gg/discord-api"); | ||
} | ||
|
||
|
||
#[test] | ||
fn no_free_formatting() { | ||
let content = MessageBuilder::new() | ||
.push_bold_safe("test**test") | ||
.build(); | ||
assert!(content != "**test**test**"); | ||
} | ||
|
||
#[test] | ||
fn mentions() { | ||
let content_emoji = MessageBuilder::new() | ||
.emoji(Emoji { | ||
id: EmojiId(32), | ||
name: "Rohrkatze".to_string(), | ||
managed: false, | ||
require_colons: true, | ||
roles: vec![] | ||
}) | ||
.build(); | ||
let content_mentions = MessageBuilder::new() | ||
.channel(1) | ||
.mention(UserId(2)) | ||
.role(3) | ||
.user(4) | ||
.build(); | ||
assert_eq!(content_mentions, "<#1><@2><@&3><@4>"); | ||
assert_eq!(content_emoji, "<:Rohrkatze:32>"); | ||
} |