Skip to content

Commit 262b90d

Browse files
committed
Update | Stable 1.0
1 parent 939b907 commit 262b90d

19 files changed

+456
-256
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/vendor/
22
/test/
33
/docs/
4+
/atlas/

README.md

+22-9
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Ourted extends Bot
3838
$dotenv = Dotenv::createImmutable(__DIR__);
3939
$dotenv->load();
4040
$this->token = $_ENV['BOT_TOKEN'];
41-
parent::__construct($this->token, '!');
41+
parent::__construct($this->token, '!'); /* 1: Bot Token, 2: Bot Prefix */
4242
$this->setBot();
4343
}
4444

@@ -94,10 +94,10 @@ class Ourted extends Bot
9494
}
9595
}
9696

97-
class EventListener extends \Ourted\Interfaces\EventListener
97+
class EventListener extends \Ourted\Model\EventListener\EventListener
9898
{
9999
# Guild
100-
public function onGuildJoin($json, $bot)
100+
public function onGuildCreate($json, $bot)
101101
{
102102

103103
}
@@ -231,8 +231,8 @@ class Ourted extends Bot
231231
}
232232
class TestCommand extends Command{
233233

234-
public function execute($message, $bot){
235-
$bot->channel->sendMessage("Command Used! Command: {$message->content}", $message->channel_id);
234+
public function execute($message, $bot, $channel, $guild){
235+
$bot->channel->sendMessage("Command Used! Command: {$message->content}", $channel);
236236
}
237237
}
238238

@@ -243,6 +243,11 @@ Result:
243243
---
244244
![Example Command](assets/Command.PNG)
245245

246+
247+
addCommand() Parameters:
248+
1. Command Name
249+
2. a Closure to call command class
250+
246251
---
247252

248253
Delete Message
@@ -290,6 +295,9 @@ new Ourted();
290295
?>
291296
````
292297

298+
First wer get channel with getChannel() function. then delete messages with channel and message id.
299+
300+
293301
Delete Bulk Message
294302
---
295303

@@ -322,10 +330,7 @@ class Ourted extends Bot
322330

323331
$ids = "";
324332
// Count Messages
325-
foreach ($this->channel->getMessages($channel) as $key => $item) {
326-
if($key == 99){
327-
return;
328-
}
333+
foreach ($this->channel->getMessages($channel, 99) as $key => $item) {
329334
count($this->channel->getMessages($channel)) -1 == $key?
330335
$ids .= "\"$item->id\"" : $ids.= "\"$item->id\",";
331336
}
@@ -341,6 +346,14 @@ new Ourted();
341346
?>
342347
````
343348

349+
On **getMessages()** Function must be 2 param setted 1-100 between, integer.
350+
351+
Paramaters:
352+
1. Ourted\Model\Channel\Channel.php Instance
353+
2. Integer
354+
355+
356+
344357
Add Role
345358
---
346359

composer.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"ext-json": "*",
1010
"react/react": "*",
1111
"react/event-loop": "*",
12-
"ext-curl": "*"
12+
"ext-curl": "*",
13+
"ext-fileinfo": "*"
1314
},
1415
"license": "GPL-3.0-or-later",
1516
"authors": [
@@ -20,7 +21,8 @@
2021
],
2122
"autoload": {
2223
"psr-4": {
23-
"Ourted\\": "src/"
24+
"Ourted\\": "src/",
25+
"Atlas\\": "Atlas/src/"
2426
}
2527
}
2628
}

src/Bot.php

