D

DiscordBot

por poggit-archive
No disponible
HerramientasVariospocketmine
6visitas
0descargas

About

DiscordBot is a pocketmine plugin that provides an extensive API for plugin developers to interact with discord creating endless possibilities.

Please note that this plugin offers no standalone features, It is a central API for external plugins to use/depend on.

such as https://poggit.pmmp.io/p/ChatBridge

API Documentation

Unfortunately its formatting is very weird on poggit please visit https://github.com/DiscordBot-PMMP/DiscordBot/blob/3.0.5/API.md for API documentation

Plugin Structure

This is a very complicated plugin when looked at but its essentially broken down into 4 parts.

(Note this is outdated and needs updating, apologies)

Part 1, The plugin

The plugin interacts directly with the pocketmine server and sets up a child thread to start the connection to discord, its also the section responsible for handling API requests from other plugins and emitting events, providing data etc to other plugins.

Part 2, The thread

This 'discord thread' is responsible for keeping a live connection to discords gateway so we can receive and pass on events back to the plugin base. We also execute API requests sent from the plugin base here and return a result in the near future when discord sends a response to our API request.

Technical note, The thread is completely independent of the Main thread and pocketmine so collisions between my composer dependencies and anything else is impossible.

Part 3, The composer libs

This part is the biggest part of the plugin that works in the background inside the discord thread, It's a collection of third part libraries including DiscordPHP, React libraries, Monolog and much more.

Note you should NEVER be using or even looking at these libraries, they are not registered in the BaseClassLoader.

Part 4, Promise API

The 'face' of the plugin, using a shaded library (https://github.com/reactphp/promise/tree/v2.9.0) the plugin provides a 'promise' API which means plugins can make requests to do certain things like sendMessage or createRole and the plugin will send back a promise.

A promise is sent back because we can't return instantly whether it was a success or not because we have to send it to the Discord Thread which then sends it to discords gateway(/api for some api methods) and then we have to wait for a response then return the response to the plugin/main thread and THEN we can tell you if it was a success or not.

So you can essentially attach functions to the promise to run when we come back quite a few ticks later with a response.

Hard to explain, go read the API tab if your still interested...