bclindner / valerius

Modular Discord bot based on discordgo.
GNU General Public License v3.0
0 stars 0 forks source link

Generic RESTCommand #1

Closed bclindner closed 5 years ago

bclindner commented 5 years ago

A generic command to hit REST endpoints would be helpful. General design might involve a config like this:

{
  "commands": [
    {
      "name": "Pokedex",
      "type": "REST",
      "options": {
        "trigger": "^!pokemon ([A-Za-z]+)$",
        "endpoint": [
          "https://pokeapi.co/api/v2/pokemon/%s/",
          1,
        ],
        "response": [
          "#%d %s: %s",
          "id",
          "name",
          "sprites.front_default"
        ]
      }
    }
  ]
}

Basically you give it a regex trigger string and it constructs the endpoint based on the groups in that regex in a printf style, where every argument after the first is a number corresponding to a regex group. Then a response can be constructed with a similar array, where every argument after the first is a string corresponding to a key in the API.

This would be extremely tricky to implement acceptably, so some redesign may be needed.

The currently-existing XKCDCommand could hopefully be re-implemented as a RESTCommand.

bclindner commented 5 years ago

Still entertaining the idea. The GJSON library seems perfect for the dot-notation stuff and is popular and supported, but I'm skeptical of relying on any more third party libraries than I already have.

bclindner commented 5 years ago

Done in commit 6d0de73. A little buggy, needs work.