Skip to content

Commit 677e9be

Browse files
committed
Added Permission Property
1 parent 9b856b1 commit 677e9be

File tree

5 files changed

+78
-20
lines changed

5 files changed

+78
-20
lines changed

src/Bot.php

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Ratchet\RFC6455\Messaging\MessageInterface;
2020
use React\EventLoop\Factory;
2121

22+
2223
class Bot
2324
{
2425

@@ -66,6 +67,8 @@ class Bot
6667
public $GAME_WATCHING = 1;
6768
public $GAME_PLAYING = 0;
6869

70+
public $OVERWRITE_TYPE_ROLE = 0;
71+
public $OVERWRITE_TYPE_MEMBER = 1;
6972

7073
/**
7174
* Getaway

src/Interfaces/Channel.php

+28-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
use Ourted\Bot;
66
use Ourted\Model\Channel\Message;
7+
use Ourted\Model\Channel\Overwrite;
78

8-
class Channel{
9+
class Channel
10+
{
911

1012
/** @var Bot */
1113
private $bot;
@@ -15,7 +17,8 @@ public function __construct($bot)
1517
$this->bot = $bot;
1618
}
1719

18-
public function getChannel($channel_id){
20+
public function getChannel($channel_id)
21+
{
1922
return new \Ourted\Model\Channel\Channel($this->bot, $channel_id);
2023
}
2124

@@ -27,7 +30,8 @@ public function getChannel($channel_id){
2730
* @var \Ourted\Model\Channel\Channel $channel
2831
*/
2932

30-
public function sendMessage($message, $channel){
33+
public function sendMessage($message, $channel)
34+
{
3135
$this->bot->api->send(
3236
"channels/{$channel->id}/messages",
3337
"{\"content\":\"{$message}\"}");
@@ -95,8 +99,27 @@ public function getMessage($channel, $message_id)
9599
* @param $channel \Ourted\Model\Channel\Channel
96100
* @return mixed
97101
*/
98-
public function deleteChannel($channel){
99-
return json_decode($this->bot->api->send("channels/{$channel->id}","", "DELETE"));
102+
public function deleteChannel($channel)
103+
{
104+
return json_decode($this->bot->api->send("channels/{$channel->id}", "", "DELETE"));
100105
}
101106

107+
/**
108+
* @param array $overwrites
109+
* @return array
110+
*/
111+
public function createOverwrite(array ...$overwrites)
112+
{
113+
$r = array();
114+
array_keys($overwrites);
115+
foreach ($overwrites as $item) {
116+
$id = $item[0];
117+
$type = $item[1];
118+
$allow = $item[2];
119+
$deny = $item[3];
120+
$o = new Overwrite($id, $type, $allow, $deny);
121+
$r[] = $o->create_object();
122+
}
123+
return $r;
124+
}
102125
}

src/Interfaces/Guild.php

+8-13
Original file line numberDiff line numberDiff line change
@@ -157,25 +157,20 @@ 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 = "", $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 = "", $permissions = null, $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)) {
167-
if (isset($permissions[0])) {
168-
$__permissions = '';
169-
foreach ($permissions as $key => $item) {
170-
if ($key == 0) {
171-
$__permissions .= "{$item}";
172-
} else {
173-
$__permissions .= ",{$item}";
174-
}
175-
}
176-
$field .= ",\"permissions\": [{$__permissions}]";
166+
if (!is_null($permissions)) {
167+
$n_item = "";
168+
foreach ($permissions as $item) {
169+
$n_item .= $item;
177170
}
178-
}*/
171+
$field .= ",\"permission_overwrites\": [{$item}]";
172+
173+
}
179174
if (!is_null($bitrate)) {
180175
if ($type == $this->bot->CHANNEL_GUILD_VOICE) {
181176
$field .= ",\"bitrate\":{$bitrate} ";

src/Model/Channel/Overwrite.php

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
11
<?php
2+
23
namespace Ourted\Model\Channel;
34

4-
class Overwrite{
55

6+
class Overwrite
7+
{
8+
9+
public $id;
10+
public $type;
11+
public $allow;
12+
public $deny;
13+
14+
15+
/**
16+
* @param int|string $id
17+
* @param int $type
18+
* @param array $allow
19+
* @param array $deny
20+
21+
*/
22+
public function __construct($id, $type, $allow = array(), $deny = array())
23+
{
24+
$this->id = $id;
25+
$this->type = $type;
26+
$n_allow = 0;
27+
$n_deny = 0;
28+
foreach ($allow as $item) $n_allow += $item;
29+
foreach ($deny as $item) $n_deny += $item;
30+
$this->allow = $n_allow;
31+
$this->deny = $n_deny;
32+
}
33+
34+
public function create_object()
35+
{
36+
return json_encode([
37+
"id" => $this->id,
38+
"type" => $this->type,
39+
"allow" => $this->allow,
40+
"deny" => $this->deny
41+
]);
42+
}
643

744
}

src/Utils/getaway.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private function send($json){
147147
private function hello($json){
148148
$this->send_log ?
149149
$this->log('Execute: HELLO') : null;
150-
$interval = intval($json->d->heartbeat_interval / 1000);
150+
$interval = intval($json->d->heartbeat_interval) / 1000;
151151
$this->getLoop()->addPeriodicTimer($interval, function () {
152152
$this->keep_alive();
153153
});

0 commit comments

Comments
 (0)