Framework
This commit is contained in:
19
src/Handlers.php
Normal file
19
src/Handlers.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
require 'MessageHandler.php';
|
||||
|
||||
class TestHandler implements MessageHandler
|
||||
{
|
||||
|
||||
public function CanHandle($room_id, $msgid, $message): bool
|
||||
{
|
||||
// TODO: Implement canHandle() method.
|
||||
return $msgid == 0;
|
||||
}
|
||||
|
||||
public function Handle($room_id, $msgid, $message): string
|
||||
{
|
||||
// TODO: Implement handle() method.
|
||||
return "uwu";
|
||||
}
|
||||
}
|
||||
7
src/MessageHandler.php
Normal file
7
src/MessageHandler.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
interface MessageHandler
|
||||
{
|
||||
public function CanHandle($room_id, $msgid, $message): bool;
|
||||
public function Handle($room_id, $msgid, $message): string;
|
||||
}
|
||||
@@ -10,7 +10,24 @@ define("INTER_ROOM", 111213);
|
||||
|
||||
// randomorg($start,$end);
|
||||
|
||||
function reply_user($room_id, $msgid, $message) : string
|
||||
require 'Handlers.php';
|
||||
|
||||
$handlers = array(
|
||||
new TestHandler()
|
||||
);
|
||||
|
||||
function reply_user($room_id, $msgid, $message)
|
||||
{
|
||||
return $msgid;
|
||||
// Placeholder Globals
|
||||
global $userid;
|
||||
global $room_lang;
|
||||
global $is_admin;
|
||||
|
||||
global $handlers;
|
||||
foreach ($handlers as $handler) {
|
||||
if($handler->CanHandle($room_id, $msgid, $message)) {
|
||||
return $handler->Handle($room_id, $msgid, $message);
|
||||
}
|
||||
}
|
||||
return ;
|
||||
}
|
||||
@@ -12,6 +12,6 @@ do {
|
||||
$input = fread(STDIN, 80); // Read up to 80 characters or a newline
|
||||
$trimmed = trim($input);
|
||||
|
||||
echo '> ' , reply_user($room_id, $msg_id, $trimmed) , "\n";
|
||||
echo $msg_id, ' > ' , reply_user($room_id, $msg_id, $trimmed) , "\n";
|
||||
$msg_id++;
|
||||
} while($trimmed !== "exit");
|
||||
Reference in New Issue
Block a user