|
1
|
|
|
<?php |
|
2
|
|
|
namespace Sovereign\Plugins\onMessage; |
|
3
|
|
|
|
|
4
|
|
|
use Discord\Discord; |
|
5
|
|
|
use Discord\Parts\Channel\Message; |
|
6
|
|
|
use Monolog\Logger; |
|
7
|
|
|
use Sovereign\Lib\Config; |
|
|
|
|
|
|
8
|
|
|
use Sovereign\Lib\cURL; |
|
9
|
|
|
use Sovereign\Lib\Db; |
|
10
|
|
|
use Sovereign\Lib\Permissions; |
|
11
|
|
|
use Sovereign\Lib\ServerConfig; |
|
12
|
|
|
use Sovereign\Lib\Settings; |
|
13
|
|
|
use Sovereign\Lib\Users; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class cleverBotMessage |
|
17
|
|
|
* @package Sovereign |
|
18
|
|
|
*/ |
|
19
|
|
|
class help extends \Threaded implements \Collectable |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var Message |
|
23
|
|
|
*/ |
|
24
|
|
|
private $message; |
|
25
|
|
|
/** |
|
26
|
|
|
* @var Discord |
|
27
|
|
|
*/ |
|
28
|
|
|
private $discord; |
|
29
|
|
|
/** |
|
30
|
|
|
* @var Logger |
|
31
|
|
|
*/ |
|
32
|
|
|
private $log; |
|
33
|
|
|
/** |
|
34
|
|
|
* @var array |
|
35
|
|
|
*/ |
|
36
|
|
|
private $channelConfig; |
|
37
|
|
|
/** |
|
38
|
|
|
* @var Config |
|
39
|
|
|
*/ |
|
40
|
|
|
private $config; |
|
41
|
|
|
/** |
|
42
|
|
|
* @var Db |
|
43
|
|
|
*/ |
|
44
|
|
|
private $db; |
|
45
|
|
|
/** |
|
46
|
|
|
* @var cURL |
|
47
|
|
|
*/ |
|
48
|
|
|
private $curl; |
|
49
|
|
|
/** |
|
50
|
|
|
* @var Settings |
|
51
|
|
|
*/ |
|
52
|
|
|
private $settings; |
|
53
|
|
|
/** |
|
54
|
|
|
* @var Permissions |
|
55
|
|
|
*/ |
|
56
|
|
|
private $permissions; |
|
57
|
|
|
/** |
|
58
|
|
|
* @var ServerConfig |
|
59
|
|
|
*/ |
|
60
|
|
|
private $serverConfig; |
|
61
|
|
|
/** |
|
62
|
|
|
* @var Users |
|
63
|
|
|
*/ |
|
64
|
|
|
private $users; |
|
65
|
|
|
/** |
|
66
|
|
|
* @var array |
|
67
|
|
|
*/ |
|
68
|
|
|
private $onMessagePlugins; |
|
69
|
|
|
private $onVoicePlugins; |
|
70
|
|
|
|
|
71
|
|
|
public function __construct($message, $discord, $channelConfig, $log, $config, $db, $curl, $settings, $permissions, $serverConfig, $users, $extras) |
|
72
|
|
|
{ |
|
73
|
|
|
$this->message = $message; |
|
74
|
|
|
$this->discord = $discord; |
|
75
|
|
|
$this->channelConfig = $channelConfig; |
|
76
|
|
|
$this->log = $log; |
|
77
|
|
|
$this->config = $config; |
|
78
|
|
|
$this->db = $db; |
|
79
|
|
|
$this->curl = $curl; |
|
80
|
|
|
$this->settings = $settings; |
|
81
|
|
|
$this->permissions = $permissions; |
|
82
|
|
|
$this->serverConfig = $serverConfig; |
|
83
|
|
|
$this->users = $users; |
|
84
|
|
|
$this->onMessagePlugins = $extras["onMessagePlugins"]; |
|
85
|
|
|
$this->onVoicePlugins = $extras["onVoicePlugins"]; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* |
|
90
|
|
|
*/ |
|
91
|
|
|
public function run() |
|
92
|
|
|
{ |
|
93
|
|
|
$explode = explode(" ", $this->message->content); |
|
94
|
|
|
$cmd = isset($explode[1]) ? $explode[1] : null; |
|
95
|
|
|
$plugins = (object)array_merge((array)$this->onMessagePlugins, (array)$this->onVoicePlugins); |
|
96
|
|
|
if (isset($cmd)) { |
|
97
|
|
|
foreach ($plugins as $command => $data) { |
|
98
|
|
|
if ($command == $cmd) { |
|
99
|
|
|
if ($data["usage"]) |
|
100
|
|
|
$this->message->reply("**{$this->channelConfig->prefix}{$command}** _{$data["usage"]}_\r\n {$data["description"]}"); |
|
101
|
|
|
else |
|
102
|
|
|
$this->message->reply("**{$this->channelConfig->prefix}{$command}** \r\n {$data["description"]}"); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
} else { |
|
106
|
|
|
$msg = "**Commands:** \r\n"; |
|
107
|
|
|
foreach ($plugins as $command => $data) { |
|
108
|
|
|
$msg .= "**{$this->channelConfig->prefix}{$command}** | "; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
$this->message->reply($msg); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
} |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: