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
|
|
|
/** |
28
|
|
|
* @property message |
29
|
|
|
*/ |
30
|
|
|
class getLog |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @var |
34
|
|
|
*/ |
35
|
|
|
public $config; |
36
|
|
|
public $discord; |
37
|
|
|
public $logger; |
38
|
|
|
public $message; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param $config |
42
|
|
|
* @param $discord |
43
|
|
|
* @param $logger |
44
|
|
|
*/ |
45
|
|
|
public function init($config, $discord, $logger) |
46
|
|
|
{ |
47
|
|
|
$this->config = $config; |
48
|
|
|
$this->discord = $discord; |
49
|
|
|
$this->logger = $logger; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param $msgData |
54
|
|
|
* @param $message |
55
|
|
|
* @return null |
56
|
|
|
*/ |
57
|
|
|
public function onMessage($msgData, $message) |
58
|
|
|
{ |
59
|
|
|
$this->message = $message; |
60
|
|
|
|
61
|
|
|
$message = $msgData['message']['message']; |
62
|
|
|
|
63
|
|
|
$data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']); |
64
|
|
|
if (isset($data['trigger'])) { |
65
|
|
|
|
66
|
|
|
//Admin Check |
67
|
|
|
$userID = $msgData['message']['fromID']; |
68
|
|
|
$adminRoles = $this->config['bot']['adminRoles']; |
69
|
|
|
$adminRoles = array_map('strtolower', $adminRoles); |
70
|
|
|
$id = $this->config['bot']['guild']; |
71
|
|
|
$guild = $this->discord->guilds->get('id', $id); |
72
|
|
|
$member = $guild->members->get('id', $userID); |
73
|
|
|
$roles = $member->roles; |
74
|
|
|
foreach ($roles as $role) { |
75
|
|
|
if (in_array(strtolower($role->name), $adminRoles, true)) { |
76
|
|
|
$logType = (string) $data['messageString']; |
77
|
|
|
if ($logType === 'log') { |
78
|
|
|
$filePath = __DIR__ . '/../../../log/dramielLog.log'; |
79
|
|
|
$title = "dramielLog - from userID {$userID}"; |
80
|
|
|
} elseif ($logType === 'error') { |
81
|
|
|
$filePath = __DIR__ . '/../../../log/dramielError.log'; |
82
|
|
|
$title = "dramielError - from userID {$userID}"; |
83
|
|
|
} elseif ($logType === 'other') { |
84
|
|
|
$filePath = __DIR__ . '/../../../log/dramielOther.log'; |
85
|
|
|
$title = "dramielOther - from userID {$userID}"; |
86
|
|
|
} else { |
87
|
|
|
$msg = 'Incorrect log selected. Use either log, error, other'; |
88
|
|
|
$this->message->reply($msg); |
89
|
|
|
return null; |
90
|
|
|
} |
91
|
|
|
$logContents = tailCustom($filePath, 100); |
92
|
|
|
$pasteURL = pasteLog($logContents, $title); |
93
|
|
|
|
94
|
|
|
$this->message->reply($pasteURL); |
95
|
|
|
return null; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
$msg = ':bangbang: You do not have the necessary roles to issue this command :bangbang:'; |
99
|
|
|
$this->message->reply($msg); |
100
|
|
|
return null; |
101
|
|
|
} |
102
|
|
|
return null; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return array |
107
|
|
|
*/ |
108
|
|
View Code Duplication |
public function information() |
|
|
|
|
109
|
|
|
{ |
110
|
|
|
return array( |
111
|
|
|
'name' => 'log', |
112
|
|
|
'trigger' => array($this->config['bot']['trigger'] . 'log'), |
113
|
|
|
'information' => 'Get a pastebin of the last 100 lines of your log files. Follow command with either log, error, other **(Admin Role Required)**' |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
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.