This commit is contained in:
groug 2023-10-22 14:09:08 +02:00
parent ce86994af0
commit 5e86865841
2 changed files with 32 additions and 21 deletions

32
example.php Normal file
View File

@ -0,0 +1,32 @@
<?php
require_once "phpmatrix.php";
$cb = function($event)
{
if ($event->event_type == "m.room.message") {
if ($event->content["body"] && $event->content["body"][0] === "!") {
$command_parts = explode(" ", $event->content["body"], 2);
$command = $command_parts[0];
$arg = isset($command_parts[1]) ? $command_parts[1] : "";
switch($command) {
case "!echo":
$event->room->send_text($arg);
break;
case "!help":
$event->room->send_text("Usage: !COMMAND ARG1 ARG2...\n!echo TEXT => repeat TEXT");
break;
}
}
}
};
$m = new MatrixClient("https://domain.tld");
//$m->login_with_password("@bot:domain.tld", "password");
//echo $m->get_access_token() . "\n";
$m->login_with_token("@bot:domain.tld", "token");
$room = $m->join_room("!roomname:domain.tld");
//$room->send_text("pouet");
$room->add_listener($cb);
$m->run();

View File

@ -256,24 +256,3 @@ class MatrixRoom
} }
} }
} }
$cb = function($event)
{
if ($event->event_type == "m.room.message") {
var_dump($event);
if ($event->content["body"] && $event->content["body"][0] === "!") {
$command_parts = explode(" ", $event->content["body"], 2);
$command = $command_parts[0];
$arg = isset($command_parts[1]) ? $command_parts[1] : "";
switch($command) {
case "!echo":
$event->room->send_text($arg);
break;
case "!help":
$event->room->send_text("Usage: !COMMAND ARG1 ARG2...\n!echo TEXT => repeat TEXT");
break;
}
}
}
};