mirror of
https://github.com/lune-org/lune.git
synced 2025-04-07 20:10:55 +01:00
Regex is overkill. Simplify
This commit is contained in:
parent
29dc42d435
commit
15e7af97e9
1 changed files with 6 additions and 9 deletions
|
@ -3,7 +3,6 @@ use std::net::Ipv4Addr;
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
|
|
||||||
use hyper::header::CONTENT_ENCODING;
|
use hyper::header::CONTENT_ENCODING;
|
||||||
use regex::Regex;
|
|
||||||
|
|
||||||
use crate::lune::{scheduler::Scheduler, util::TableBuilder};
|
use crate::lune::{scheduler::Scheduler, util::TableBuilder};
|
||||||
|
|
||||||
|
@ -144,19 +143,17 @@ where
|
||||||
.app_data_ref::<&Scheduler>()
|
.app_data_ref::<&Scheduler>()
|
||||||
.expect("Lua struct is missing scheduler");
|
.expect("Lua struct is missing scheduler");
|
||||||
|
|
||||||
let address_pattern = Regex::new(r"(?:.*:\/\/)?(\d+\.\d+\.\d+\.\d+)(?::\d+)?").unwrap();
|
|
||||||
|
|
||||||
let address: Ipv4Addr = match &config.address {
|
let address: Ipv4Addr = match &config.address {
|
||||||
Some(addr) => {
|
Some(addr) => {
|
||||||
let addr_str = addr.to_str()?;
|
let addr_str = addr.to_str()?;
|
||||||
|
|
||||||
if let Some(caps) = address_pattern.captures(addr_str) {
|
addr_str
|
||||||
caps[1].parse::<Ipv4Addr>()?
|
.trim_start_matches("http://")
|
||||||
} else {
|
.trim_start_matches("https://")
|
||||||
return Err(LuaError::runtime(format!(
|
.parse()
|
||||||
|
.map_err(|_e| LuaError::RuntimeError(format!(
|
||||||
"IP address format is incorrect (expected an IP in the form 'http://0.0.0.0' or '0.0.0.0', got '{addr_str}')"
|
"IP address format is incorrect (expected an IP in the form 'http://0.0.0.0' or '0.0.0.0', got '{addr_str}')"
|
||||||
)));
|
)))?
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => DEFAULT_IP_ADDRESS,
|
None => DEFAULT_IP_ADDRESS,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue