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
|
|
|
use Discord\Parts\User\Game; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @property message |
30
|
|
|
*/ |
31
|
|
|
class setGame |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
public $config; |
34
|
|
|
public $discord; |
35
|
|
|
public $logger; |
36
|
|
|
public $message; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param $config |
40
|
|
|
* @param $discord |
41
|
|
|
* @param $logger |
42
|
|
|
*/ |
43
|
|
|
public function init($config, $discord, $logger) |
44
|
|
|
{ |
45
|
|
|
$this->config = $config; |
46
|
|
|
$this->discord = $discord; |
47
|
|
|
$this->logger = $logger; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param $msgData |
52
|
|
|
* @param $message |
53
|
|
|
* @return null |
54
|
|
|
*/ |
55
|
|
|
public function onMessage($msgData, $message) |
56
|
|
|
{ |
57
|
|
|
$this->message = $message; |
58
|
|
|
|
59
|
|
|
$message = $msgData['message']['message']; |
60
|
|
|
|
61
|
|
|
$data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']); |
62
|
|
|
if (isset($data['trigger'])) { |
63
|
|
|
|
64
|
|
|
//Admin Check |
65
|
|
|
$userID = $msgData['message']['fromID']; |
66
|
|
|
$adminRoles = $this->config['bot']['adminRoles']; |
67
|
|
|
$adminRoles = array_map('strtolower', $adminRoles); |
68
|
|
|
$id = $this->config['bot']['guild']; |
69
|
|
|
$guild = $this->discord->guilds->get('id', $id); |
70
|
|
|
$member = $guild->members->get('id', $userID); |
71
|
|
|
$roles = $member->roles; |
72
|
|
|
foreach ($roles as $role) { |
73
|
|
|
if (in_array(strtolower($role->name), $adminRoles, true)) { |
74
|
|
|
$newGame = (string) $data['messageString']; |
75
|
|
|
$game = $this->discord->factory(Game::class, [ |
76
|
|
|
'name' => $newGame, |
77
|
|
|
]); |
78
|
|
|
$this->discord->updatePresence($game); |
79
|
|
|
setPermCache('botGame', $newGame); |
80
|
|
|
|
81
|
|
|
$msg = "Bot is now playing **{$newGame}**"; |
82
|
|
|
$this->logger->addInfo("setGame: Bot game changed to {$newGame} by {$msgData['message']['from']}"); |
83
|
|
|
$this->message->reply($msg); |
84
|
|
|
return null; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
$this->logger->addInfo("setGame: {$msgData['message']['from']} attempted to change the bot's game."); |
88
|
|
|
$msg = ':bangbang: You do not have the necessary roles to issue this command :bangbang:'; |
89
|
|
|
$this->message->reply($msg); |
90
|
|
|
return null; |
91
|
|
|
} |
92
|
|
|
return null; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return array |
97
|
|
|
*/ |
98
|
|
View Code Duplication |
public function information() |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
return array( |
101
|
|
|
'name' => 'game', |
102
|
|
|
'trigger' => array($this->config['bot']['trigger'] . 'game'), |
103
|
|
|
'information' => 'Changes the bots game **(Admin Role Required)**' |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
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.