Fix some unwrap's

This commit is contained in:
2022-11-06 23:23:34 +01:00
parent b53f87452d
commit 13a63f277c
3 changed files with 51 additions and 38 deletions

View File

@@ -27,7 +27,8 @@ pub enum AnnotationCommand {
impl CommandParse<Self> for AnnotationCommand {
fn parse(s: &str, bot_name: &str) -> Result<Self, strum::ParseError> {
let re = Regex::new(r"^/(?P<an_type>a|b)_an_(?P<id>\d+)$").unwrap();
let re = Regex::new(r"^/(?P<an_type>a|b)_an_(?P<id>\d+)$")
.unwrap_or_else(|_| panic!("Can't create AnnotationCommand regexp!"));
let full_bot_name = format!("@{bot_name}");
let after_replace = s.replace(&full_bot_name, "");
@@ -39,7 +40,9 @@ impl CommandParse<Self> for AnnotationCommand {
};
let annotation_type = &caps["an_type"];
let id: u32 = caps["id"].parse().unwrap();
let id: u32 = caps["id"]
.parse()
.unwrap_or_else(|_| panic!("Can't get id from AnnotationCommand!"));
match annotation_type {
"a" => Ok(AnnotationCommand::Author { id }),

View File

@@ -78,12 +78,15 @@ impl BotsManager {
.auto_send();
let token = bot.inner().token();
let port = self.bot_port_map.get(&bot_data.id).unwrap();
let port = self.bot_port_map
.get(&bot_data.id)
.unwrap_or_else(|| panic!("Can't get bot port!"));
let addr = ([0, 0, 0, 0], *port).into();
let host = format!("{}:{}", &config::CONFIG.webhook_base_url, port);
let url = Url::parse(&format!("{host}/{token}")).unwrap();
let url = Url::parse(&format!("{host}/{token}"))
.unwrap_or_else(|_| panic!("Can't parse webhook url!"));
log::info!(
"Start bot(id={}) with {:?} handler, port {}",