-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
647 additions
and
1,782 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
BOT_TOKEN=NzQwNjQyNDAyODg4NDUwMTQw.Xyr-_Q.GuDhf7g7Ue_P9Lal0X8L9_kt4QE | ||
BOT_TOKEN=NzQwNjQyNDAyODg4NDUwMTQw.Xyr-_Q.qmCZP9S1rMAoqVE7eTuZSI-uQgA |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '\\..\\vendor\\autoload.php'; | ||
|
||
use Dotenv\Dotenv; | ||
use Ourted\Bot; | ||
|
||
class Ourted extends Bot | ||
{ | ||
|
||
public $token; | ||
|
||
public function __construct() | ||
{ | ||
$dotenv = Dotenv::createImmutable(__DIR__ . '/../'); | ||
$dotenv->load(); | ||
$this->token = $_ENV['BOT_TOKEN']; | ||
parent::__construct($this->token); | ||
$this->setBot(); | ||
} | ||
|
||
public function setBot() | ||
{ | ||
// Ready Event Listener | ||
$this->addListener( | ||
"EventListener" | ||
); | ||
echo "Hello World\n"; | ||
$this->run(); | ||
} | ||
} | ||
|
||
class EventListener extends \Ourted\Interfaces\EventListener | ||
{ | ||
|
||
public function onMessageCreate($json, $bot) | ||
{ | ||
/* | ||
Content: $json->content | ||
Author Username: $json->author->username | ||
Author Discriminator: $json->author->discriminator | ||
Author ID: $json->author->id | ||
*/ | ||
|
||
if(isset($json->author->bot)){ | ||
return; | ||
} | ||
$this->func->sendMessage("Message Sended! By: <@{$json->author->id}>, Content: {$json->content}", $json->channel_id); | ||
} | ||
|
||
|
||
} | ||
|
||
new Ourted(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,106 @@ | ||
## Ourted: A Discord bot in PHP | ||
|
||
The `Ourted` library provides a long-running bot process written in PHP. | ||
The `Ourted` library provides a running bot process written in PHP. | ||
|
||
### Installation | ||
|
||
``` | ||
git clone git@github.com:GianC-Dev/Ourret.git | ||
composer install | ||
composer require ourted/ourted | ||
``` | ||
|
||
Copy the `.env.dist` file to `.env` and configure it with your bot's token. | ||
Edit ``.env`` and configure bot token | ||
|
||
### Usage | ||
### Examples | ||
Without Event Listener | ||
```php | ||
<?php | ||
|
||
``` | ||
php bin/dbot.php | ||
``` | ||
require_once __DIR__ . '\\..\\vendor\\autoload.php'; | ||
|
||
use Dotenv\Dotenv; | ||
use Ourted\Bot; | ||
|
||
class Ourted extends Bot | ||
{ | ||
|
||
### Adding a Dispatch action | ||
public $token; | ||
|
||
public function __construct() | ||
{ | ||
$dotenv = Dotenv::createImmutable(__DIR__ . '/../'); | ||
$dotenv->load(); | ||
$this->token = $_ENV['BOT_TOKEN']; | ||
parent::__construct($this->token); | ||
$this->setBot(); | ||
} | ||
|
||
public function setBot() | ||
{ | ||
echo "Hello World\n"; | ||
$this->run(); | ||
} | ||
} | ||
|
||
new Ourted(); | ||
?> | ||
``` | ||
|
||
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`: | ||
With Event Listener | ||
|
||
```php | ||
<?php | ||
$bot = new Bot($_ENV['BOT_TOKEN']); | ||
|
||
$bot->addDispatch('GUILD_CREATE', function($json) { | ||
echo 'guild create!!!!'."\n"; | ||
require_once __DIR__ . '\\..\\vendor\\autoload.php'; | ||
|
||
use Dotenv\Dotenv; | ||
use Ourted\Bot; | ||
|
||
class Ourted extends Bot | ||
{ | ||
|
||
public $token; | ||
|
||
public function __construct() | ||
{ | ||
$dotenv = Dotenv::createImmutable(__DIR__ . '/../'); | ||
$dotenv->load(); | ||
$this->token = $_ENV['BOT_TOKEN']; | ||
parent::__construct($this->token); | ||
$this->setBot(); | ||
} | ||
|
||
public function setBot() | ||
{ | ||
// Ready Event Listener | ||
$this->addListener( | ||
"EventListener" | ||
); | ||
echo "Hello World\n"; | ||
$this->run(); | ||
} | ||
} | ||
|
||
class EventListener extends \Ourted\Interfaces\EventListener | ||
{ | ||
|
||
public function onMessageCreate($json, $bot) | ||
{ | ||
/* | ||
Content: $json->content | ||
Author Username: $json->author->username | ||
Author Discriminator: $json->author->discriminator | ||
Author ID: $json->author->id | ||
*/ | ||
|
||
if(isset($json->author->bot)){ | ||
return; | ||
} | ||
$this->func->sendMessage("Message Sended! By: <@{$json->author->id}>, Content: {$json->content}", $json->channel_id); | ||
} | ||
|
||
|
||
return 'test'; | ||
}); | ||
} | ||
|
||
$bot->init(); | ||
new Ourted(); | ||
?> | ||
``` |
Oops, something went wrong.