getTelegram()->addCommand(
new class extends Command {
+ protected $name = 'search';
+ protected $description = 'Search songs list';
+
+ public function handle($arguments) {
+ if (!$arguments) {
+ $this->replyWithMessage(
+ [
+ 'text' => "Search command requires a query to search."
+ ]
+ );
+ return;
+ }
+
+ $songs = map(function ($song) use ($arguments) {
+ similar_text(strtolower($arguments), strtolower($song), $perc);
+ return ['title' => $song, 'similarity' => $perc];
+ })(unserialize(file_get_contents(__DIR__ . '/hashmap.txt')));
+ $top5 = ∘(unlines, aaray_column('title'), aaray_slice(0)(5), 'array_reverse', 'array_values', ssort(∘(∘f(field('similarity')), ⬄, field('similarity'))));
+
+ $this->replyWithMessage(
+ [
+ 'text' => "Here are the 5 most similar favourites I could find...\n\n" . $top5($songs)
+ ]
+ );
+ }
+ }
+);
+
+getTelegram()->addCommand(
+ new class extends Command {
protected $name = 'searchfaves';
- protected $description = 'List favourites';
+ protected $description = 'Search favourites';
public function handle($arguments) {
if (!$arguments) {