🎉 Hello world
This commit is contained in:
53
bot/Commands/Tasks.php
Normal file
53
bot/Commands/Tasks.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user