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