mirror of
https://github.com/flibusta-apps/book_bot.git
synced 2025-12-06 15:35:35 +01:00
Fix some unwrap's
This commit is contained in:
@@ -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 }),
|
||||
|
||||
@@ -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 {}",
|
||||
|
||||
Reference in New Issue
Block a user