Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Discord relay #2

Open
divinity76 opened this issue Oct 26, 2016 · 1 comment
Open

add Discord relay #2

divinity76 opened this issue Oct 26, 2016 · 1 comment

Comments

@divinity76
Copy link
Owner

No description provided.

@divinity76
Copy link
Owner Author

divinity76 commented Nov 15, 2016

very crude code i made for playing with discord API (which works, just replace the IJIFJQIUUIJFQFAKEFAKEFAKEFAKE.Cwm9rQ.IJIFJQIUUIJFQFAKEFAKEFAKEFAKE with a real token, and 209972668449947648 with the channel you're interested in) :

<?php
declare(strict_types = 1);
require_once ('hhb_.inc.php');
define ( 'BASE_URL', 'https://discordapp.com/api', true );
$dbot = new DiscordBot ();
$dbot->postMessage ( "@takeoded#1532 test" );
$dbot->postMessage ( "@takeoded test" );

class DiscordBot {
    private $hc = NULL;
    private $data;
    function __construct() {
        $hc = &$this->hc;
        $hc = new hhb_curl ();
        $hc->_setComfortableOptions ();
        $hc->setopt_array ( array (
                CURLOPT_TIMEOUT => 18,
                CURLOPT_CONNECTTIMEOUT => 17,
                CURLOPT_USERAGENT => 'trolling (http://shadowfied.com/ , 1.0)'
        ) );

        $postjson = json_encode ( array (
                'name' => 'wat',
                'avatar' => file_get_contents ( 'avatar.b64' )
        ) );

        $hc->setopt_array ( array (
                CURLOPT_POST => true,
                CURLOPT_HTTPHEADER => array (
                        'Authorization: Bot IJIFJQIUUIJFQFAKEFAKEFAKEFAKE.Cwm9rQ.IJIFJQIUUIJFQFAKEFAKEFAKEFAKE',
                        'Accept: application/json',
                        'Content-Type: application/json'
                ),
                //
                CURLOPT_POSTFIELDS => $postjson
        ) );
        $url = BASE_URL . '/channels/209972668449947648/webhooks';
        $hc->exec ( $url );
        $this->data = json_decode ( $hc->getResponseBody (), true );
        hhb_var_dump ( $hc->getResponseBody (), $this->data, $url );
    }
    function postMessage(string $message) {
        // POST
        $hc = &$this->hc;
        $postdata = array (
                'content' => $message,
                'tts' => true
        );
        $postjson = json_encode ( $postdata );
        $hc->setopt_array ( array (
                CURLOPT_POST => true,
                CURLOPT_HTTPHEADER => array (
                        'Authorization: Bot IJIFJQIUUIJFQFAKEFAKEFAKEFAKE.Cwm9rQ.IJIFJQIUUIJFQFAKEFAKEFAKEFAKE',
                        'Accept: application/json',
                        'Content-Type: application/json'
                ),
                //
                CURLOPT_POSTFIELDS => $postjson
        ) );
        echo "POSTING MESSAGE";
        $url = BASE_URL . '/webhooks/' . $this->data ['id'] . '/' . $this->data ['token'];
        $hc->exec ( $url );
        hhb_var_dump ( $hc->getResponseBody (), $hc->getResponseHeaders (), $url );
    }
    function __destruct() {
        echo "destructing...";
        $hc = &$this->hc;
        $hc->setopt_array ( array (
                CURLOPT_CUSTOMREQUEST => 'DELETE',
                CURLOPT_HTTPHEADER => array (
                        'Authorization: Bot IJIFJQIUUIJFQFAKEFAKEFAKEFAKE.Cwm9rQ.IJIFJQIUUIJFQFAKEFAKEFAKEFAKE',
                        'Accept: application/json',
                        'Content-Type: application/json'
                ),
                CURLOPT_POSTFIELDS => json_encode ( array () )
        ) );
        $url = BASE_URL . '/webhooks/' . $this->data ['id'];
        $hc->exec ( $url );
        hhb_var_dump ( $hc->getResponseBody (), $url );
    }
}

(and it was written and tested in a hurry too, thus the ugly global define)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant