54 lines
1.2 KiB
PHP
54 lines
1.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Shikiryu\Bot\Commands;
|
||
|
|
||
|
use JsonRPC\Client;
|
||
|
use Shikiryu\Bot\Bot;
|
||
|
|
||
|
class Tasks implements Icommands
|
||
|
{
|
||
|
public static function getMessage(Bot $bot, array $data)
|
||
|
{
|
||
|
$config = $bot->getConfig();
|
||
|
if (!array_key_exists('kanboard', $config)) {
|
||
|
$bot->replyPolitely('Je n\'ai pas la configuration nécessaire');
|
||
|
}
|
||
|
$config = $config['kanboard'];
|
||
|
$client = new Client($config['url']);
|
||
|
$client->authentication('jsonrpc', $config['token']);
|
||
|
|
||
|
$task = $data[1];
|
||
|
$project = $data[2];
|
||
|
|
||
|
if (!is_numeric($project)) {
|
||
|
$asked_project = strtolower($project);
|
||
|
$projects = $client->getAllProjects();
|
||
|
foreach ($projects as $project) {
|
||
|
if (strtolower($project['name']) === $asked_project) {
|
||
|
$project = (int) $project['id'];
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$new_task = $client->createTask([
|
||
|
'title' => $task,
|
||
|
'project_id' => $project,
|
||
|
]);
|
||
|
|
||
|
if ($new_task === false) {
|
||
|
$bot->replyPolitely('La tâche n\'a pas pu être ajoutée.');
|
||
|
} else {
|
||
|
$bot->replyPolitely(sprintf('Tâche ajoutée. Elle porte le n°%u', $new_task));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @return string
|
||
|
*/
|
||
|
public static function getDescription()
|
||
|
{
|
||
|
return 'Ajoute une tâche dans Kanboard';
|
||
|
}
|
||
|
}
|