Skip to content

Commit

Permalink
Update | Beta 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gncdev committed Aug 7, 2020
1 parent 4cfaf59 commit 585c329
Show file tree
Hide file tree
Showing 17 changed files with 647 additions and 1,782 deletions.
2 changes: 1 addition & 1 deletion .env
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
2 changes: 1 addition & 1 deletion .idea/Ourted.iml

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

194 changes: 157 additions & 37 deletions .idea/workspace.xml

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions Example.php
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();
101 changes: 85 additions & 16 deletions README.md
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();
?>
```
Loading

0 comments on commit 585c329

Please sign in to comment.