forked from dmcdaniel12/mibew_slack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plugin.php
81 lines (72 loc) · 2 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?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');
}
/**
* Initializer
* @return boolean
*/
public function initialized()
{
return true;
}
/**
* This creates the listener that listens for new
* threads to send out slack notifications
*/
public function run()
{
$dispatcher = EventDispatcher::getInstance();
$dispatcher->attachListener(Events::THREAD_CREATE, $this, 'sendSlackNotification');
}
/**
* Sends notification to slack.
* Sends the date with the username as well
* @return boolean
*/
public function sendSlackNotification(&$args)
{
$settings = [
'username' => $this->config['username'],
'channel' => '#' . $this->config['channel'],
'link_names' => true
];
$client = new Client($this->config['slack_url'], $settings);
$client->send(getlocal('You have a new user waiting for a response. Username: {0}', array($args['thread']->userName)));
return true;
}
/**
* Returns plugin's version.
*
* @return string
*/
public static function getVersion()
{
return '1.0.0';
}
/**
* Returns plugin's dependencies.
*
* @return type
*/
public static function getDependencies()
{
return array();
}
}