example
This commit is contained in:
parent
ce86994af0
commit
5e86865841
32
example.php
Normal file
32
example.php
Normal 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();
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user