Skip to content

Commit 9b856b1

Browse files
committed
Replaced Ops
Moved Settings.php Removed unnecessary files Renamed a someone files Removed $permissions param from createChannel()
1 parent 2118a83 commit 9b856b1

29 files changed

Lines changed: 304 additions & 481 deletions

src/Bot.php

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
use Ourted\Interfaces\User;
1212
use Ourted\Interfaces\Webhook;
1313
use Ourted\Model\Channel\Embed;
14-
use Ourted\Utils\API;
15-
use Ourted\Utils\Settings;
14+
use Ourted\Utils\getaway;
15+
use Ourted\Utils\http;
16+
use Ourted\Interfaces\Settings;
1617
use Ratchet\Client\Connector;
1718
use Ratchet\Client\WebSocket;
1819
use Ratchet\RFC6455\Messaging\MessageInterface;
@@ -22,55 +23,55 @@ class Bot
2223
{
2324

2425

25-
public $CREATE_INSTANT_INVITE = 0x00000001;
26-
public $KICK_MEMBERS = 0x00000002;
27-
public $BAN_MEMBERS = 0x00000004;
28-
public $ADMINISTRATOR = 0x00000008;
29-
public $MANAGE_CHANNELS = 0x00000010;
30-
public $MANAGE_GUILD = 0x00000020;
31-
public $ADD_REACTIONS = 0x00000040;
32-
public $VIEW_AUDIT_LOG = 0x00000080;
33-
public $PRIORITY_SPEAKER = 0x00000100;
34-
public $STREAM = 0x00000200;
35-
public $VIEW_CHANNEL = 0x00000400;
36-
public $SEND_MESSAGES = 0x00000800;
37-
public $SEND_TTS_MESSAGES = 0x00001000;
38-
public $MANAGE_MESSAGES = 0x00002000;
39-
public $EMBED_LINKS = 0x00004000;
40-
public $ATTACH_FILES = 0x00008000;
41-
public $READ_MESSAGE_HISTORY = 0x00010000;
42-
public $MENTION_EVERYONE = 0x00020000;
43-
public $USE_EXTERNAL_EMOJIS = 0x00040000;
44-
public $VIEW_GUILD_INSIGHTS = 0x00080000;
45-
public $CONNECT = 0x00100000;
46-
public $SPEAK = 0x00200000;
47-
public $MUTE_MEMBERS = 0x00400000;
48-
public $DEAFEN_MEMBERS = 0x00800000;
49-
public $MOVE_MEMBERS = 0x01000000;
50-
public $USE_VAD = 0x02000000;
51-
public $CHANGE_NICKNAME = 0x04000000;
52-
public $MANAGE_NICKNAMES = 0x08000000;
53-
public $MANAGE_ROLES = 0x10000000;
54-
public $MANAGE_WEBHOOKS = 0x20000000;
55-
public $MANAGE_EMOJIS = 0x40000000;
56-
57-
public $GUILD_TEXT = 0;
58-
public $DM = 1;
59-
public $GUILD_VOICE = 2;
60-
public $GROUP_DM = 3;
61-
public $GUILD_NEWS = 4;
62-
public $GUILD_STORE = 5;
26+
public $PERMISSION_CREATE_INSTANT_INVITE = 0x00000001;
27+
public $PERMISSION_KICK_MEMBERS = 0x00000002;
28+
public $PERMISSION_BAN_MEMBERS = 0x00000004;
29+
public $PERMISSION_ADMINISTRATOR = 0x00000008;
30+
public $PERMISSION_MANAGE_CHANNELS = 0x00000010;
31+
public $PERMISSION_MANAGE_GUILD = 0x00000020;
32+
public $PERMISSION_ADD_REACTIONS = 0x00000040;
33+
public $PERMISSION_VIEW_AUDIT_LOG = 0x00000080;
34+
public $PERMISSION_PRIORITY_SPEAKER = 0x00000100;
35+
public $PERMISSION_STREAM = 0x00000200;
36+
public $PERMISSION_VIEW_CHANNEL = 0x00000400;
37+
public $PERMISSION_SEND_MESSAGES = 0x00000800;
38+
public $PERMISSION_SEND_TTS_MESSAGES = 0x00001000;
39+
public $PERMISSION_MANAGE_MESSAGES = 0x00002000;
40+
public $PERMISSION_EMBED_LINKS = 0x00004000;
41+
public $PERMISSION_ATTACH_FILES = 0x00008000;
42+
public $PERMISSION_READ_MESSAGE_HISTORY = 0x00010000;
43+
public $PERMISSION_MENTION_EVERYONE = 0x00020000;
44+
public $PERMISSION_USE_EXTERNAL_EMOJIS = 0x00040000;
45+
public $PERMISSION_VIEW_GUILD_INSIGHTS = 0x00080000;
46+
public $PERMISSION_CONNECT = 0x00100000;
47+
public $PERMISSION_SPEAK = 0x00200000;
48+
public $PERMISSION_MUTE_MEMBERS = 0x00400000;
49+
public $PERMISSION_DEAFEN_MEMBERS = 0x00800000;
50+
public $PERMISSION_MOVE_MEMBERS = 0x01000000;
51+
public $PERMISSION_USE_VAD = 0x02000000;
52+
public $PERMISSION_CHANGE_NICKNAME = 0x04000000;
53+
public $PERMISSION_MANAGE_NICKNAMES = 0x08000000;
54+
public $PERMISSION_MANAGE_ROLES = 0x10000000;
55+
public $PERMISSION_MANAGE_WEBHOOKS = 0x20000000;
56+
public $PERMISSION_MANAGE_EMOJIS = 0x40000000;
57+
58+
public $CHANNEL_CHANNEL_GUILD_TEXT = 0;
59+
public $CHANNEL_DM = 1;
60+
public $CHANNEL_GUILD_VOICE = 2;
61+
public $CHANNEL_GROUP_DM = 3;
62+
public $CHANNEL_GUILD_NEWS = 4;
63+
public $CHANNEL_GUILD_STORE = 5;
6364

6465
public $GAME_LISTEN = 2;
6566
public $GAME_WATCHING = 1;
6667
public $GAME_PLAYING = 0;
6768

6869

6970
/**
70-
* State
71-
* @var State
71+
* Getaway
72+
* @var getaway
7273
*/
73-
public $state;
74+
public $getaway;
7475
/**
7576
* Functions
7677
* @var Settings Instance
@@ -90,7 +91,7 @@ class Bot
9091
* @var bool
9192
*/
9293
public $send_log = false;
93-
/** @var API */
94+
/** @var http */
9495
public $api;
9596
/** @var Channel */
9697
public $channel;
@@ -169,7 +170,7 @@ public function __construct($botToken, $botPrefix, $wssUrl = null)
169170
$this->invite = new Invite($this);
170171
$this->guild = new Guild($this);
171172
$this->user = new User($this);
172-
$this->api = new API($this);
173+
$this->api = new http($this);
173174

174175
$this->loop = Factory::create();
175176
$this->init();
@@ -183,17 +184,17 @@ public function init()
183184
$connector = new Connector($this->loop, new \React\Socket\Connector($this->loop));
184185
$connector($this->wssUrl)->then(function (WebSocket $conn) {
185186
$this->connection = $conn;
186-
$this->state = $state = new State($conn, $this->loop, $this->token);
187-
$this->state->send_log = $this->send_log;
188-
$state->addDispatch($this->dispatch);
187+
$this->getaway = $getaway = new getaway($conn, $this->loop, $this->token);
188+
$this->getaway->send_log = $this->send_log;
189+
$getaway->addDispatch($this->dispatch);
189190

190191

191-
$conn->on('message', function (MessageInterface $msg) use ($conn, $state) {
192+
$conn->on('message', function (MessageInterface $msg) use ($conn, $getaway) {
192193
$json = json_decode($msg);
193194
if (isset($json->d->session_id)) {
194195
$this->session_id = $json->d->session_id;
195196
}
196-
$state->action($json, $this->loop);
197+
$getaway->action($json);
197198
});
198199

199200

src/Interfaces/Channel.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function getChannel($channel_id){
2828
*/
2929

3030
public function sendMessage($message, $channel){
31-
$this->bot->api->init_curl_with_header(
31+
$this->bot->api->send(
3232
"channels/{$channel->id}/messages",
3333
"{\"content\":\"{$message}\"}");
3434
}
@@ -42,7 +42,7 @@ public function sendMessage($message, $channel){
4242

4343
public function deleteMessage($message)
4444
{
45-
return $this->bot->api->init_curl_with_header(
45+
return $this->bot->api->send(
4646
"channels/{$message->channel_id}/messages/{$message->id}",
4747
"", "DELETE");
4848
}
@@ -57,7 +57,7 @@ public function deleteMessage($message)
5757

5858
public function deleteBulkMessage($message, $channel)
5959
{
60-
return json_decode($this->bot->api->init_curl_with_header(
60+
return json_decode($this->bot->api->send(
6161
"channels/{$channel->id}/messages/bulk-delete",
6262
"{\"messages\":{$message}}", "POST"));
6363
}
@@ -72,7 +72,7 @@ public function deleteBulkMessage($message, $channel)
7272

7373
public function getMessages($channel, $limit = 50)
7474
{
75-
return json_decode($this->bot->api->init_curl_with_header(
75+
return json_decode($this->bot->api->send(
7676
"channels/{$channel->id}/messages?limit={$limit}",
7777
"", "GET"));
7878
}
@@ -96,7 +96,7 @@ public function getMessage($channel, $message_id)
9696
* @return mixed
9797
*/
9898
public function deleteChannel($channel){
99-
return json_decode($this->bot->api->init_curl_with_header("channels/{$channel->id}","", "DELETE"));
99+
return json_decode($this->bot->api->send("channels/{$channel->id}","", "DELETE"));
100100
}
101101

102102
}

src/Interfaces/Emoji.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct($bot)
2121
*/
2222
public function getEmojis($guild)
2323
{
24-
return json_decode($this->bot->api->init_curl_with_header(
24+
return json_decode($this->bot->api->send(
2525
"guilds/{$guild->id}/emojis",
2626
"", "GET"));
2727
}
@@ -34,7 +34,7 @@ public function getEmojis($guild)
3434
*/
3535
public function createEmoji($guild, $name, $image)
3636
{
37-
return $this->getEmoji($guild, json_decode($this->bot->api->init_curl_with_header(
37+
return $this->getEmoji($guild, json_decode($this->bot->api->send(
3838
"guilds/{$guild->id}/emojis",
3939
"{\"name\":\"{$name}\",\"image\":\"{$image}\",\"roles\":\"[]\"}"))->id);
4040
}
@@ -56,7 +56,7 @@ public function getEmoji($guild, $emoji_id)
5656
*/
5757
public function deleteEmoji($guild, $emoji)
5858
{
59-
return $this->getEmoji($guild, json_decode($this->bot->api->init_curl_with_header(
59+
return $this->getEmoji($guild, json_decode($this->bot->api->send(
6060
"guilds/{$guild->id}/emojis/{$emoji->id}",
6161
"", "DELETE"))->id);
6262
}

src/Interfaces/Guild.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct($bot)
2626

2727
public function get_guilds_properties()
2828
{
29-
return json_decode($this->bot->api->init_curl_with_header(
29+
return json_decode($this->bot->api->send(
3030
"users/@me/guilds",
3131
"", "GET"));
3232
}
@@ -65,7 +65,7 @@ public function getRoles($guild)
6565
*/
6666
public function getChannels($guild)
6767
{
68-
return json_decode($this->bot->api->init_curl_with_header("guilds/{$guild->id}/channels", "", "GET"));
68+
return json_decode($this->bot->api->send("guilds/{$guild->id}/channels", "", "GET"));
6969
}
7070

7171
/**
@@ -75,7 +75,7 @@ public function getChannels($guild)
7575
*/
7676
public function getPrune($guild)
7777
{
78-
return json_decode($this->bot->api->init_curl_with_header("guilds/{$guild->id}/prunes", "", "GET"));
78+
return json_decode($this->bot->api->send("guilds/{$guild->id}/prunes", "", "GET"));
7979
}
8080

8181
/**
@@ -85,7 +85,7 @@ public function getPrune($guild)
8585
*/
8686
public function getInvites($guild)
8787
{
88-
return json_decode($this->bot->api->init_curl_with_header("guilds/{$guild->id}/invites", "", "GET"));
88+
return json_decode($this->bot->api->send("guilds/{$guild->id}/invites", "", "GET"));
8989
}
9090

9191

@@ -111,7 +111,7 @@ public function getIntegrations($guild)
111111
*/
112112
public function addRole($guild, $role_name, $color, $mentionable, $hoist)
113113
{
114-
$result = json_decode($this->bot->api->init_curl_with_header("guilds/{$guild->id}/roles", "{\"name\":\"{$role_name}\", \"color\":\"{$color}\", \"hoist\":{$hoist}, \"mentionable\":{$mentionable}}", "POST"));
114+
$result = json_decode($this->bot->api->send("guilds/{$guild->id}/roles", "{\"name\":\"{$role_name}\", \"color\":\"{$color}\", \"hoist\":{$hoist}, \"mentionable\":{$mentionable}}", "POST"));
115115
return new Role($this->bot, $guild, $result->id);
116116
}
117117

@@ -126,7 +126,7 @@ public function addRole($guild, $role_name, $color, $mentionable, $hoist)
126126
*/
127127
public function modifyRole($guild, $role_name = null, $color = null, $mentionable = null, $hoist = null)
128128
{
129-
$result = json_decode($this->bot->api->init_curl_with_header("guilds/{$guild->id}/roles", "{\"name\":\"{$role_name}\", \"color\":\"{$color}\", \"hoist\":{$hoist}, \"mentionable\":{$mentionable}}", "PATCH"));
129+
$result = json_decode($this->bot->api->send("guilds/{$guild->id}/roles", "{\"name\":\"{$role_name}\", \"color\":\"{$color}\", \"hoist\":{$hoist}, \"mentionable\":{$mentionable}}", "PATCH"));
130130
return new Role($this->bot, $guild, $result->id);
131131
}
132132

@@ -138,7 +138,7 @@ public function modifyRole($guild, $role_name = null, $color = null, $mentionabl
138138
*/
139139
public function deleteRole($guild, $role_id)
140140
{
141-
$result = json_decode($this->bot->api->init_curl_with_header("guilds/{$guild->id}/roles/{$role_id}", "", "DELETE"));
141+
$result = json_decode($this->bot->api->send("guilds/{$guild->id}/roles/{$role_id}", "", "DELETE"));
142142
return new Role($this->bot, $guild, $result->id);
143143
}
144144

@@ -157,13 +157,13 @@ public function deleteRole($guild, $role_id)
157157
* @param bool
158158
* @return \Ourted\Model\Channel\Channel
159159
*/
160-
public function createChannel($guild, $channel_name, $type = 0, $topic = "", $permissions = null, $bitrate = null, $user_limit = null, $rate_limit_per_user = null, $position = null, $parent_id = null)
160+
public function createChannel($guild, $channel_name, $type = 0, $topic = "", $bitrate = null, $user_limit = null, $rate_limit_per_user = null, $position = null, $parent_id = null)
161161
{
162162
$field = "";
163163
$field .= "\"name\": \"$channel_name\"";
164164
$field .= ",\"type\": $type";
165165
$field .= ",\"topic\": \"{$topic}\"";
166-
if (!is_null($permissions)) {
166+
/*if (!is_null($permissions)) {
167167
if (isset($permissions[0])) {
168168
$__permissions = '';
169169
foreach ($permissions as $key => $item) {
@@ -175,14 +175,14 @@ public function createChannel($guild, $channel_name, $type = 0, $topic = "", $pe
175175
}
176176
$field .= ",\"permissions\": [{$__permissions}]";
177177
}
178-
}
178+
}*/
179179
if (!is_null($bitrate)) {
180-
if ($type == $this->bot->GUILD_VOICE) {
180+
if ($type == $this->bot->CHANNEL_GUILD_VOICE) {
181181
$field .= ",\"bitrate\":{$bitrate} ";
182182
}
183183
}
184184
if (!is_null($user_limit)) {
185-
if ($type == $this->bot->GUILD_VOICE) {
185+
if ($type == $this->bot->CHANNEL_GUILD_VOICE) {
186186
$field .= ",\"user_limit\": {$user_limit}";
187187
}
188188
}
@@ -195,7 +195,7 @@ public function createChannel($guild, $channel_name, $type = 0, $topic = "", $pe
195195
if (!is_null($parent_id)) {
196196
$field .= ",\"parent_id\": {$parent_id}";
197197
}
198-
$result = json_decode($this->bot->api->init_curl_with_header(
198+
$result = json_decode($this->bot->api->send(
199199
"guilds/{$guild->id}/channels", "
200200
{{$field}}", "POST"));
201201
return new \Ourted\Model\Channel\Channel($this->bot, $result->id);
@@ -210,7 +210,7 @@ public function createChannel($guild, $channel_name, $type = 0, $topic = "", $pe
210210
*/
211211
public function changeChannelPosition($guild, $channel, $position)
212212
{
213-
$result = json_decode($this->bot->api->init_curl_with_header("guilds/{$guild->id}/channels", "{\"id\":{$channel->id}, \"position\":{$position}}", "PATCH"));
213+
$result = json_decode($this->bot->api->send("guilds/{$guild->id}/channels", "{\"id\":{$channel->id}, \"position\":{$position}}", "PATCH"));
214214
return new \Ourted\Model\Channel\Channel($this->bot, $result->id);
215215
}
216216
}

0 commit comments

Comments
 (0)