|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* The MIT License (MIT) |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) 2016 Robert Sardinia |
|
6
|
|
|
* |
|
7
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
9
|
|
|
* in the Software without restriction, including without limitation the rights |
|
10
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
11
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
12
|
|
|
* furnished to do so, subject to the following conditions: |
|
13
|
|
|
* |
|
14
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
15
|
|
|
* copies or substantial portions of the Software. |
|
16
|
|
|
* |
|
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
18
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
19
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
20
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
21
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
22
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
23
|
|
|
* SOFTWARE. |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Class about |
|
28
|
|
|
*/ |
|
29
|
|
|
class about |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
public $config; |
|
32
|
|
|
public $discord; |
|
33
|
|
|
public $logger; |
|
34
|
|
|
public $message; |
|
35
|
|
|
private $excludeChannel; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param $config |
|
39
|
|
|
* @param $discord |
|
40
|
|
|
* @param $logger |
|
41
|
|
|
* @internal param $message |
|
42
|
|
|
*/ |
|
43
|
|
View Code Duplication |
public function init($config, $discord, $logger) |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
|
|
$this->config = $config; |
|
46
|
|
|
$this->discord = $discord; |
|
47
|
|
|
$this->logger = $logger; |
|
48
|
|
|
$this->excludeChannel = $this->config['bot']['restrictedChannels']; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param $msgData |
|
53
|
|
|
* @param $message |
|
54
|
|
|
* @return null |
|
55
|
|
|
*/ |
|
56
|
|
|
public function onMessage($msgData, $message) |
|
57
|
|
|
{ |
|
58
|
|
|
$this->message = $message; |
|
59
|
|
|
$info['guilds'] = $this->discord->guilds->count(); |
|
|
|
|
|
|
60
|
|
|
$channelID = (int) $msgData['message']['channelID']; |
|
61
|
|
|
|
|
62
|
|
|
if (in_array($channelID, $this->excludeChannel, true)) |
|
63
|
|
|
{ |
|
64
|
|
|
return null; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
global $startTime; // Get the starttime of the bot |
|
|
|
|
|
|
68
|
|
|
$time1 = new DateTime(date('Y-m-d H:i:s', $startTime)); |
|
69
|
|
|
$time2 = new DateTime(date('Y-m-d H:i:s')); |
|
70
|
|
|
$interval = $time1->diff($time2); |
|
71
|
|
|
|
|
72
|
|
|
$botID = $this->discord->id; |
|
73
|
|
|
|
|
74
|
|
|
$message = $msgData['message']['message']; |
|
75
|
|
|
$user = $msgData['message']['from']; |
|
76
|
|
|
|
|
77
|
|
|
$data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']); |
|
78
|
|
|
if (isset($data['trigger'])) { |
|
79
|
|
|
$gitRevision = gitRevision(); |
|
80
|
|
|
$gitBranch = gitBranch(); |
|
81
|
|
|
$msg = '``` |
|
82
|
|
|
Developer: Shibdib (In-game Name: Mr Twinkie) |
|
83
|
|
|
|
|
84
|
|
|
Bot ID: ' . $botID . ' |
|
85
|
|
|
|
|
86
|
|
|
Current Version: ' . $gitRevision['short'] . ' |
|
87
|
|
|
Current Branch: ' . $gitBranch . " |
|
88
|
|
|
Github Repo: https://github.com/shibdib/Dramiel |
|
89
|
|
|
|
|
90
|
|
|
Statistics: |
|
91
|
|
|
Currently on {$info['guilds']} different discord servers. |
|
92
|
|
|
Up-time: " . $interval->y . ' Year(s), ' . $interval->m . ' Month(s), ' . $interval->d . ' Days, ' . $interval->h . ' Hours, ' . $interval->i . ' Minutes, ' . $interval->s . ' seconds. |
|
93
|
|
|
Memory Usage: ~' . round(memory_get_usage() / 1024 / 1024, 3) . 'MB```'; |
|
94
|
|
|
$this->logger->addInfo("About: Sending about info to {$user}"); |
|
95
|
|
|
$this->message->reply($msg); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @return array |
|
101
|
|
|
*/ |
|
102
|
|
|
public function information() |
|
103
|
|
|
{ |
|
104
|
|
|
return array( |
|
105
|
|
|
'name' => 'about', |
|
106
|
|
|
'trigger' => array($this->config['bot']['trigger'] . 'about'), |
|
107
|
|
|
'information' => "Shows information on the bot, who created it, what library it's using, revision, and other stats. Example: !about" |
|
108
|
|
|
); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.