protected $description = 'List favourites';
public function handle($arguments) {
+ if (!$arguments) {
+ $this->replyWithMessage(
+ [
+ 'text' => "Searchfaves command requires a query to search."
+ ]
+ );
+ return;
+ }
+
$faveFiles = foldMap(☐(null)(∘(lines, 'trim', 'file_get_contents')))(glob(PATH_TO_GROOVENET . '/*.favourites.txt'));
$names = map(☐(produceValue(0))(null))(array_keys($faveFiles));
$hashes = map(map(☐(produceValue(0))(null)))(array_values($faveFiles));
$thing = map(function ($fave) use ($arguments) {
$justTitle = join(' ', array_slice(explode(' ', $fave), 0 , -2));
- similar_text($arguments, $justTitle ?: '', $perc);
+ similar_text(strtolower($arguments), strtolower($justTitle), $perc);
return ['title' => $fave, 'similarity' => $perc];
- });
+ })($newFaves);
$top5 = ∘(unlines, aaray_column('title'), aaray_slice(0)(5), 'array_reverse', 'array_values', ssort(∘(∘f(field('similarity')), ⬄, field('similarity'))));
$this->replyWithMessage(
[
- 'text' => unlines($top5($thing))
+ 'text' => "Here are the 5 most similar favourites I could find...\n\n" . $top5($thing)
]
);
}