pub async fn create_webhook_with_avatar<'a>(&self, http: impl AsRef<Http>, name: impl std::fmt::Display, avatar: impl Into<AttachmentType<'a>>) -> Result<Webhook> {
        let name = name.to_string();
        let avatar = avatar.into();

        if name.len() < 2 {
            return Err(Error::Model(ModelError::NameTooShort))
        } else if name.len() > 100 {
            return Err(Error::Model(ModelError::NameTooLong))
        } else if self.kind.num() != 0 {
            return Err(Error::Model(ModelError::InvalidChannelType))
        }

        let avatar = match avatar {
            AttachmentType::Bytes{ data, filename: _ } => {
                "data:image/png;base64,".to_string() + &base64::encode(&data.into_owned())
            },
            AttachmentType::File{ file, filename: _ } => {
                let mut buf = Vec::new();
                file.try_clone().await?.read_to_end(&mut buf).await?;

                "data:image/png;base64,".to_string() + &base64::encode(&buf)
            },
            AttachmentType::Path(path) => {
                let mut file = File::open(path).await?;
                let mut buf = vec![];
                file.read_to_end(&mut buf).await?;

                "data:image/png;base64,".to_string() + &base64::encode(&buf)
            },
            AttachmentType::Image(url) => {
                let url = Url::parse(url).map_err(|_| Error::Url(url.to_string()))?;
                let response = http.as_ref().client.get(url).send().await?;
                let mut bytes = response.bytes().await?;
                let mut picture: Vec<u8> = vec![0; bytes.len()];
                bytes.copy_to_slice(&mut picture[..]);

                "data:image/png;base64,".to_string() + &base64::encode(&picture)
            },
        };

        let map = serde_json::json!({
            "name": name,
            "avatar": avatar
        });

        http.as_ref().create_webhook(self.id.0, &map).await
    }
/// Avatar must be a 128x128 image.
Avatar must be a 128x128 image.
Avatar must be a 128x128 image .
pub async fn create_webhook_with_avatar<'a>(&self, http: impl AsRef<Http>, name: impl std::fmt::Display, avatar: impl Into<AttachmentType<'a>>) -> Result<Webhook> {
        let name = name.to_string();
        let avatar = avatar.into();
        if name.len() < 2 {
            return Err(Error::Model(ModelError::NameTooShort))
        } else if name.len() > 100 {
            return Err(Error::Model(ModelError::NameTooLong))
        } else if self.kind.num() != 0 {
            return Err(Error::Model(ModelError::InvalidChannelType))
        }
        let avatar = match avatar {
            AttachmentType::Bytes{ data, filename: _ } => {
                "data:image/png;base64,".to_string() + &base64::encode(&data.into_owned())
            },
            AttachmentType::File{ file, filename: _ } => {
                let mut buf = Vec::new();
                file.try_clone().await?.read_to_end(&mut buf).await?;
                "data:image/png;base64,".to_string() + &base64::encode(&buf)
            },
            AttachmentType::Path(path) => {
                let mut file = File::open(path).await?;
                let mut buf = vec![];
                file.read_to_end(&mut buf).await?;
                "data:image/png;base64,".to_string() + &base64::encode(&buf)
            },
            AttachmentType::Image(url) => {
                let url = Url::parse(url).map_err(|_| Error::Url(url.to_string()))?;
                let response = http.as_ref().client.get(url).send().await?;
                let mut bytes = response.bytes().await?;
                let mut picture: Vec<u8> = vec![0; bytes.len()];
                bytes.copy_to_slice(&mut picture[..]);
                "data:image/png;base64,".to_string() + &base64::encode(&picture)
            },
        };
        let map = serde_json::json!({
            "name": name,
            "avatar": avatar
        });
        http.as_ref().create_webhook(self.id.0, &map).await
    }
pub async fn create_webhook_with_avatar < ' a > ( & self , http : impl AsRef < Http > , name : impl std :: fmt :: Display , avatar : impl Into < AttachmentType < ' a > > ) -> Result < Webhook > { let name = name . to_string ( ) ; let avatar = avatar . into ( ) ; if name . len ( ) < 2 { return Err ( Error :: Model ( ModelError :: NameTooShort ) ) } else if name . len ( ) > 100 { return Err ( Error :: Model ( ModelError :: NameTooLong ) ) } else if self . kind . num ( ) != 0 { return Err ( Error :: Model ( ModelError :: InvalidChannelType ) ) } let avatar = match avatar { AttachmentType :: Bytes { data , filename : _ } => { " " . to_string ( ) + & base64 :: encode ( & data . into_owned ( ) ) } , AttachmentType :: File { file , filename : _ } => { let mut buf = Vec :: new ( ) ; file . try_clone ( ) . await ? . read_to_end ( & mut buf ) . await ? ; " " . to_string ( ) + & base64 :: encode ( & buf ) } , AttachmentType :: Path ( path ) => { let mut file = File :: open ( path ) . await ? ; let mut buf = vec ! [ ] ; file . read_to_end ( & mut buf ) . await ? ; " " . to_string ( ) + & base64 :: encode ( & buf ) } , AttachmentType :: Image ( url ) => { let url = Url :: parse ( url ) . map_err ( | _ | Error :: Url ( url . to_string ( ) ) ) ? ; let response = http . as_ref ( ) . client . get ( url ) . send ( ) . await ? ; let mut bytes = response . bytes ( ) . await ? ; let mut picture : Vec < u8 > = vec ! [ 0 bytes len ( ) ] ; bytes . copy_to_slice ( & mut picture [ .. ] ) ; " " . to_string ( ) + & base64 :: encode ( & picture ) } , } ; let map = serde_json :: json ! ( { " " name " " avatar } ) ; http . as_ref ( ) . create_webhook ( self . id . 0 , & map ) . await }
Avatar must be a 128x128 image.
Avatar must be a 128x128 image .
&self
http
impl AsRef<Http>
name
impl std::fmt::Display
avatar
impl Into<AttachmentType<'a>>