From f61cebf4a5d9dcf349bccaa3c29d47b4914ed33b Mon Sep 17 00:00:00 2001 From: GianC-Dev Date: Mon, 10 Aug 2020 13:01:51 +0300 Subject: [PATCH] Update | Beta 4.0.1 --- README.md | 4 ++-- example/Ourted.php | 6 +++--- src/Interfaces/Channel.php | 12 ++++++------ src/Interfaces/Guild.php | 6 +++--- src/Model/Command/Command.php | 13 +++++++++++++ src/State.php | 2 +- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 14c1b6e..96b3866 100644 --- a/README.md +++ b/README.md @@ -247,11 +247,11 @@ class Ourted extends Bot $ids = ""; // Count Messages - foreach (json_decode($this->channel->getMessages($channel)) as $key => $item) { + foreach ($this->channel->getMessages($channel) as $key => $item) { if($key == 99){ return; } - count(json_decode($this->channel->getMessages($channel))) -1 == $key? + count($this->channel->getMessages($channel)) -1 == $key? $ids .= "\"$item->id\"" : $ids.= "\"$item->id\","; } // Delete Messages diff --git a/example/Ourted.php b/example/Ourted.php index 083e5c4..c7c892e 100644 --- a/example/Ourted.php +++ b/example/Ourted.php @@ -46,7 +46,7 @@ public function setBot() /* Embed Start */ $embed_array = array(); $embed_string = ""; - foreach (json_decode($this->guild->get_guilds_properties()) as $key => $server) { + foreach ($this->guild->get_guilds_properties() as $key => $server) { $embed_array[] = array("name" => "Server of {$key}.", "value" => $server->name); $embed_string .= " Server of {$key}: {$server->name} "; } @@ -72,9 +72,9 @@ public function setBot() /* Bulk Delete Start */ $ids = ""; // Count Messages - foreach (json_decode($this->channel->getMessages($channel)) as $key => $item) { + foreach ($this->channel->getMessages($channel) as $key => $item) { if($key == 99){ - return; + break; } count(json_decode($this->channel->getMessages($channel))) -1 == $key? $ids .= "\"$item->id\"" : $ids.= "\"$item->id\","; diff --git a/src/Interfaces/Channel.php b/src/Interfaces/Channel.php index 4a8e2af..74f6832 100644 --- a/src/Interfaces/Channel.php +++ b/src/Interfaces/Channel.php @@ -51,30 +51,30 @@ public function deleteMessage($message) /** * Deleting Message * - * @return bool|string + * @return bool|array * @var string $message * @var \Ourted\Model\Channel\Channel $channel */ public function deleteBulkMessage($message, $channel) { - return $this->bot->api->init_curl_with_header( + return json_decode($this->bot->api->init_curl_with_header( "channels/{$channel->id}/messages/bulk-delete", - "{\"messages\":{$message}}", "POST"); + "{\"messages\":{$message}}", "POST")); } /** * Getting Messages in Selected Channel * - * @return bool|string + * @return bool|array * @var \Ourted\Model\Channel\Channel $channel Channel Instance */ public function getMessages($channel) { - return $this->bot->api->init_curl_with_header( + return json_decode($this->bot->api->init_curl_with_header( "channels/{$channel->id}/messages", - "", "GET"); + "", "GET")); } /** diff --git a/src/Interfaces/Guild.php b/src/Interfaces/Guild.php index 326f21b..88a60b0 100644 --- a/src/Interfaces/Guild.php +++ b/src/Interfaces/Guild.php @@ -18,14 +18,14 @@ public function __construct($bot) /** * Get guilds * - * @return bool|string + * @return bool|array */ public function get_guilds_properties() { - return $this->bot->api->init_curl_with_header( + return json_decode($this->bot->api->init_curl_with_header( "users/@me/guilds", - "", "GET"); + "", "GET")); } } \ No newline at end of file diff --git a/src/Model/Command/Command.php b/src/Model/Command/Command.php index 4953188..9a891b3 100644 --- a/src/Model/Command/Command.php +++ b/src/Model/Command/Command.php @@ -14,6 +14,12 @@ abstract class Command */ protected $bot; + /** + * Current bot instance + * @var stdClass $json + */ + protected $json; + /** * Curernt loop instance * @var EventLoop\ @@ -30,12 +36,19 @@ abstract class Command public function __construct($bot, $command_name) { $bot->addDispatch('MESSAGE_CREATE', $command_name, function ($json) use ($command_name, $bot) { + $this->json = $json->d; if (str_starts_with($json->d->content, $bot->prefix . $command_name)) { $this->execute($json->d, $bot); } }); } + protected function getArgs(){ + $result = explode(" ", $this->json->content); + unset($result[0]); + return $result; + } + /** * Execute * diff --git a/src/State.php b/src/State.php index ede3e5c..4eca07f 100644 --- a/src/State.php +++ b/src/State.php @@ -42,7 +42,7 @@ class State /** * @var bool */ - public $send_log = false; + public $send_log = true; /** * Discord API operations to class relationships