Skip to content

Commit

Permalink
Check if session exists
Browse files Browse the repository at this point in the history
  • Loading branch information
xtrime-ru committed Feb 6, 2020
1 parent e00c4c2 commit 1169f27
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public function connect($sessionFiles): void

public function addSession(string $session, array $settings = []): void
{
if (isset($this->instances[$session])) {
throw new InvalidArgumentException('Session already exists');
}
$file = static::getSessionFile($session);
$settings = array_replace_recursive((array) Config::getInstance()->get('telegram'), $settings);
$instance = new MadelineProto\API($file, $settings);
Expand All @@ -101,7 +104,7 @@ function() use ($instance) {
public function removeSession($session): void
{
if (empty($this->instances[$session])) {
throw new InvalidArgumentException('Instance not found');
throw new InvalidArgumentException('Session not found');
}

$this->instances[$session]->stop();
Expand Down

0 comments on commit 1169f27

Please sign in to comment.