|
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
|
|
|
namespace Nickname;
|
|
27
|
|
|
|
|
28
|
|
|
/**
|
|
29
|
|
|
* @property message
|
|
30
|
|
|
*/
|
|
31
|
|
|
class setNickname
|
|
32
|
|
|
{
|
|
33
|
|
|
/**
|
|
34
|
|
|
* @var
|
|
35
|
|
|
*/
|
|
36
|
|
|
var $config;
|
|
|
|
|
|
|
37
|
|
|
/**
|
|
38
|
|
|
* @var
|
|
39
|
|
|
*/
|
|
40
|
|
|
var $discord;
|
|
|
|
|
|
|
41
|
|
|
/**
|
|
42
|
|
|
* @var
|
|
43
|
|
|
*/
|
|
44
|
|
|
var $logger;
|
|
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
public $message;
|
|
47
|
|
|
|
|
48
|
|
|
/**
|
|
49
|
|
|
* @param $config
|
|
50
|
|
|
* @param $discord
|
|
51
|
|
|
* @param $logger
|
|
52
|
|
|
*/
|
|
53
|
|
|
function init($config, $discord, $logger)
|
|
|
|
|
|
|
54
|
|
|
{
|
|
55
|
|
|
$this->config = $config;
|
|
56
|
|
|
$this->discord = $discord;
|
|
57
|
|
|
$this->logger = $logger;
|
|
58
|
|
|
}
|
|
59
|
|
|
|
|
60
|
|
|
/**
|
|
61
|
|
|
*
|
|
62
|
|
|
*/
|
|
63
|
|
|
function tick()
|
|
|
|
|
|
|
64
|
|
|
{
|
|
65
|
|
|
}
|
|
66
|
|
|
|
|
67
|
|
|
/**
|
|
68
|
|
|
* @param $msgData
|
|
69
|
|
|
* @param $message
|
|
70
|
|
|
* @return null
|
|
71
|
|
|
*/
|
|
72
|
|
|
function onMessage($msgData, $message)
|
|
|
|
|
|
|
73
|
|
|
{
|
|
74
|
|
|
$this->message = $message;
|
|
75
|
|
|
|
|
76
|
|
|
$message = $msgData["message"]["message"];
|
|
77
|
|
|
|
|
78
|
|
|
$data = command($message, $this->information()["trigger"], $this->config["bot"]["trigger"]);
|
|
79
|
|
|
if (isset($data["trigger"])) {
|
|
80
|
|
|
|
|
81
|
|
|
//Admin Check
|
|
82
|
|
|
$botID = $this->discord->id;
|
|
83
|
|
|
$userID = $msgData["message"]["fromID"];
|
|
84
|
|
|
$adminRoles = $this->config["bot"]["adminRoles"];
|
|
85
|
|
|
$id = $this->config["bot"]["guild"];
|
|
86
|
|
|
$guild = $this->discord->guilds->get('id', $id);
|
|
87
|
|
|
$member = $guild->members->get("id", $userID);
|
|
88
|
|
|
$roles = $member->roles;
|
|
89
|
|
|
foreach ($roles as $role) {
|
|
90
|
|
|
if (in_array($role->name, $adminRoles, true)) {
|
|
91
|
|
|
$member = $guild->members->get("id", $botID);
|
|
92
|
|
|
$nick = (string) $data["messageString"];
|
|
93
|
|
|
$member->setNickname($nick);
|
|
94
|
|
|
|
|
95
|
|
|
$msg = "Bot nickname changed to **{$nick}** by {$msgData["message"]["from"]}";
|
|
96
|
|
|
$this->logger->addInfo("Bot nickname changed to {$nick} by {$msgData["message"]["from"]}");
|
|
97
|
|
|
$this->message->reply($msg);
|
|
98
|
|
|
return null;
|
|
99
|
|
|
}
|
|
100
|
|
|
}
|
|
101
|
|
|
$msg = ":bangbang: You do not have the necessary roles to issue this command :bangbang:";
|
|
102
|
|
|
$this->message->reply($msg);
|
|
103
|
|
|
return null;
|
|
104
|
|
|
}
|
|
105
|
|
|
return null;
|
|
106
|
|
|
}
|
|
107
|
|
|
|
|
108
|
|
|
/**
|
|
109
|
|
|
* @return array
|
|
110
|
|
|
*/
|
|
111
|
|
View Code Duplication |
function information()
|
|
|
|
|
|
|
112
|
|
|
{
|
|
113
|
|
|
return array(
|
|
114
|
|
|
"name" => "nickname",
|
|
115
|
|
|
"trigger" => array($this->config["bot"]["trigger"] . "nickname"),
|
|
116
|
|
|
"information" => "Changes the bots nickname (Admin Role)"
|
|
117
|
|
|
);
|
|
118
|
|
|
}
|
|
119
|
|
|
|
|
120
|
|
|
/**
|
|
121
|
|
|
* @param $msgData
|
|
122
|
|
|
* @param $message
|
|
123
|
|
|
*/
|
|
124
|
|
|
function onMessageAdmin()
|
|
|
|
|
|
|
125
|
|
|
{
|
|
126
|
|
|
}
|
|
127
|
|
|
|
|
128
|
|
|
}
|
|
129
|
|
|
|
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.