Skip to content

Commit

Permalink
Update | Beta 3.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gncdev committed Aug 8, 2020
1 parent 5d7e025 commit 2d1e085
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 35 deletions.
113 changes: 113 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Ourted extends Bot
public function setBot()
{
// Ready Event Listener
$this->addListener(
$this->addListeners(
"EventListener"
);
echo "Hello World\n";
Expand Down
4 changes: 2 additions & 2 deletions example/Ourted.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public function setBot()
$func = $this->functions;
$settings = $this->settings;

// Ready Event Listener
$this->addListener(
// Ready Event Listeners
$this->addListeners(
"EventListener"
);

Expand Down
10 changes: 6 additions & 4 deletions src/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,14 @@ public function __construct($botToken, $botPrefix, $wssUrl = null)
/**
* Add a new dispatch handler
*
* @param string $listener
* @param string ...$listener
*/
public function addListener($listener)
public function addListeners(...$listener)
{
$this->listeners[] = $listener;
new $listener($this->getBot());
foreach ($listener as $item) {
$this->listeners[] = $item;
new $item($this->getBot());
}
}


Expand Down
48 changes: 25 additions & 23 deletions src/Model/EventListener/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ abstract class EventListener
*/
public $token;

private function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}

/**
*
* @var Bot $bot
Expand All @@ -38,53 +48,50 @@ public function __construct($bot)
$this->bot = $bot;
$this->token = $bot->getToken();
$this->func = $bot->functions;
$bot->addDispatch('GUILD_CREATE','GUILD_CREATE', function ($json) {
$bot->addDispatch('GUILD_CREATE',$this->generateRandomString(), function ($json) {
$this->onGuildJoin($json->d, $this->bot);
});
$bot->addDispatch('GUILD_MEMBER_ADD','GUILD_MEMBER_ADD', function ($json) {
$bot->addDispatch('GUILD_MEMBER_ADD',$this->generateRandomString(), function ($json) {
$this->onGuildMemberAdd($json->d, $this->bot);
});
$bot->addDispatch('GUILD_MEMBER_UPDATE','GUILD_MEMBER_UPDATE', function ($json) {
$bot->addDispatch('GUILD_MEMBER_UPDATE',$this->generateRandomString(), function ($json) {
$this->onGuildMemberUpdate($json->d, $this->bot);
});
$bot->addDispatch('GUILD_MEMBER_DELETE','GUILD_MEMBER_DELETE', function ($json) {
$bot->addDispatch('GUILD_MEMBER_DELETE',$this->generateRandomString(), function ($json) {
$this->onGuildMemberDelete($json->d, $this->bot);
});
$bot->addDispatch('GUILD_UPDATE','GUILD_UPDATE', function ($json) {
$bot->addDispatch('GUILD_UPDATE',$this->generateRandomString(), function ($json) {
$this->onGuildDelete($json->d, $this->bot);
});
$bot->addDispatch('GUILD_DELETE','GUILD_DELETE', function ($json) {
$bot->addDispatch('GUILD_DELETE',$this->generateRandomString(), function ($json) {
$this->onGuildUpdate($json->d, $this->bot);
});
$bot->addDispatch('GUILD_ROLE_CREATE','GUILD_ROLE_CREATE', function ($json) {
$bot->addDispatch('GUILD_ROLE_CREATE',$this->generateRandomString(), function ($json) {
$this->onGuildRoleCreate($json->d, $this->bot);
});
$bot->addDispatch('GUILD_ROLE_UPDATE','GUILD_ROLE_UPDATE', function ($json) {
$bot->addDispatch('GUILD_ROLE_UPDATE',$this->generateRandomString(), function ($json) {
$this->onGuildRoleUpdate($json->d, $this->bot);
});
$bot->addDispatch('GUILD_ROLE_DELETE','GUILD_ROLE_DELETE', function ($json) {
$bot->addDispatch('GUILD_ROLE_DELETE',$this->generateRandomString(), function ($json) {
$this->onGuildRoleDelete($json->d, $this->bot);
});
$bot->addDispatch('MESSAGE_CREATE','MESSAGE_CREATEee', function ($json) {
$bot->addDispatch('MESSAGE_CREATE',$this->generateRandomString(), function ($json) {
$this->onMessageCreate($json->d, $this->bot);
});
$bot->addDispatch('MESSAGE_CREATE','COMMANDS', function ($json) {
$this->onCommand($json->d, $this->bot);
});
$bot->addDispatch('CHANNEL_CREATE','CHANNEL_CREATE', function ($json) {
$bot->addDispatch('CHANNEL_CREATE',$this->generateRandomString(), function ($json) {
$this->onChannelCreate($json->d, $this->bot);
});
$bot->addDispatch('CHANNEL_UPDATE','CHANNEL_UPDATE', function ($json) {
$bot->addDispatch('CHANNEL_UPDATE',$this->generateRandomString(), function ($json) {
$this->onChannelUpdate($json->d, $this->bot);
});
$bot->addDispatch('CHANNEL_DELETE','CHANNEL_DELETE', function ($json) {
$bot->addDispatch('CHANNEL_DELETE',$this->generateRandomString(), function ($json) {
$this->onChannelDelete($json->d, $this->bot);
});
$bot->addDispatch('CHANNEL_PINS_UPDATE','CHANNEL_PINS_UPDATE', function ($json) {
$bot->addDispatch('CHANNEL_PINS_UPDATE',$this->generateRandomString(), function ($json) {
$this->onChannelPinsUpdate($json->d, $this->bot);
});

$bot->addDispatch('READY','READY', function ($json) {
$bot->addDispatch('READY',$this->generateRandomString(), function ($json) {
$this->onReady($json->d, $this->bot);
});
}
Expand Down Expand Up @@ -170,11 +177,6 @@ public function onMessageCreate($json, $bot)

}

# Command
public function onCommand($json, $bot)
{

}

# Bot
public function onReady($json, $bot)
Expand Down
1 change: 0 additions & 1 deletion src/Model/Message/Embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,4 @@ function send_embed()
"channels/{$this->embed['channel_id']}/messages",
$headers, $field, "POST");
}

}
9 changes: 5 additions & 4 deletions src/Utils/Functions.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php


namespace Ourted\Utils;

use Ourted\Bot;
Expand Down Expand Up @@ -52,7 +53,7 @@ public function init_curl_with_header($url, $headers, $field, $tur = "POST")
{
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://discord.com/api/v6/".$url);
curl_setopt($ch, CURLOPT_URL, "https://discord.com/api/v6/" . $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $tur);
curl_setopt($ch, CURLOPT_POST, 1);
Expand Down Expand Up @@ -86,7 +87,7 @@ public function init_curl_with_header_print_r($url, $headers, $tur = "GET")
$headers[] = 'X-RateLimit-Reset: 147017';
$headers[] = 'X-RateLimit-Reset-After: 5';
$headers[] = 'X-RateLimit-Bucket: abcd1234';
curl_setopt($ch, CURLOPT_URL, "https://discord.com/api/v6/".$url);
curl_setopt($ch, CURLOPT_URL, "https://discord.com/api/v6/" . $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $tur);
curl_setopt($ch, CURLOPT_POST, 1);
Expand Down Expand Up @@ -167,7 +168,6 @@ public function deleteMessage($message)
}



/**
* Get guilds
*
Expand All @@ -185,7 +185,8 @@ public function get_guilds_properties()
$headers, "", "GET");
}

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

Expand Down
1 change: 1 addition & 0 deletions src/Utils/Settings.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php


namespace Ourted\Utils;

use Ourted\Bot;
Expand Down

0 comments on commit 2d1e085

Please sign in to comment.