From 266aaf96b3988cb63e0e195460344a3c57915208 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 20 Aug 2023 14:48:34 +0200 Subject: [PATCH] Validate songs --- magna.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/magna.php b/magna.php index 862ddf9..6546515 100755 --- a/magna.php +++ b/magna.php @@ -29,6 +29,7 @@ use danog\MadelineProto\EventHandler\SimpleFilter\Incoming; use danog\MadelineProto\EventHandler\SimpleFilter\IsReply; use danog\MadelineProto\Exception; use danog\MadelineProto\LocalFile; +use danog\MadelineProto\Ogg; use danog\MadelineProto\RPCErrorException; use danog\MadelineProto\SimpleEventHandler; use danog\MadelineProto\Tools; @@ -164,10 +165,24 @@ class MyEventHandler extends SimpleEventHandler private $my_users; private $me; public $calls = []; + private array $songs = []; public function onStart(): void { $this->me = '@' . ((($this->getSelf())['username']) ?? 'magnaluna'); + $songs = glob('*ogg'); + if (!$songs) { + throw new \AssertionError('No songs defined! Convert some songs by sending them to https://t.me/libtgvoipbot and putting them in the current directory'); + } + foreach ($songs as $song) { + try { + Ogg::validateOgg(new LocalFile($song)); + } catch (Throwable $e) { + throw new AssertionError("An error occurred during validation of $song, please convert the file using convert.php or @libtgvoipbot!", 0, $e); + } + } + $this->songs = $songs; + $this->programmed_call = []; foreach ($this->programmed_call as $key => [$user, $time]) { continue; @@ -217,10 +232,7 @@ class MyEventHandler extends SimpleEventHandler } public function configureCall(VoIP $call): void { - $songs = glob('*ogg'); - if (!$songs) { - throw new \AssertionError('No songs defined! Convert some songs by sending them to https://t.me/libtgvoipbot and putting them in the current directory'); - } + $songs = $this->songs; $songs_length = count($songs); for ($x = 0; $x < $songs_length; $x++) {