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

taxon: support custom commands via tags cog #154

Open
synrg opened this issue Jul 15, 2021 · 1 comment
Open

taxon: support custom commands via tags cog #154

synrg opened this issue Jul 15, 2021 · 1 comment
Labels
enhancement New feature or request inat 🍃 iNaturalist cog taxon iNaturalist taxa

Comments

@synrg
Copy link
Collaborator

synrg commented Jul 15, 2021

The tags cog by @phenom4n4n now has Custom Blocks support which allows a developer to create custom commands that call into Dronefly code with a little code snippet like:

[p]tagset block add

import aiohttp

class RandomDuck(tse.Block):
    ACCEPTED_NAMES = ("duck",)

    async def process(self, ctx: tse.Context):
        async with aiohttp.ClientSession() as session:
        async with session.get("https://random-d.uk/api/v2/random") as resp:
            data = await resp.json()
        return data["url"]

return RandomDuck

See full doc here:

https://phen-cogs.readthedocs.io/en/latest/tags/owner_guide.html#custom-blocks

Once dronefly-core work has progressed to the point where it can be split from inatcog into its own package, we could provide various code blocks that do things like return the bionomial for a query, or just a genus, etc. as appropriate for the different kinds of custom command we would like. I understand this would be like this:

[p]tag global add xcsp https://www.xeno-canto.org/species/{binomial:{args}}

Where binomial is one of the ACCEPTED_NAMES for the block defined as per the example above, except importing dronefly-core and doing the actual binomial lookup in the process() method, then returning it with a dash between the genus and epithet, as xcsp requires.

@synrg synrg added enhancement New feature or request inat 🍃 iNaturalist cog taxon iNaturalist taxa labels Jul 15, 2021
@synrg synrg changed the title taxon: support custom commands taxon: support custom commands via tags cog Jul 15, 2021
@synrg
Copy link
Collaborator Author

synrg commented Jul 15, 2021

Note: since the code snippets are actually entered by the bot owner as a command, this enhancement is actually a request to document the command that would implement such a binomial command block, and not actually to produce code that is part of dronefly cog itself. Blockers for this, as mentioned above are:

  • dronefly-core does not yet actually access the API, so that would either have to be done via aiohttp as per phen's example code, or else (preferably) via pyinaturalist
  • dronefly-core needs to be its own package so that the custom block can import it & call into it

TODO: Both jobs should have separate issues filed for them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request inat 🍃 iNaturalist cog taxon iNaturalist taxa
Projects
None yet
Development

No branches or pull requests

1 participant