|
|
|
@ -1,6 +1,5 @@
|
|
|
|
|
use crate::utils::error::BotResult;
|
|
|
|
|
use rand::Rng;
|
|
|
|
|
use regex::Regex;
|
|
|
|
|
use serenity::client::Context;
|
|
|
|
|
use serenity::model::channel::Message;
|
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
@ -38,38 +37,3 @@ pub async fn get_previous_message_or_reply(
|
|
|
|
|
|
|
|
|
|
Ok(referenced)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns the file for a given domain
|
|
|
|
|
pub fn get_file_name_for_domain(url: &str) -> Option<String> {
|
|
|
|
|
lazy_static::lazy_static! {
|
|
|
|
|
static ref FILE_REGEX: Regex = Regex::new(r"^(https?://)?(www\.)?(\w+\.)+\w+([^/]*/)*([^/]+)$").unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let captures = FILE_REGEX.captures(url)?;
|
|
|
|
|
|
|
|
|
|
captures.get(3).map(|c| c.as_str().to_string())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns if the given file is an image
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn is_image(url: &str) -> bool {
|
|
|
|
|
static IMAGE_EXTENSIONS: &[&str] = &["png", "webp", "jpg", "jpeg", "ico", "gif"];
|
|
|
|
|
for ext in IMAGE_EXTENSIONS {
|
|
|
|
|
if url.ends_with(ext) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns if the given file is an image
|
|
|
|
|
#[inline]
|
|
|
|
|
pub fn is_video(url: &str) -> bool {
|
|
|
|
|
static IMAGE_EXTENSIONS: &[&str] = &["mp4", "flv", "mkv", "webm"];
|
|
|
|
|
for ext in IMAGE_EXTENSIONS {
|
|
|
|
|
if url.ends_with(ext) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|