songy

telegram bot as a songbook
git clone git://git.relim.de/songy.git
Log | Files | Refs | README | LICENSE

commit be414673c1467cd413dec138a2284ad4864a51f2
parent b07583dc089edbbadb5df5201c33e61de53009ec
Author: devnibo <kroekerrobin@gmail.com>
Date:   Thu, 13 Jul 2023 09:21:15 +0200

Refactor and little bit writing doc

Diffstat:
MREADME.md | 5+++++
Msrc/langs.rs | 24++++++++++++------------
2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/README.md b/README.md @@ -66,6 +66,11 @@ line 2: <filename_without_extension>:<song_title>:<song_lyrics> ... ``` +`<filename_wihtout_extension>` shouldn't contain any hyphens (`-`) or umlauts. This will be taken as the command in the list of songs and telegram will only treat the whole name as a command if you meat this requirement. + +`<song_title>` can contain umlauts. +`<song_lyrics>` can contain umlauts. + ##### Example So suppose you have the song `Love Me Tender` in your `--songs-path` folder and the actual file name is `Love_Me_Tender.pdf` . The line for the `--search_file` text file could look like this: diff --git a/src/langs.rs b/src/langs.rs @@ -14,7 +14,7 @@ impl Strings { let l: &str = lang.as_str(); match l { "de" => { - start_msg = format!( + start_msg = String::from(format!( "Hallo. Dies ist ein digitales Liederbuch. :)\n\ Befehle:\n\ /list - Listet alle Lieder auf\n\ @@ -22,11 +22,11 @@ impl Strings { Ansonsten tippe einfach den Titel oder Teile des Titels \ des Liedes ein und du bekommst dein Lied zugeschickt.", get_commands(songs_path).as_str() - ).to_string(); - song_not_found = "Kein Lied mit diesem Titel gefunden.".to_string(); + )); + song_not_found = String::from("Kein Lied mit diesem Titel gefunden."); }, "md" => { - start_msg = format!( + start_msg = String::from(format!( "Salut! Această e o carte de cântari digitală. :)\n\ Comenzi:\n\ /list - Listează toate cântările\n\ @@ -34,11 +34,11 @@ impl Strings { Deasemenea puteți introduce titlul sau cuvinte din titlul \ cântării iar bot-ul va găsi piesa corespondentă.", get_commands(songs_path).as_str() - ).to_string(); - song_not_found = "Niciun cântec găsit cu acest nume".to_string(); + )); + song_not_found = String::from("Niciun cântec găsit cu acest nume"); }, _ => { - start_msg = format!( + start_msg = String::from(format!( "Hello. This is a digital song book. :)\n\ Commands:\n\ /list - Lists all songs\n\ @@ -46,8 +46,8 @@ impl Strings { Otherwise simply type the title or parts of the title \ of the song and you will receive the song.", get_commands(songs_path).as_str() - ).to_string(); - song_not_found = "Didn't find any song with this title.".to_string(); + )); + song_not_found = String::from("Didn't find any song with this title."); } } Self { @@ -93,15 +93,15 @@ fn get_commands(songs_path: String) -> String { } pub fn get_folder_names(songs_path: &String) -> Vec<String> { - let songs_dir = fs::read_dir(songs_path).expect("Error: read_dir songs_path"); + let songs_dir = fs::read_dir(songs_path).unwrap(); let mut folder_names: Vec<String> = vec![]; let mut is_dir: bool; let mut dir_entry; for f in songs_dir { dir_entry = f.expect("Error: f"); - is_dir = dir_entry.file_type().expect("Error: is_dir").is_dir(); + is_dir = dir_entry.file_type().unwrap().is_dir(); if is_dir { - let name: String = dir_entry.file_name().to_str().expect("Error: filename").to_string(); + let name: String = dir_entry.file_name().to_str().unwrap().to_string(); folder_names.push(name) } }