ghost-discord / ghost

🤖 A modular, multi-feature Discord bot
GNU General Public License v3.0
23 stars 31 forks source link

REST API for ghost2-wrapper #55

Open weakphish opened 3 years ago

weakphish commented 3 years ago

@cbryant02 mentioned exposing a REST API for the GUI wrapper to work through. I'd be happy to take a crack at this if given a little direction/place to start/some basic requirements, since I'm not terribly familiar with the code base beyond what I've contributed in command modules.

zzzowoey commented 3 years ago

As much as I would like to, I haven't had much time on my hands to focus on this project. Here are some basic ideas, though. I'll continue to expand on this as we go.

API outline

Handling events

Communicating events from the bot to the wrapper should be done over a WebSocket. Here's some example payloads.

User 195635151005417472 in guild 175928847299117063 ran g!wikipedia dog

{
    "timestamp": "2020-09-23T18:16:09+00:00",
    "event_type": "command",
    "event_data": {
        "name": "wikipedia",
        "args": { "dog" },
        "user_id": "195635151005417472",
        "guild_id": "175928847299117063"
   }
}

ghost2 made a request to the Wikipedia API for "dog"

{
    "timestamp": "2020-09-23T18:16:10+00:00",
    "event_type": "get",
    "event_data": {
        "url": "https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=dog&utf8=&format=json"
    }
}
Here's a handful of events to start with, including some data to attach to the payload. Type Data Description
command name, args, user_id, guild_id A user invoked a command.
new_operator user_id A user became the bot operator.
music_create guild_id A MusicService was created.
music_queue guild_id, track A MusicService queued a track.
music_destroy guild_id A MusicService was destroyed.
get url A web request to an external API was made.
weakphish commented 3 years ago

I plan on working on this in November, when my semester ends as I pretty much have zero time outside of school. This is assuming nobody else takes up the task, to which they are of course welcome to 🙂