add: markdown emoji parsing
This commit is contained in:
parent
d9234bf656
commit
af67077ae7
8 changed files with 243 additions and 46 deletions
|
@ -54,40 +54,30 @@ impl DataManager {
|
|||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Get all emojis by user.
|
||||
/// Get an emoji by community and name.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `user` - the ID of the user to fetch emojis for
|
||||
pub async fn get_emojis_by_user(&self, user: usize) -> Result<Vec<CustomEmoji>> {
|
||||
let conn = match self.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
};
|
||||
|
||||
let res = query_rows!(
|
||||
&conn,
|
||||
"SELECT * FROM emojis WHERE (owner = $1 OR members LIKE $2) AND community = 0 ORDER BY created DESC",
|
||||
params![&(user as i64), &format!("%{user}%")],
|
||||
|x| { Self::get_emoji_from_row(x) }
|
||||
);
|
||||
|
||||
if res.is_err() {
|
||||
return Err(Error::GeneralNotFound("emoji".to_string()));
|
||||
/// * `community` - the ID of the community to fetch emoji from
|
||||
/// * `name` - the name of the emoji
|
||||
///
|
||||
/// # Returns
|
||||
/// `(custom emoji, emoji string)`
|
||||
///
|
||||
/// Custom emoji will be none if emoji string is some, and vice versa. Emoji string
|
||||
/// will only be some if the community is 0 (no community ID in parsed string, or `0.emoji_name`)
|
||||
///
|
||||
/// Regular unicode emojis should have a community ID of 0, since they don't belong
|
||||
/// to any community and can be used by anyone.
|
||||
pub async fn get_emoji_by_community_name(
|
||||
&self,
|
||||
community: usize,
|
||||
name: &str,
|
||||
) -> Result<(Option<CustomEmoji>, Option<String>)> {
|
||||
if community == 0 {
|
||||
return Ok((None, Some("🐇".to_string())));
|
||||
}
|
||||
|
||||
Ok(res.unwrap())
|
||||
}
|
||||
|
||||
/// Get a emoji given its `owner` and a member.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `owner` - the ID of the owner
|
||||
/// * `member` - the ID of the member
|
||||
pub async fn get_emoji_by_owner_member(
|
||||
&self,
|
||||
owner: usize,
|
||||
member: usize,
|
||||
) -> Result<CustomEmoji> {
|
||||
// ...
|
||||
let conn = match self.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
|
@ -95,9 +85,9 @@ impl DataManager {
|
|||
|
||||
let res = query_row!(
|
||||
&conn,
|
||||
"SELECT * FROM emojis WHERE owner = $1 AND members = $2 AND community = 0 ORDER BY created DESC",
|
||||
params![&(owner as i64), &format!("[{member}]")],
|
||||
|x| { Ok(Self::get_emoji_from_row(x)) }
|
||||
"SELECT * FROM emojis WHERE community = $1 AND name = $2 ORDER BY name ASC",
|
||||
params![&(community as i64), &name],
|
||||
|x| { Ok((Some(Self::get_emoji_from_row(x)), None)) }
|
||||
);
|
||||
|
||||
if res.is_err() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue