redcatbot/RedCat/RecordFormatter.fs
2024-05-16 11:03:36 +02:00

53 lines
No EOL
2.2 KiB
Forth
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

module RedCat.RecordFormatter
open RedCat.DrugsDataExtractor
let formatDrugInput (drugRawName: string) =
drugRawName.ToLower().Replace(" ", "").Replace("-", "").Replace(",", "")
let formatDrugInfoResponse (drugData: DrugRecord) =
let toPrettyString (drugInfo: string option) =
match drugInfo with
| Some s when drugInfo = drugData.Summary -> $"📜 {s}" |> Some
| Some s when drugInfo = drugData.Dose -> $"🍽️ {s}" |> Some
| Some s when drugInfo = drugData.TotalDuration -> $"⏳ Durata: {s}" |> Some
| Some s when drugInfo = drugData.OnSet -> $"🤯 Inizio effetti: {s}" |> Some
| _ -> None
let formattedCategories =
drugData.Categories
|> Option.bind(fun catgs -> catgs |> String.concat " | " |> Some)
let mainResponseText =
[drugData.Summary; drugData.Dose; drugData.TotalDuration; drugData.OnSet]
|> List.choose toPrettyString
|> String.concat "\n\n"
match formattedCategories with
| None -> $"~{drugData.Name} \n\n{mainResponseText}"
| Some categories -> $"~{drugData.Name} [ {categories} ]\n\n{mainResponseText}"
let formatComboRecord (comboData: ComboRecord) =
let translate (s: string) =
match s with
| "Dangerous" -> "❌ Molto pericoloso alla vita e alla salute"
| "Unsafe" -> "‼️ Pericoloso"
| "Caution" -> "⚠️ Attenzione"
| "Low Risk & Synergy" -> " Rischio basso e amplificazione effetto "
| "Low Risk & Decrease" -> " Rischio basso e diminuzione effetto "
| "Low Risk & No Synergy" -> "🟰🟰 Rischio basso e interazione assente 🟰🟰"
| _ -> failwith "Shouldn't happen here"
let toPrettyString (comboInfo: string option) =
match comboInfo with
| Some s when comboInfo = comboData.Status -> $"{translate s}" |> Some
| Some s when comboInfo = comboData.Note -> $"{s}" |> Some
| _ -> None
let comboText =
[comboData.Status; comboData.Note]
|> List.choose toPrettyString
|> String.concat "\n"
$"[{comboData.DrugA}] ~ [{comboData.DrugB}]\n\n{comboText}"