2017-01-25 07:04:29 +03:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* This file is a part of Mibew Slack Plugin.
|
|
|
|
*
|
|
|
|
* Copyright 2017 Derek McDaniel <dmcdaniel12@gmail.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Mibew\Mibew\Plugin\Slack;
|
|
|
|
|
|
|
|
use Maknz\Slack\Client;
|
|
|
|
use Mibew\EventDispatcher\EventDispatcher;
|
|
|
|
use Mibew\EventDispatcher\Events;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
|
|
|
|
class Plugin extends \Mibew\Plugin\AbstractPlugin implements \Mibew\Plugin\PluginInterface
|
|
|
|
{
|
|
|
|
public function __construct($config)
|
|
|
|
{
|
|
|
|
parent::__construct($config);
|
|
|
|
|
|
|
|
// Use autoloader for Composer's packages that shipped with the plugin
|
|
|
|
require(__DIR__ . '/vendor/autoload.php');
|
|
|
|
}
|
2017-02-25 15:09:08 +03:00
|
|
|
/**
|
|
|
|
* Initializer
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2017-01-25 07:04:29 +03:00
|
|
|
public function initialized()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2017-02-25 15:09:08 +03:00
|
|
|
/**
|
|
|
|
* This creates the listener that listens for new
|
|
|
|
* threads to send out slack notifications
|
|
|
|
*/
|
2017-02-02 06:54:28 +03:00
|
|
|
public function run()
|
2017-01-25 07:04:29 +03:00
|
|
|
{
|
|
|
|
$dispatcher = EventDispatcher::getInstance();
|
|
|
|
$dispatcher->attachListener(Events::THREAD_CREATE, $this, 'sendSlackNotification');
|
|
|
|
}
|
2017-02-25 15:09:08 +03:00
|
|
|
/**
|
|
|
|
* Sends notification to slack.
|
|
|
|
* Sends the date with the username as well
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2017-01-25 07:04:29 +03:00
|
|
|
public function sendSlackNotification(&$args)
|
|
|
|
{
|
|
|
|
$settings = [
|
2017-02-02 06:54:28 +03:00
|
|
|
'username' => $this->config['username'],
|
|
|
|
'channel' => '#' . $this->config['channel'],
|
|
|
|
'link_names' => true
|
2017-01-25 07:04:29 +03:00
|
|
|
];
|
|
|
|
|
2017-01-25 17:10:24 +03:00
|
|
|
$client = new Client($this->config['slack_url'], $settings);
|
|
|
|
|
2017-02-25 15:00:26 +03:00
|
|
|
$client->send(getlocal('You have a new user waiting for a response. Username: {0}', array($args['thread']->userName)));
|
2017-02-22 02:52:07 +03:00
|
|
|
|
2017-02-25 15:09:08 +03:00
|
|
|
return true;
|
2017-01-25 07:04:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-19 18:28:22 +03:00
|
|
|
* Returns plugin's version.
|
2017-01-25 07:04:29 +03:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function getVersion()
|
|
|
|
{
|
|
|
|
return '1.0.0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns plugin's dependencies.
|
|
|
|
*
|
|
|
|
* @return type
|
|
|
|
*/
|
|
|
|
public static function getDependencies()
|
|
|
|
{
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
}
|