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';