Add friend request command
This commit is contained in:
@@ -1,5 +1,56 @@
|
||||
//! Call commands and events.
|
||||
|
||||
use twilight_model::gateway::payload::incoming::MessageCreate;
|
||||
use twilight_validate::request::webhook_username;
|
||||
|
||||
use crate::discord::images;
|
||||
|
||||
pub mod commands;
|
||||
pub mod events;
|
||||
pub(super) mod moderation;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DisplayProfile {
|
||||
pub id: u64,
|
||||
pub name: String,
|
||||
pub avatar_url: String,
|
||||
pub mask: Option<String>,
|
||||
}
|
||||
|
||||
fn get_display_profile(event: &MessageCreate) -> DisplayProfile {
|
||||
let member = event.member.clone();
|
||||
|
||||
let name = if let Some(nick) = &member.clone().and_then(|member| member.nick) {
|
||||
if webhook_username(nick).is_err() {
|
||||
"Invalid Nickname".to_string()
|
||||
} else {
|
||||
nick.clone()
|
||||
}
|
||||
} else if let Some(name) = &event.author.global_name {
|
||||
if webhook_username(name).is_err() {
|
||||
"Invalid Global Name".to_string()
|
||||
} else {
|
||||
name.clone()
|
||||
}
|
||||
} else if webhook_username(&event.author.name).is_err() {
|
||||
"Invalid Username".to_string()
|
||||
} else {
|
||||
event.author.name.clone()
|
||||
};
|
||||
|
||||
let avatar_hash = member
|
||||
.and_then(|inner| inner.avatar)
|
||||
.or(event.author.avatar);
|
||||
let avatar_url = images::get_avatar_url(
|
||||
avatar_hash,
|
||||
event.author.id.get(),
|
||||
event.author.discriminator as u64,
|
||||
);
|
||||
|
||||
DisplayProfile {
|
||||
id: event.author.id.get(),
|
||||
name,
|
||||
avatar_url,
|
||||
mask: None,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user