feat(january): add MAX_EMBED_COUNT variable
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
use crate::util::{
|
use crate::util::{
|
||||||
result::{Error, Result},
|
result::{Error, Result},
|
||||||
variables::JANUARY_URL,
|
variables::JANUARY_URL,
|
||||||
|
variables::MAX_EMBED_COUNT,
|
||||||
};
|
};
|
||||||
use linkify::{LinkFinder, LinkKind};
|
use linkify::{LinkFinder, LinkKind};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
@@ -126,7 +127,7 @@ impl Embed {
|
|||||||
|
|
||||||
let mut finder = LinkFinder::new();
|
let mut finder = LinkFinder::new();
|
||||||
finder.kinds(&[LinkKind::Url]);
|
finder.kinds(&[LinkKind::Url]);
|
||||||
let links: Vec<_> = finder.links(&content).take(5).collect();
|
let links: Vec<_> = finder.links(&content).take(*MAX_EMBED_COUNT).collect();
|
||||||
|
|
||||||
if links.len() == 0 {
|
if links.len() == 0 {
|
||||||
return Err(Error::LabelMe);
|
return Err(Error::LabelMe);
|
||||||
@@ -134,14 +135,13 @@ impl Embed {
|
|||||||
|
|
||||||
let mut embeds: Vec<Embed> = Vec::new();
|
let mut embeds: Vec<Embed> = Vec::new();
|
||||||
|
|
||||||
// ! FIXME: allow configuration of number of embeds
|
|
||||||
// ! FIXME: batch request to january?
|
|
||||||
let mut link_index = 0;
|
let mut link_index = 0;
|
||||||
|
|
||||||
|
// ! FIXME: batch request to january?
|
||||||
while link_index < links.len() {
|
while link_index < links.len() {
|
||||||
let link = &links[link_index];
|
let link = &links[link_index];
|
||||||
|
|
||||||
// Check if we did the same link already in for this message.
|
// Check if we already processed this link.
|
||||||
if link_index != 0 && links.iter().take(link_index).any(|x| x.as_str() == link.as_str()) {
|
if link_index != 0 && links.iter().take(link_index).any(|x| x.as_str() == link.as_str()) {
|
||||||
link_index = link_index + 1;
|
link_index = link_index + 1;
|
||||||
continue;
|
continue;
|
||||||
@@ -169,7 +169,7 @@ impl Embed {
|
|||||||
link_index = link_index + 1;
|
link_index = link_index + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent database update when no embeds are found
|
// Prevent database update when no embeds are found.
|
||||||
if embeds.len() > 0 {
|
if embeds.len() > 0 {
|
||||||
Ok(embeds)
|
Ok(embeds)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ lazy_static! {
|
|||||||
env::var("REVOLT_MAX_GROUP_SIZE").unwrap_or_else(|_| "50".to_string()).parse().unwrap();
|
env::var("REVOLT_MAX_GROUP_SIZE").unwrap_or_else(|_| "50".to_string()).parse().unwrap();
|
||||||
pub static ref MAX_BOT_COUNT: usize =
|
pub static ref MAX_BOT_COUNT: usize =
|
||||||
env::var("REVOLT_MAX_BOT_COUNT").unwrap_or_else(|_| "5".to_string()).parse().unwrap();
|
env::var("REVOLT_MAX_BOT_COUNT").unwrap_or_else(|_| "5".to_string()).parse().unwrap();
|
||||||
|
pub static ref MAX_EMBED_COUNT: usize =
|
||||||
|
env::var("REVOLT_MAX_EMBED_COUNT").unwrap_or_else(|_| "5".to_string()).parse().unwrap();
|
||||||
pub static ref EARLY_ADOPTER_BADGE: i64 =
|
pub static ref EARLY_ADOPTER_BADGE: i64 =
|
||||||
env::var("REVOLT_EARLY_ADOPTER_BADGE").unwrap_or_else(|_| "0".to_string()).parse().unwrap();
|
env::var("REVOLT_EARLY_ADOPTER_BADGE").unwrap_or_else(|_| "0".to_string()).parse().unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user