Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ emojis = "0.8.0"
floodgate = "0.5.1"
futures = "0.3.31"
humantime = "2.3.0"
lazy_static = "1.5.0"
moka = { version = "0.11.3", features = ["future"] }
psutil = "3.3.0"
regex = "1.12.2"
Expand Down
20 changes: 9 additions & 11 deletions src/core/embedder/attachment_handle.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::sync::LazyLock;

use async_trait::async_trait;
use lazy_static::lazy_static;
use regex::Regex;
use twilight_model::{
channel::{Attachment as ReceivedAttachment, message::embed::Embed},
http::attachment::Attachment,
Expand Down Expand Up @@ -27,17 +29,13 @@ impl AttachmentHandle {
) -> StarboardResult<Option<Attachment>> {
// this should always be a proxy url, but we do this to make 100%
// sure that there isn't a bug that could potentially leak the VPS ip.
{
lazy_static! {
static ref RE: regex::Regex = regex::Regex::new(
r#"^https://[\w\.\-]*\.(discord\.com|discordapp\.com|discordapp.net)"#
)
.unwrap();
}
static RE: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r#"^https://[\w\.\-]*\.(discord\.com|discordapp\.com|discordapp.net)"#)
.unwrap()
});

if !RE.is_match(&self.url) {
return Ok(None);
}
if !RE.is_match(&self.url) {
return Ok(None);
}

// we only want to download files under 8mb
Expand Down
11 changes: 5 additions & 6 deletions src/core/embedder/builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::fmt::Write;
use std::{fmt::Write, sync::LazyLock};

use lazy_static::lazy_static;
use regex::Regex;
use twilight_model::{
channel::message::{
Expand Down Expand Up @@ -29,13 +28,13 @@ use crate::{
},
};

lazy_static! {
static ref URL_REGEX: Regex = Regex::new(concat!(
static URL_REGEX: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(concat!(
r"^https?://(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]",
r"{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&/=]*)$"
))
.unwrap();
}
.unwrap()
});

pub struct FullBuiltStarboardEmbed {
pub top_content: String,
Expand Down
19 changes: 8 additions & 11 deletions src/core/embedder/gifv.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
use std::str::FromStr;
use std::{str::FromStr, sync::LazyLock};

use lazy_static::lazy_static;
use regex::Regex;
use reqwest::Url;

pub fn get_gif_url(url: &str, provider: &str) -> Option<String> {
lazy_static! {
static ref TENOR: regex::Regex =
regex::Regex::new(r#"^https://media\.tenor\.com?/(.+)/(.*)\.\w+$"#).unwrap();
}
lazy_static! {
static ref GIPHY: regex::Regex =
regex::Regex::new(r#"^https://media\d*\.giphy\.com/media/([\w-]+)/(.*)\.gif$"#)
.unwrap();
}
static TENOR: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r#"^https://media\.tenor\.com?/(.+)/(.*)\.\w+$"#).unwrap());
static GIPHY: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(r#"^https://media\d*\.giphy\.com/media/([\w-]+)/(.*)\.gif$"#).unwrap()
});

match provider {
"Tenor" => {
Expand Down Expand Up @@ -53,6 +49,7 @@ pub fn get_gif_url(url: &str, provider: &str) -> Option<String> {

Some(format!("{origin}/{gif_id}-size_restricted.gif"))
}
"Klipy" => Some(url.to_owned()), // I take back everything bad I said about klipy
other => {
eprintln!("Unkown GIFV provider: {other}\n{url}");
None
Expand Down
10 changes: 5 additions & 5 deletions src/core/embedder/imgur.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use lazy_static::lazy_static;
use std::sync::LazyLock;

use regex::Regex;
use twilight_model::channel::message::{Embed, embed::EmbedImage};

use super::AttachmentHandle;
Expand Down Expand Up @@ -36,10 +38,8 @@ pub fn modify_imgur_embed(mut embed: Embed) -> ImgurResult {
}

pub fn modify_imgur_url(url: &str) -> Option<String> {
lazy_static! {
static ref RE: regex::Regex =
regex::Regex::new(r#"https://i\.imgur\.com/(\w+)\.(\w+)"#).unwrap();
}
static RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r#"https://i\.imgur\.com/(\w+)\.(\w+)"#).unwrap());

let caps: Vec<_> = RE.captures_iter(url).collect();
let groups = caps.first()?;
Expand Down
7 changes: 2 additions & 5 deletions src/core/emoji.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::str::FromStr;
use std::{str::FromStr, sync::LazyLock};

use lazy_static::lazy_static;
use regex::Regex;
use twilight_http::request::channel::reaction::RequestReactionType;
use twilight_mention::Mention;
Expand Down Expand Up @@ -57,9 +56,7 @@ impl SimpleEmoji {
bot: &StarboardBot,
guild_id: Id<GuildMarker>,
) -> Vec<Self> {
lazy_static! {
static ref CUSTOM: Regex = Regex::new(r"^\d{10,}").unwrap();
}
static CUSTOM: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^\d{10,}").unwrap());

let mut emojis = Vec::new();

Expand Down
10 changes: 5 additions & 5 deletions src/database/validation/cooldown.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use lazy_static::lazy_static;
use std::sync::LazyLock;

use regex::Regex;

pub fn parse_cooldown(inp: &str) -> Result<(i16, i16), String> {
lazy_static! {
static ref RE: regex::Regex =
regex::Regex::new(r#"(?P<count>\d+).+?(?P<secs>\d+)"#).unwrap();
}
static RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r#"(?P<count>\d+).+?(?P<secs>\d+)"#).unwrap());

let found = match RE.captures(inp) {
None => {
Expand Down
8 changes: 3 additions & 5 deletions src/database/validation/mentions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Parsing and validation for different types of mentions.

use std::{collections::HashSet, str::FromStr};
use std::{collections::HashSet, str::FromStr, sync::LazyLock};

use lazy_static::lazy_static;
use regex::Regex;
use twilight_model::id::{Id, marker::GuildMarker};

use crate::{client::bot::StarboardBot, errors::StarboardResult, utils::id_as_i64::GetI64};
Expand All @@ -12,9 +12,7 @@ where
IdT: FromStr,
<IdT as FromStr>::Err: std::fmt::Debug,
{
lazy_static! {
static ref RE: regex::Regex = regex::Regex::new(r#"\d+"#).unwrap();
}
static RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r#"\d+"#).unwrap());

RE.find_iter(inp).map(|val| val.as_str().parse().unwrap())
}
Expand Down
8 changes: 3 additions & 5 deletions src/database/validation/time_delta.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{borrow::Cow, time::Duration};
use std::{borrow::Cow, sync::LazyLock, time::Duration};

use lazy_static::lazy_static;
use regex::Regex;

use crate::constants;
Expand Down Expand Up @@ -36,9 +35,8 @@ fn unit_conversion(unit: &str) -> Option<i64> {
}

pub fn parse_time_delta(inp: &str) -> Result<i64, String> {
lazy_static! {
static ref RE: Regex = Regex::new(r#"^(?P<value>\d+)(?P<unit>\w+)$"#).unwrap();
}
static RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r#"^(?P<value>\d+)(?P<unit>\w+)$"#).unwrap());

let mut seconds = 0;
let mut carry = None;
Expand Down
8 changes: 3 additions & 5 deletions src/utils/message_link.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::fmt::Display;
use std::{fmt::Display, sync::LazyLock};

use lazy_static::lazy_static;
use regex::Regex;

pub fn parse_message_link(link: &str) -> Option<(i64, i64)> {
Expand All @@ -17,9 +16,8 @@ pub fn parse_message_link(link: &str) -> Option<(i64, i64)> {
return Some((channel_id, message_id));
}

lazy_static! {
static ref RE: Regex = Regex::new(r#"/channels/(\d+)/(\d+)/(\d+)"#).unwrap();
}
static RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r#"/channels/(\d+)/(\d+)/(\d+)"#).unwrap());

let ret = RE.captures(link)?;

Expand Down