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
|
|
|
private $triggers; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param $config |
40
|
|
|
* @param $discord |
41
|
|
|
* @param $logger |
42
|
|
|
* @internal param $message |
43
|
|
|
*/ |
44
|
|
View Code Duplication |
public function init($config, $discord, $logger) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$this->config = $config; |
47
|
|
|
$this->discord = $discord; |
48
|
|
|
$this->logger = $logger; |
49
|
|
|
$this->excludeChannel = $this->config['bot']['restrictedChannels']; |
50
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'about'; |
51
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'About'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param $msgData |
56
|
|
|
* @param $message |
57
|
|
|
* @return null |
58
|
|
|
*/ |
59
|
|
|
public function onMessage($msgData, $message) |
60
|
|
|
{ |
61
|
|
|
$this->message = $message; |
62
|
|
|
$info['guilds'] = $this->discord->guilds->count(); |
|
|
|
|
63
|
|
|
$channelID = (int) $msgData['message']['channelID']; |
64
|
|
|
|
65
|
|
|
if (in_array($channelID, $this->excludeChannel, true)) |
66
|
|
|
{ |
67
|
|
|
return null; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
global $startTime; // Get the starttime of the bot |
|
|
|
|
71
|
|
|
$time1 = new DateTime(date('Y-m-d H:i:s', $startTime)); |
72
|
|
|
$time2 = new DateTime(date('Y-m-d H:i:s')); |
73
|
|
|
$interval = $time1->diff($time2); |
74
|
|
|
|
75
|
|
|
$botID = $this->discord->id; |
76
|
|
|
|
77
|
|
|
$message = $msgData['message']['message']; |
78
|
|
|
$user = $msgData['message']['from']; |
79
|
|
|
|
80
|
|
|
$data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']); |
81
|
|
|
if (isset($data['trigger'])) { |
82
|
|
|
$gitRevision = gitRevision(); |
83
|
|
|
$gitBranch = gitBranch(); |
84
|
|
|
$msg = '``` |
85
|
|
|
Developer: Shibdib (In-game Name: Mr Twinkie) |
86
|
|
|
|
87
|
|
|
Bot ID: ' . $botID . ' |
88
|
|
|
|
89
|
|
|
Current Version: ' . $gitRevision['short'] . ' |
90
|
|
|
Current Branch: ' . $gitBranch . " |
91
|
|
|
Github Repo: https://github.com/shibdib/Dramiel |
92
|
|
|
|
93
|
|
|
Statistics: |
94
|
|
|
Currently on {$info['guilds']} different discord servers. |
95
|
|
|
Up-time: " . $interval->y . ' Year(s), ' . $interval->m . ' Month(s), ' . $interval->d . ' Days, ' . $interval->h . ' Hours, ' . $interval->i . ' Minutes, ' . $interval->s . ' seconds. |
96
|
|
|
Memory Usage: ~' . round(memory_get_usage() / 1024 / 1024, 3) . 'MB```'; |
97
|
|
|
$this->logger->addInfo("About: Sending about info to {$user}"); |
98
|
|
|
$this->message->reply($msg); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return array |
104
|
|
|
*/ |
105
|
|
|
public function information() |
106
|
|
|
{ |
107
|
|
|
return array( |
108
|
|
|
'name' => 'about', |
109
|
|
|
'trigger' => $this->triggers, |
110
|
|
|
'information' => "Shows information on the bot, who created it, what library it's using, revision, and other stats. Example: !about" |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
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.