+88-21
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
use Ourted\Interfaces\Invite;
1010
use Ourted\Interfaces\Member;
1111
use Ourted\Interfaces\User;
12-
use Ourted\Model\Message\Embed;
12+
use Ourted\Interfaces\Webhook;
13+
use Ourted\Model\Channel\Embed;
1314
use Ourted\Utils\API;
1415
use Ourted\Utils\Settings;
1516
use Ratchet\Client\Connector;
@@ -20,6 +21,51 @@
2021
class Bot
2122
{
2223

24+
25+
public $CREATE_INSTANT_INVITE = 0x00000001;
26+
public $KICK_MEMBERS = 0x00000002;
27+
public $BAN_MEMBERS = 0x00000004;
28+
public $ADMINISTRATOR = 0x00000008;
29+
public $MANAGE_CHANNELS = 0x00000010;
30+
public $MANAGE_GUILD = 0x00000020;
31+
public $ADD_REACTIONS = 0x00000040;
32+
public $VIEW_AUDIT_LOG = 0x00000080;
33+
public $PRIORITY_SPEAKER = 0x00000100;
34+
public $STREAM = 0x00000200;
35+
public $VIEW_CHANNEL = 0x00000400;
36+
public $SEND_MESSAGES = 0x00000800;
37+
public $SEND_TTS_MESSAGES = 0x00001000;
38+
public $MANAGE_MESSAGES = 0x00002000;
39+
public $EMBED_LINKS = 0x00004000;
40+
public $ATTACH_FILES = 0x00008000;
41+
public $READ_MESSAGE_HISTORY = 0x00010000;
42+
public $MENTION_EVERYONE = 0x00020000;
43+
public $USE_EXTERNAL_EMOJIS = 0x00040000;
44+
public $VIEW_GUILD_INSIGHTS = 0x00080000;
45+
public $CONNECT = 0x00100000;
46+
public $SPEAK = 0x00200000;
47+
public $MUTE_MEMBERS = 0x00400000;
48+
public $DEAFEN_MEMBERS = 0x00800000;
49+
public $MOVE_MEMBERS = 0x01000000;
50+
public $USE_VAD = 0x02000000;
51+
public $CHANGE_NICKNAME = 0x04000000;
52+
public $MANAGE_NICKNAMES = 0x08000000;
53+
public $MANAGE_ROLES = 0x10000000;
54+
public $MANAGE_WEBHOOKS = 0x20000000;
55+
public $MANAGE_EMOJIS = 0x40000000;
56+
57+
public $GUILD_TEXT = 0;
58+
public $DM = 1;
59+
public $GUILD_VOICE = 2;
60+
public $GROUP_DM = 3;
61+
public $GUILD_NEWS = 4;
62+
public $GUILD_STORE = 5;
63+
64+
public $GAME_LISTEN = 2;
65+
public $GAME_WATCHING = 1;
66+
public $GAME_PLAYING = 0;
67+
68+
2369
/**
2470
* State
2571
* @var State
@@ -56,6 +102,12 @@ class Bot
56102
public $member;
57103
/** @var Invite */
58104
public $invite;
105+
/** @var Webhook */
106+
public $webhook;
107+
/**
108+
* @var mixed
109+
*/
110+
public $session_id;
59111
/**
60112
* Default WSS URL (from the Discord API docs)
61113
* @var string
@@ -66,7 +118,6 @@ class Bot
66118
* @var WebSocket Instance
67119
*/
68120
protected $connection;
69-
70121
/**
71122
* @var bool
72123
*/
@@ -112,6 +163,7 @@ public function __construct($botToken, $botPrefix, $wssUrl = null)
112163
$this->prefix = $botPrefix;
113164
$this->token = $botToken;
114165
$this->settings = new Settings($this);
166+
$this->webhook = new Webhook($this);
115167
$this->channel = new Channel($this);
116168
$this->member = new Member($this);
117169
$this->invite = new Invite($this);
@@ -138,17 +190,26 @@ public function init()
138190

139191
$conn->on('message', function (MessageInterface $msg) use ($conn, $state) {
140192
$json = json_decode($msg);
193+
if (isset($json->d->session_id)) {
194+
$this->session_id = $json->d->session_id;
195+
}
141196
$state->action($json, $this->loop);
142197
});
143198

144199

145-
$conn->on('close', function ($code = null, $reason = null) {
200+
$conn->on('close', function ($code = null, $reason = null) use ($conn) {
146201
echo "\nConnection closed ({$code} - {$reason})\n";
147-
if(!$this->reconnect) {
202+
if (!$this->reconnect) {
148203
die();
149-
}else{
150-
$this->stop();
151-
$this->run();
204+
} else {
205+
$conn->send(json_encode([
206+
"op" => 6,
207+
"d" => [
208+
"token" => $this->getBot()->token,
209+
"session_id" => $this->getBot()->session_id,
210+
"seq" => 1337
211+
]
212+
]));
152213
}
153214
});
154215

@@ -161,16 +222,27 @@ public function init()
161222
return null;
162223
}
163224

225+
public function getBot()
226+
{
227+
return $this;
228+
}
229+
164230
public function stop()
165231
{
166232
$this->loop->stop();
167233
}
168234

235+
public function run()
236+
{
237+
238+
$this->loop->run();
239+
echo "Connection Started!";
240+
}
241+
169242
/**
170243
* Add a new dispatch handler
171244
*
172245
* @param string $type Dispatch type
173-
* @param string $callback_name Dispatch name
174246
* @param string|Callable $callback Callback to execute when dispatching action
175247
*/
176248
public function addDispatch($type, $callback)
@@ -196,10 +268,17 @@ public function addCommand($command_name, $function)
196268
$function($this, $command_name);
197269
}
198270

271+
public function getImageData($image_path){
272+
if(!file_exists($image_path) || str_ends_with($image_path, ("png" || "jpg" || "jpeg" | "PNG" || "JPG" || "JPEG"))) return "Fail";
273+
$imageData = base64_encode(file_get_contents($image_path));
274+
return 'data: '.mime_content_type($image_path).';base64,'.$imageData;
275+
}
276+
199277
/**
200278
* @param $title
201-
* @param \Ourted\Model\Channel\Channel $channel
279+
* @param Model\Channel\Channel $channel
202280
* @param string $description
281+
* @return Embed
203282
*/
204283
public function createEmbed($title, $channel, $description = "")
205284
{
@@ -219,13 +298,6 @@ public function addListeners(...$listener)
219298
}
220299
}
221300

222-
public function run()
223-
{
224-
225-
$this->loop->run();
226-
echo "Connection Started!";
227-
}
228-
229301
/**
230302
* Get Connection
231303
*
@@ -241,10 +313,5 @@ public function getToken()
241313
return $this->token;
242314
}
243315

244-
public function getBot()
245-
{
246-
return $this;
247-
}
248-
249316

250317
}

src/Interfaces/Channel.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Ourted\Interfaces;
44

55
use Ourted\Bot;
6-
use Ourted\Model\Message\Message;
6+
use Ourted\Model\Channel\Message;
77

88
class Channel{
99

@@ -67,12 +67,13 @@ public function deleteBulkMessage($message, $channel)
6767
*
6868
* @return bool|array
6969
* @var \Ourted\Model\Channel\Channel $channel Channel Instance
70+
* @var int $limit
7071
*/
7172

72-
public function getMessages($channel)
73+
public function getMessages($channel, $limit = 50)
7374
{
7475
return json_decode($this->bot->api->init_curl_with_header(
75-
"channels/{$channel->id}/messages",
76+
"channels/{$channel->id}/messages?limit={$limit}",
7677
"", "GET"));
7778
}
7879

src/Interfaces/Guild.php

+29-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Ourted\Bot;
66
use Ourted\Model\Guild\Integration;
7-
use Ourted\Model\Role\Role;
7+
use Ourted\Model\Guild\Role;
88

99
class Guild
1010
{
@@ -156,9 +156,34 @@ public function deleteRole($guild, $role_id)
156156
* @param bool
157157
* @return \Ourted\Model\Channel\Channel
158158
*/
159-
public function createChannel($guild, $channel_name, $type = 0, $topic = "", $bitrate = 0, $user_limit = 0, $rate_limit_per_user = 0, $position = 0, $parent_id = 0, $nsfw = false)
159+
public function createChannel($guild, $channel_name, $type = 0, $topic = "", $bitrate = null, $user_limit = null, $rate_limit_per_user = null, $position = null, $parent_id = null)
160160
{
161-
$result = json_decode($this->bot->api->init_curl_with_header("guilds/{$guild->id}/channels", "{\"name\": \"{$channel_name}\", \"type\": {$type}, \"topic\", \"{$topic}\", \"bitrate\":{$bitrate}, \"user_limit\": {$user_limit}, \"rate_limit_per_user\": {$rate_limit_per_user}, \"position\":{$position}, \"parent_id\": {$parent_id}, \"nsfw\": {$nsfw}}", "POST"));
161+
$field = "";
162+
$field .= "\"name\": \"$channel_name\"";
163+
$field .= ",\"type\": $type";
164+
$field .= ",\"topic\": \"{$topic}\"";
165+
if (!is_null($bitrate)) {
166+
if ($type == $this->bot->GUILD_VOICE) {
167+
$field .= ",\"bitrate\":{$bitrate} ";
168+
}
169+
}
170+
if (!is_null($user_limit)) {
171+
if ($type == $this->bot->GUILD_VOICE) {
172+
$field .= ",\"user_limit\": {$user_limit}";
173+
}
174+
}
175+
if (!is_null($rate_limit_per_user)) {
176+
$field .= ",\"rate_limit_per_user\": {$rate_limit_per_user}";
177+
}
178+
if (!is_null($position)) {
179+
$field .= ",\"position\": {$position}";
180+
}
181+
if (!is_null($parent_id)) {
182+
$field .= ",\"parent_id\": {$parent_id}";
183+
}
184+
$result = json_decode($this->bot->api->init_curl_with_header(
185+
"guilds/{$guild->id}/channels", "
186+
{{$field}}", "POST"));
162187
return new \Ourted\Model\Channel\Channel($this->bot, $result->id);
163188
}
164189

@@ -167,6 +192,7 @@ public function createChannel($guild, $channel_name, $type = 0, $topic = "", $bi
167192
* @param \Ourted\Model\Guild\Guild $guild
168193
* @param \Ourted\Model\Channel\Channel
169194
* @param int
195+
* @return \Ourted\Model\Channel\Channel
170196
*/
171197
public function changeChannelPosition($guild, $channel, $position)
172198
{

src/Interfaces/Member.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Ourted\Interfaces;
44

55
use Ourted\Bot;
6-
use Ourted\Model\Role\Role;
6+
use Ourted\Model\Guild\Role;
77

88
class Member
99
{
@@ -47,6 +47,7 @@ public function setNickname($guild, $user, $nickname)
4747
* @param bool $mute
4848
* @param \Ourted\Model\User\User $user
4949
*
50+
* @return mixed
5051
*/
5152
public function setMute($guild, $user, $mute)
5253
{

0 commit comments

Comments
 (0)