Skip to content

Commit 585c329

Browse files
committed
Update | Beta 1.0
1 parent 4cfaf59 commit 585c329

17 files changed

+647
-1782
lines changed

.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
BOT_TOKEN=NzQwNjQyNDAyODg4NDUwMTQw.Xyr-_Q.GuDhf7g7Ue_P9Lal0X8L9_kt4QE
1+
BOT_TOKEN=NzQwNjQyNDAyODg4NDUwMTQw.Xyr-_Q.qmCZP9S1rMAoqVE7eTuZSI-uQgA

.idea/Ourted.iml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

+157-37
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example.php

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
require_once __DIR__ . '\\..\\vendor\\autoload.php';
4+
5+
use Dotenv\Dotenv;
6+
use Ourted\Bot;
7+
8+
class Ourted extends Bot
9+
{
10+
11+
public $token;
12+
13+
public function __construct()
14+
{
15+
$dotenv = Dotenv::createImmutable(__DIR__ . '/../');
16+
$dotenv->load();
17+
$this->token = $_ENV['BOT_TOKEN'];
18+
parent::__construct($this->token);
19+
$this->setBot();
20+
}
21+
22+
public function setBot()
23+
{
24+
// Ready Event Listener
25+
$this->addListener(
26+
"EventListener"
27+
);
28+
echo "Hello World\n";
29+
$this->run();
30+
}
31+
}
32+
33+
class EventListener extends \Ourted\Interfaces\EventListener
34+
{
35+
36+
public function onMessageCreate($json, $bot)
37+
{
38+
/*
39+
Content: $json->content
40+
Author Username: $json->author->username
41+
Author Discriminator: $json->author->discriminator
42+
Author ID: $json->author->id
43+
*/
44+
45+
if(isset($json->author->bot)){
46+
return;
47+
}
48+
$this->func->sendMessage("Message Sended! By: <@{$json->author->id}>, Content: {$json->content}", $json->channel_id);
49+
}
50+
51+
52+
}
53+
54+
new Ourted();

README.md

+85-16
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,106 @@
11
## Ourted: A Discord bot in PHP
22

3-
The `Ourted` library provides a long-running bot process written in PHP.
3+
The `Ourted` library provides a running bot process written in PHP.
44

55
### Installation
66

77
```
8-
git clone git@github.com:GianC-Dev/Ourret.git
9-
composer install
8+
composer require ourted/ourted
109
```
1110

12-
Copy the `.env.dist` file to `.env` and configure it with your bot's token.
11+
Edit ``.env`` and configure bot token
1312

14-
### Usage
13+
### Examples
14+
Without Event Listener
15+
```php
16+
<?php
1517

16-
```
17-
php bin/dbot.php
18-
```
18+
require_once __DIR__ . '\\..\\vendor\\autoload.php';
19+
20+
use Dotenv\Dotenv;
21+
use Ourted\Bot;
1922

23+
class Ourted extends Bot
24+
{
2025

21-
### Adding a Dispatch action
26+
public $token;
27+
28+
public function __construct()
29+
{
30+
$dotenv = Dotenv::createImmutable(__DIR__ . '/../');
31+
$dotenv->load();
32+
$this->token = $_ENV['BOT_TOKEN'];
33+
parent::__construct($this->token);
34+
$this->setBot();
35+
}
36+
37+
public function setBot()
38+
{
39+
echo "Hello World\n";
40+
$this->run();
41+
}
42+
}
43+
44+
new Ourted();
45+
?>
46+
```
2247

23-
When the Discord API sends a new event on the websocket, your bot will receive the message with a `t` value in the JSON. This is the "dispatch type". Handlers for these can be added to the `bin/dbot.php` script like this for a `GUILD_CREATE`:
48+
With Event Listener
2449

2550
```php
2651
<?php
27-
$bot = new Bot($_ENV['BOT_TOKEN']);
2852

29-
$bot->addDispatch('GUILD_CREATE', function($json) {
30-
echo 'guild create!!!!'."\n";
53+
require_once __DIR__ . '\\..\\vendor\\autoload.php';
54+
55+
use Dotenv\Dotenv;
56+
use Ourted\Bot;
57+
58+
class Ourted extends Bot
59+
{
60+
61+
public $token;
62+
63+
public function __construct()
64+
{
65+
$dotenv = Dotenv::createImmutable(__DIR__ . '/../');
66+
$dotenv->load();
67+
$this->token = $_ENV['BOT_TOKEN'];
68+
parent::__construct($this->token);
69+
$this->setBot();
70+
}
71+
72+
public function setBot()
73+
{
74+
// Ready Event Listener
75+
$this->addListener(
76+
"EventListener"
77+
);
78+
echo "Hello World\n";
79+
$this->run();
80+
}
81+
}
82+
83+
class EventListener extends \Ourted\Interfaces\EventListener
84+
{
85+
86+
public function onMessageCreate($json, $bot)
87+
{
88+
/*
89+
Content: $json->content
90+
Author Username: $json->author->username
91+
Author Discriminator: $json->author->discriminator
92+
Author ID: $json->author->id
93+
*/
94+
95+
if(isset($json->author->bot)){
96+
return;
97+
}
98+
$this->func->sendMessage("Message Sended! By: <@{$json->author->id}>, Content: {$json->content}", $json->channel_id);
99+
}
100+
31101

32-
return 'test';
33-
});
102+
}
34103

35-
$bot->init();
104+
new Ourted();
36105
?>
37106
```

0 commit comments

Comments
 (0)