fix: title can be more than one word
This commit is contained in:
parent
280acaa8b0
commit
7a4253f723
26
src/main.rs
26
src/main.rs
|
@ -70,7 +70,7 @@ struct Message {
|
|||
time: String,
|
||||
}
|
||||
|
||||
async fn generate_post(config: &Config, client: &mut Client) -> Result<String> {
|
||||
async fn generate_post(config: &Config, client: &mut Client, title: &str) -> Result<String> {
|
||||
let day: DateTime<Local> = Local::now();
|
||||
let file = PathBuf::from(format!("{}/texts.json", config.data_folder));
|
||||
let tempdir = tempdir()?;
|
||||
|
@ -84,6 +84,7 @@ async fn generate_post(config: &Config, client: &mut Client) -> Result<String> {
|
|||
.ok_or_eyre("Gestern gab es nicht?????????")?
|
||||
.format("%d.%m.%Y")
|
||||
.to_string(),
|
||||
title: title.to_string(),
|
||||
..Default::default()
|
||||
};
|
||||
let mut msgs = Vec::new();
|
||||
|
@ -209,7 +210,12 @@ async fn main() -> Result<()> {
|
|||
if let Some(text) = text {
|
||||
// ©ontrol character
|
||||
let cmds: Vec<&str> = text.split_whitespace().collect();
|
||||
if cmds.len() >= 2 && cmds[0] == "©" {
|
||||
if text.starts_with("©") {
|
||||
if cmds.len() == 1 {
|
||||
let text = "\nAvailable commands:\n - post: Generate post for yesterday\n - tz: change timezone\n"
|
||||
.to_string();
|
||||
send(&client, sender, text).await?;
|
||||
}
|
||||
match cmds[1] {
|
||||
"help" => {
|
||||
let text = "\nAvailable commands:\n - post: Generate post for yesterday\n - tz: change timezone\n"
|
||||
|
@ -217,15 +223,15 @@ async fn main() -> Result<()> {
|
|||
send(&client, sender, text).await?;
|
||||
}
|
||||
"post" => {
|
||||
if cmds.len() != 3 {
|
||||
send(
|
||||
&client,
|
||||
sender,
|
||||
"Wrong number of arguments.\nExpected: 1(title)".to_string(),
|
||||
)
|
||||
.await?;
|
||||
if cmds.len() < 3 {
|
||||
send(&client, sender, "Missing title".to_string()).await?;
|
||||
} else {
|
||||
let res = generate_post(&config, &mut client.borrow_mut()).await;
|
||||
let res = generate_post(
|
||||
&config,
|
||||
&mut client.borrow_mut(),
|
||||
&cmds[2..].join(" "),
|
||||
)
|
||||
.await;
|
||||
if let Ok(res) = res {
|
||||
send(
|
||||
&client,
|
||||
|
|
Loading…
Reference in a new issue