🎉 Hello world

This commit is contained in:
2020-03-26 00:11:37 +01:00
commit eedfbcc2ab
14 changed files with 686 additions and 0 deletions

53
bot/Commands/Tasks.php Normal file
View 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';
}
}