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

Reply with random object #9

Open
HarHarLinks opened this issue Apr 14, 2022 · 0 comments
Open

Reply with random object #9

HarHarLinks opened this issue Apr 14, 2022 · 0 comments

Comments

@HarHarLinks
Copy link

For example, let's say I want to the bot to select one out of 2 images when it reads a certain word.

To accomplish this, I tried modelling after samples/random-reaction.yaml, specifically the random filter and combined it with my replymedia template. However, now my selection isn't a basic object anymore, but a dict whose value I need to access.

reactbot/README.md

Lines 29 to 30 in a1e5d2c

The object can contain variables using a custom syntax: All instances of
`$${variablename}` will be replaced with the value matching `variablename`.

This custom syntax does not appear to allow this in any way I tried, such as $${selection.url} or $${selection[url]} or $${selection['url']}.

Next I tried json, at which point I'm limited by having to use " double quotes for each key and value as well as the whole content being a string so the parser does not try to interpret it as yaml object. After failing with the usual escape syntax, I accomplished this by this syntax

content: >
  {"key": "{{selection['value']}}"}

and other ways to access the dict, but again this does not appear to work, the jinja templated parts are simply empty.

Then I tried providing the whole object in the rule's variables and discard the reply field for now, but still failed with errors that I don't understand at this point, like AttributeError: 'CommentedSeq' object has no attribute 'items'.

  1. I would like the custom syntax to support subscription if possible.
  2. Where did I go wrong with jinja? Can you provide an example if this is possible?
  3. Where did I go wrong in my brute force approach? Is this currently possible at all?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant