-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20556c0
commit ef13e77
Showing
13 changed files
with
318 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
} | ||
], | ||
"license": "MIT", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"require": { | ||
"php": "^8.0.0" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace AliceFramework; | ||
|
||
use AliceFramework\Commands\CommandList; | ||
|
||
class App | ||
{ | ||
/** | ||
* @var string Dialog name | ||
*/ | ||
private string $name; | ||
|
||
/** | ||
* @var Request Dialog request | ||
*/ | ||
private Request $request; | ||
|
||
/** | ||
* @param string $data Request | ||
* @param string $name Dialog Name | ||
*/ | ||
public function __construct(string $data, string $name = "AliceFramework") | ||
{ | ||
$this->name = strtolower($name); | ||
$this->request = new Request($data); | ||
} | ||
|
||
/** | ||
* Start processing request data | ||
* | ||
* @return false|string | ||
*/ | ||
public function start() : false|string | ||
{ | ||
if (!$this->request->isValid()) | ||
return Response::error('Wrong request'); | ||
|
||
$response = new Response( | ||
$this->request->getSessionId(), | ||
$this->request->getMessageId(), | ||
$this->request->getUserId() | ||
); | ||
|
||
// Command includes skill name | ||
if (str_contains($this->request->getCommand(), $this->name) || empty($this->request->getCommand())) | ||
return $response->success('Hello i am ' . $this->name); | ||
|
||
// Check command | ||
if (!CommandList::exists($this->request->getCommand())) | ||
return $response->success('I do not understand'); | ||
|
||
// Command processing | ||
try { | ||
return $response->success( | ||
(new CommandList::$commands[$this->request->getCommand()])->start() | ||
); | ||
} | ||
catch (\Exception $e) | ||
{ | ||
return Response::error('Command error'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace AliceFramework\Commands; | ||
|
||
interface Command | ||
{ | ||
public function start() : string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace AliceFramework\Commands; | ||
|
||
class CommandList | ||
{ | ||
/** | ||
* @var array $commands List of all active commands | ||
*/ | ||
public static array $commands = [ | ||
"случайная цитата" => RandomQuote::class, | ||
"пример" => Example::class | ||
]; | ||
|
||
/** | ||
* Check if command exists | ||
* | ||
* @param string $command Command name | ||
* @return bool | ||
*/ | ||
public static function exists(string $command) : bool | ||
{ | ||
return array_key_exists($command, CommandList::$commands); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.