Skip to content

Commit

Permalink
Replaced Ops
Browse files Browse the repository at this point in the history
Moved Settings.php
Removed unnecessary files
Renamed a someone files
Removed $permissions param from createChannel()
  • Loading branch information
gncdev committed Sep 19, 2020
1 parent 2118a83 commit 9b856b1
Show file tree
Hide file tree
Showing 29 changed files with 304 additions and 481 deletions.
101 changes: 51 additions & 50 deletions src/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
use Ourted\Interfaces\User;
use Ourted\Interfaces\Webhook;
use Ourted\Model\Channel\Embed;
use Ourted\Utils\API;
use Ourted\Utils\Settings;
use Ourted\Utils\getaway;
use Ourted\Utils\http;
use Ourted\Interfaces\Settings;
use Ratchet\Client\Connector;
use Ratchet\Client\WebSocket;
use Ratchet\RFC6455\Messaging\MessageInterface;
Expand All @@ -22,55 +23,55 @@ class Bot
{


public $CREATE_INSTANT_INVITE = 0x00000001;
public $KICK_MEMBERS = 0x00000002;
public $BAN_MEMBERS = 0x00000004;
public $ADMINISTRATOR = 0x00000008;
public $MANAGE_CHANNELS = 0x00000010;
public $MANAGE_GUILD = 0x00000020;
public $ADD_REACTIONS = 0x00000040;
public $VIEW_AUDIT_LOG = 0x00000080;
public $PRIORITY_SPEAKER = 0x00000100;
public $STREAM = 0x00000200;
public $VIEW_CHANNEL = 0x00000400;
public $SEND_MESSAGES = 0x00000800;
public $SEND_TTS_MESSAGES = 0x00001000;
public $MANAGE_MESSAGES = 0x00002000;
public $EMBED_LINKS = 0x00004000;
public $ATTACH_FILES = 0x00008000;
public $READ_MESSAGE_HISTORY = 0x00010000;
public $MENTION_EVERYONE = 0x00020000;
public $USE_EXTERNAL_EMOJIS = 0x00040000;
public $VIEW_GUILD_INSIGHTS = 0x00080000;
public $CONNECT = 0x00100000;
public $SPEAK = 0x00200000;
public $MUTE_MEMBERS = 0x00400000;
public $DEAFEN_MEMBERS = 0x00800000;
public $MOVE_MEMBERS = 0x01000000;
public $USE_VAD = 0x02000000;
public $CHANGE_NICKNAME = 0x04000000;
public $MANAGE_NICKNAMES = 0x08000000;
public $MANAGE_ROLES = 0x10000000;
public $MANAGE_WEBHOOKS = 0x20000000;
public $MANAGE_EMOJIS = 0x40000000;

public $GUILD_TEXT = 0;
public $DM = 1;
public $GUILD_VOICE = 2;
public $GROUP_DM = 3;
public $GUILD_NEWS = 4;
public $GUILD_STORE = 5;
public $PERMISSION_CREATE_INSTANT_INVITE = 0x00000001;
public $PERMISSION_KICK_MEMBERS = 0x00000002;
public $PERMISSION_BAN_MEMBERS = 0x00000004;
public $PERMISSION_ADMINISTRATOR = 0x00000008;
public $PERMISSION_MANAGE_CHANNELS = 0x00000010;
public $PERMISSION_MANAGE_GUILD = 0x00000020;
public $PERMISSION_ADD_REACTIONS = 0x00000040;
public $PERMISSION_VIEW_AUDIT_LOG = 0x00000080;
public $PERMISSION_PRIORITY_SPEAKER = 0x00000100;
public $PERMISSION_STREAM = 0x00000200;
public $PERMISSION_VIEW_CHANNEL = 0x00000400;
public $PERMISSION_SEND_MESSAGES = 0x00000800;
public $PERMISSION_SEND_TTS_MESSAGES = 0x00001000;
public $PERMISSION_MANAGE_MESSAGES = 0x00002000;
public $PERMISSION_EMBED_LINKS = 0x00004000;
public $PERMISSION_ATTACH_FILES = 0x00008000;
public $PERMISSION_READ_MESSAGE_HISTORY = 0x00010000;
public $PERMISSION_MENTION_EVERYONE = 0x00020000;
public $PERMISSION_USE_EXTERNAL_EMOJIS = 0x00040000;
public $PERMISSION_VIEW_GUILD_INSIGHTS = 0x00080000;
public $PERMISSION_CONNECT = 0x00100000;
public $PERMISSION_SPEAK = 0x00200000;
public $PERMISSION_MUTE_MEMBERS = 0x00400000;
public $PERMISSION_DEAFEN_MEMBERS = 0x00800000;
public $PERMISSION_MOVE_MEMBERS = 0x01000000;
public $PERMISSION_USE_VAD = 0x02000000;
public $PERMISSION_CHANGE_NICKNAME = 0x04000000;
public $PERMISSION_MANAGE_NICKNAMES = 0x08000000;
public $PERMISSION_MANAGE_ROLES = 0x10000000;
public $PERMISSION_MANAGE_WEBHOOKS = 0x20000000;
public $PERMISSION_MANAGE_EMOJIS = 0x40000000;

public $CHANNEL_CHANNEL_GUILD_TEXT = 0;
public $CHANNEL_DM = 1;
public $CHANNEL_GUILD_VOICE = 2;
public $CHANNEL_GROUP_DM = 3;
public $CHANNEL_GUILD_NEWS = 4;
public $CHANNEL_GUILD_STORE = 5;

public $GAME_LISTEN = 2;
public $GAME_WATCHING = 1;
public $GAME_PLAYING = 0;


/**
* State
* @var State
* Getaway
* @var getaway
*/
public $state;
public $getaway;
/**
* Functions
* @var Settings Instance
Expand All @@ -90,7 +91,7 @@ class Bot
* @var bool
*/
public $send_log = false;
/** @var API */
/** @var http */
public $api;
/** @var Channel */
public $channel;
Expand Down Expand Up @@ -169,7 +170,7 @@ public function __construct($botToken, $botPrefix, $wssUrl = null)
$this->invite = new Invite($this);
$this->guild = new Guild($this);
$this->user = new User($this);
$this->api = new API($this);
$this->api = new http($this);

$this->loop = Factory::create();
$this->init();
Expand All @@ -183,17 +184,17 @@ public function init()
$connector = new Connector($this->loop, new \React\Socket\Connector($this->loop));
$connector($this->wssUrl)->then(function (WebSocket $conn) {
$this->connection = $conn;
$this->state = $state = new State($conn, $this->loop, $this->token);
$this->state->send_log = $this->send_log;
$state->addDispatch($this->dispatch);
$this->getaway = $getaway = new getaway($conn, $this->loop, $this->token);
$this->getaway->send_log = $this->send_log;
$getaway->addDispatch($this->dispatch);


$conn->on('message', function (MessageInterface $msg) use ($conn, $state) {
$conn->on('message', function (MessageInterface $msg) use ($conn, $getaway) {
$json = json_decode($msg);
if (isset($json->d->session_id)) {
$this->session_id = $json->d->session_id;
}
$state->action($json, $this->loop);
$getaway->action($json);
});


Expand Down
10 changes: 5 additions & 5 deletions src/Interfaces/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function getChannel($channel_id){
*/

public function sendMessage($message, $channel){
$this->bot->api->init_curl_with_header(
$this->bot->api->send(
"channels/{$channel->id}/messages",
"{\"content\":\"{$message}\"}");
}
Expand All @@ -42,7 +42,7 @@ public function sendMessage($message, $channel){

public function deleteMessage($message)
{
return $this->bot->api->init_curl_with_header(
return $this->bot->api->send(
"channels/{$message->channel_id}/messages/{$message->id}",
"", "DELETE");
}
Expand All @@ -57,7 +57,7 @@ public function deleteMessage($message)

public function deleteBulkMessage($message, $channel)
{
return json_decode($this->bot->api->init_curl_with_header(
return json_decode($this->bot->api->send(
"channels/{$channel->id}/messages/bulk-delete",
"{\"messages\":{$message}}", "POST"));
}
Expand All @@ -72,7 +72,7 @@ public function deleteBulkMessage($message, $channel)

public function getMessages($channel, $limit = 50)
{
return json_decode($this->bot->api->init_curl_with_header(
return json_decode($this->bot->api->send(
"channels/{$channel->id}/messages?limit={$limit}",
"", "GET"));
}
Expand All @@ -96,7 +96,7 @@ public function getMessage($channel, $message_id)
* @return mixed
*/
public function deleteChannel($channel){
return json_decode($this->bot->api->init_curl_with_header("channels/{$channel->id}","", "DELETE"));
return json_decode($this->bot->api->send("channels/{$channel->id}","", "DELETE"));
}

}
6 changes: 3 additions & 3 deletions src/Interfaces/Emoji.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct($bot)
*/
public function getEmojis($guild)
{
return json_decode($this->bot->api->init_curl_with_header(
return json_decode($this->bot->api->send(
"guilds/{$guild->id}/emojis",
"", "GET"));
}
Expand All @@ -34,7 +34,7 @@ public function getEmojis($guild)
*/
public function createEmoji($guild, $name, $image)
{
return $this->getEmoji($guild, json_decode($this->bot->api->init_curl_with_header(
return $this->getEmoji($guild, json_decode($this->bot->api->send(
"guilds/{$guild->id}/emojis",
"{\"name\":\"{$name}\",\"image\":\"{$image}\",\"roles\":\"[]\"}"))->id);
}
Expand All @@ -56,7 +56,7 @@ public function getEmoji($guild, $emoji_id)
*/
public function deleteEmoji($guild, $emoji)
{
return $this->getEmoji($guild, json_decode($this->bot->api->init_curl_with_header(
return $this->getEmoji($guild, json_decode($this->bot->api->send(
"guilds/{$guild->id}/emojis/{$emoji->id}",
"", "DELETE"))->id);
}
Expand Down
28 changes: 14 additions & 14 deletions src/Interfaces/Guild.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct($bot)

public function get_guilds_properties()
{
return json_decode($this->bot->api->init_curl_with_header(
return json_decode($this->bot->api->send(
"users/@me/guilds",
"", "GET"));
}
Expand Down Expand Up @@ -65,7 +65,7 @@ public function getRoles($guild)
*/
public function getChannels($guild)
{
return json_decode($this->bot->api->init_curl_with_header("guilds/{$guild->id}/channels", "", "GET"));
return json_decode($this->bot->api->send("guilds/{$guild->id}/channels", "", "GET"));
}

/**
Expand All @@ -75,7 +75,7 @@ public function getChannels($guild)
*/
public function getPrune($guild)
{
return json_decode($this->bot->api->init_curl_with_header("guilds/{$guild->id}/prunes", "", "GET"));
return json_decode($this->bot->api->send("guilds/{$guild->id}/prunes", "", "GET"));
}

/**
Expand All @@ -85,7 +85,7 @@ public function getPrune($guild)
*/
public function getInvites($guild)
{
return json_decode($this->bot->api->init_curl_with_header("guilds/{$guild->id}/invites", "", "GET"));
return json_decode($this->bot->api->send("guilds/{$guild->id}/invites", "", "GET"));
}


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

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

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

Expand All @@ -157,13 +157,13 @@ public function deleteRole($guild, $role_id)
* @param bool
* @return \Ourted\Model\Channel\Channel
*/
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)
public function createChannel($guild, $channel_name, $type = 0, $topic = "", $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 (!is_null($permissions)) {
if (isset($permissions[0])) {
$__permissions = '';
foreach ($permissions as $key => $item) {
Expand All @@ -175,14 +175,14 @@ public function createChannel($guild, $channel_name, $type = 0, $topic = "", $pe
}
$field .= ",\"permissions\": [{$__permissions}]";
}
}
}*/
if (!is_null($bitrate)) {
if ($type == $this->bot->GUILD_VOICE) {
if ($type == $this->bot->CHANNEL_GUILD_VOICE) {
$field .= ",\"bitrate\":{$bitrate} ";
}
}
if (!is_null($user_limit)) {
if ($type == $this->bot->GUILD_VOICE) {
if ($type == $this->bot->CHANNEL_GUILD_VOICE) {
$field .= ",\"user_limit\": {$user_limit}";
}
}
Expand All @@ -195,7 +195,7 @@ public function createChannel($guild, $channel_name, $type = 0, $topic = "", $pe
if (!is_null($parent_id)) {
$field .= ",\"parent_id\": {$parent_id}";
}
$result = json_decode($this->bot->api->init_curl_with_header(
$result = json_decode($this->bot->api->send(
"guilds/{$guild->id}/channels", "
{{$field}}", "POST"));
return new \Ourted\Model\Channel\Channel($this->bot, $result->id);
Expand All @@ -210,7 +210,7 @@ public function createChannel($guild, $channel_name, $type = 0, $topic = "", $pe
*/
public function changeChannelPosition($guild, $channel, $position)
{
$result = json_decode($this->bot->api->init_curl_with_header("guilds/{$guild->id}/channels", "{\"id\":{$channel->id}, \"position\":{$position}}", "PATCH"));
$result = json_decode($this->bot->api->send("guilds/{$guild->id}/channels", "{\"id\":{$channel->id}, \"position\":{$position}}", "PATCH"));
return new \Ourted\Model\Channel\Channel($this->bot, $result->id);
}
}
Loading

0 comments on commit 9b856b1

Please sign in to comment.