From: Cameron Ball Date: Mon, 19 Nov 2018 13:33:01 +0000 (+0800) Subject: Fun function to find movies X-Git-Url: http://git.cameron1729.xyz/?p=SonOfLokstallBot.git;a=commitdiff_plain;h=ff2e9c5974b97491307ded8ae126095a96c46e4f Fun function to find movies --- diff --git a/purjolok.php b/purjolok.php index 3e78f8d..1678cb2 100644 --- a/purjolok.php +++ b/purjolok.php @@ -14,6 +14,31 @@ use function Common\{ use Telegram\Bot\Actions; use Telegram\Bot\Commands\Command; + +getTelegram()->addCommand( + new class extends Command { + protected $name = 'searchmovies'; + protected $description = 'Search through the movie collection'; + + public function handle($arguments) { + $results = array_map( + function($moviename) use ($arguments) { + similar_text($arguments, substr($moviename, 0, -7) ?: '', $perc); + return ['title' => $moviename, 'similarity' => $perc]; + }, + scandir('/mnt/media/Movies') + ); + + uasort($results, function($a, $b) { + return $b['similarity'] <=> $a['similarity']; + }); + + $results = array_column(array_slice(array_values($results), 0, 5), 'title'); + $this->replyWithMessage(['text' => "Here are the most similar movies titles I could find...\n\n" . implode("\n", $results)]); + } + } +); + getTelegram()->addCommand( new class extends Command { protected $name = 'chatid';