Skip to content

Commit

Permalink
Added Permission Property
Browse files Browse the repository at this point in the history
  • Loading branch information
gncdev committed Oct 15, 2020
1 parent 9b856b1 commit 677e9be
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 20 deletions.
3 changes: 3 additions & 0 deletions src/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Ratchet\RFC6455\Messaging\MessageInterface;
use React\EventLoop\Factory;


class Bot
{

Expand Down Expand Up @@ -66,6 +67,8 @@ class Bot
public $GAME_WATCHING = 1;
public $GAME_PLAYING = 0;

public $OVERWRITE_TYPE_ROLE = 0;
public $OVERWRITE_TYPE_MEMBER = 1;

/**
* Getaway
Expand Down
33 changes: 28 additions & 5 deletions src/Interfaces/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

use Ourted\Bot;
use Ourted\Model\Channel\Message;
use Ourted\Model\Channel\Overwrite;

class Channel{
class Channel
{

/** @var Bot */
private $bot;
Expand All @@ -15,7 +17,8 @@ public function __construct($bot)
$this->bot = $bot;
}

public function getChannel($channel_id){
public function getChannel($channel_id)
{
return new \Ourted\Model\Channel\Channel($this->bot, $channel_id);
}

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

public function sendMessage($message, $channel){
public function sendMessage($message, $channel)
{
$this->bot->api->send(
"channels/{$channel->id}/messages",
"{\"content\":\"{$message}\"}");
Expand Down Expand Up @@ -95,8 +99,27 @@ public function getMessage($channel, $message_id)
* @param $channel \Ourted\Model\Channel\Channel
* @return mixed
*/
public function deleteChannel($channel){
return json_decode($this->bot->api->send("channels/{$channel->id}","", "DELETE"));
public function deleteChannel($channel)
{
return json_decode($this->bot->api->send("channels/{$channel->id}", "", "DELETE"));
}

/**
* @param array $overwrites
* @return array
*/
public function createOverwrite(array ...$overwrites)
{
$r = array();
array_keys($overwrites);
foreach ($overwrites as $item) {
$id = $item[0];
$type = $item[1];
$allow = $item[2];
$deny = $item[3];
$o = new Overwrite($id, $type, $allow, $deny);
$r[] = $o->create_object();
}
return $r;
}
}
21 changes: 8 additions & 13 deletions src/Interfaces/Guild.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,20 @@ public function deleteRole($guild, $role_id)
* @param bool
* @return \Ourted\Model\Channel\Channel
*/
public function createChannel($guild, $channel_name, $type = 0, $topic = "", $bitrate = null, $user_limit = null, $rate_limit_per_user = null, $position = null, $parent_id = null)
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)
{
$field = "";
$field .= "\"name\": \"$channel_name\"";
$field .= ",\"type\": $type";
$field .= ",\"topic\": \"{$topic}\"";
/*if (!is_null($permissions)) {
if (isset($permissions[0])) {
$__permissions = '';
foreach ($permissions as $key => $item) {
if ($key == 0) {
$__permissions .= "{$item}";
} else {
$__permissions .= ",{$item}";
}
}
$field .= ",\"permissions\": [{$__permissions}]";
if (!is_null($permissions)) {
$n_item = "";
foreach ($permissions as $item) {
$n_item .= $item;
}
}*/
$field .= ",\"permission_overwrites\": [{$item}]";

}
if (!is_null($bitrate)) {
if ($type == $this->bot->CHANNEL_GUILD_VOICE) {
$field .= ",\"bitrate\":{$bitrate} ";
Expand Down
39 changes: 38 additions & 1 deletion src/Model/Channel/Overwrite.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
<?php

namespace Ourted\Model\Channel;

class Overwrite{

class Overwrite
{

public $id;
public $type;
public $allow;
public $deny;


/**
* @param int|string $id
* @param int $type
* @param array $allow
* @param array $deny
*/
public function __construct($id, $type, $allow = array(), $deny = array())
{
$this->id = $id;
$this->type = $type;
$n_allow = 0;
$n_deny = 0;
foreach ($allow as $item) $n_allow += $item;
foreach ($deny as $item) $n_deny += $item;
$this->allow = $n_allow;
$this->deny = $n_deny;
}

public function create_object()
{
return json_encode([
"id" => $this->id,
"type" => $this->type,
"allow" => $this->allow,
"deny" => $this->deny
]);
}

}
2 changes: 1 addition & 1 deletion src/Utils/getaway.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private function send($json){
private function hello($json){
$this->send_log ?
$this->log('Execute: HELLO') : null;
$interval = intval($json->d->heartbeat_interval / 1000);
$interval = intval($json->d->heartbeat_interval) / 1000;
$this->getLoop()->addPeriodicTimer($interval, function () {
$this->keep_alive();
});
Expand Down

0 comments on commit 677e9be

Please sign in to comment.