context-mod icon indicating copy to clipboard operation
context-mod copied to clipboard

can i use the name of a check as a template value in an action?

Open wchristian opened this issue 4 years ago • 3 comments

I want to have a bunch of checks that have different rules, but the same action (create a report) and indicate which check they belong to, and i think i could save some space by having the action report template just use the check's name.

wchristian avatar Apr 09 '22 14:04 wchristian

I'm not sure I understand what you are trying to do, could you give me an example configuration with your desired behavior?

You can used named rules to reference defined rules, if this is what you are looking for. The same naming behavior works for rules as well.

FoxxMD avatar Apr 11 '22 13:04 FoxxMD

In short, i'm trying to golf this.

runs:
  - checks:
      - name: dgg Dual Citizen
        kind: comment
        rules:
          - condition: AND
            rules:
              - kind: recentActivity
                window: 30 days
                thresholds: [ { threshold: '>= 6', subreddits: ["destiny"] } ]
              - kind: recentActivity
                window: 30 days
                thresholds: [ { threshold: '>= 6', subreddits: ["vaushv"] } ]
        actions:
          - kind: report
            content: bot report - dgg Dual Citizen
      - name: dgg Hardcore
        kind: comment
        rules:
          - condition: AND
            rules:
              - kind: recentActivity
                window: 30 days
                thresholds: [ { threshold: '>= 6', subreddits: ["destiny"] } ]
              - kind: recentActivity
                window: 30 days
                thresholds: [ { threshold: '>= 1', subreddits: ["vaushv"] } ]
        actions:
          - kind: report
            content: bot report - dgg Hardcore
      - name: dgg Ambassador
        kind: comment
        rules:
          - condition: AND
            rules:
              - kind: recentActivity
                window: 30 days
                thresholds: [ { threshold: '>= 1', subreddits: ["destiny"] } ]
              - kind: recentActivity
                window: 30 days
                thresholds: [ { threshold: '>= 6', subreddits: ["vaushv"] } ]
        actions:
          - kind: report
            content: bot report - dgg Ambassador
      - name: dgg Newbie
        kind: comment
        rules:
          - condition: AND
            rules:
              - kind: recentActivity
                window: 30 days
                thresholds: [ { threshold: '>= 1', subreddits: ["destiny"] } ]
              - kind: recentActivity
                window: 30 days
                thresholds: [ { threshold: '>= 1', subreddits: ["vaushv"] } ]
        actions:
          - kind: report
            content: bot report - dgg Newbie

wchristian avatar Apr 11 '22 14:04 wchristian

Ok, I see what you mean now.

The content rendering function doesn't have access to the check name but I can add that in pretty easily! I'll make sure that gets added for the next release.

In the meantime you can shorten your config somewhat by re-using rules:

runs:
  - checks:
      - name: dgg Dual Citizen
        kind: comment
        rules:
          - condition: AND
            rules:
              - kind: recentActivity
                name: destinySixRecent
                window: '30 days'
                thresholds:
                  - threshold: '>= 6'
                    subreddits:
                      - destiny
              - kind: recentActivity
                name: vaushSixRecent
                window: '30 days'
                thresholds:
                  - threshold: '>= 6'
                    subreddits:
                      - vaushv
        actions:
          - kind: report
            content: bot report - dgg Dual Citizen
      - name: dgg Hardcore
        kind: comment
        rules:
          - condition: AND
            rules:
              - destinySixRecent
              - kind: recentActivity
                name: vaushOneRecent
                window: '30 days'
                thresholds:
                  - threshold: '>= 1'
                    subreddits:
                      - vaushv
        actions:
          - kind: report
            content: bot report - dgg Hardcore
      - name: dgg Ambassador
        kind: comment
        rules:
          - condition: AND
            rules:
              - kind: recentActivity
                name: destinyOneRecent
                window: '30 days'
                thresholds:
                  - threshold: '>= 1'
                    subreddits:
                      - vaushv
              - vaushSixRecent
        actions:
          - kind: report
            content: bot report - dgg Ambassador
      - name: dgg Newbie
        kind: comment
        rules:
          - condition: AND
            rules:
              - destinyOneRecent
              - vaushOneRecent
        actions:
          - kind: report
            content: bot report - dgg Newbie

P.S. you can write the whole config in JSON if you are more familiar with that ;)

FoxxMD avatar Apr 11 '22 17:04 FoxxMD

Suggested by @CuriousLyz -- add {{subreddit}} to template

FoxxMD avatar Aug 25 '22 02:08 FoxxMD

hey @wchristian ! Sorry this is so late but you can now use {{check}} to get the check name. This is in the edge branch now and I'll do a release next week. You would use it like this:

actions:
          - kind: report
            content: {{check}}

You could also re-use the action if you named it, like this:

checks:
  - name: myCheck
    #...
    actions:
      - name: reportCheck
        kind: report
        content: {{check}}
        
  - name: mySecondCheck
    #...
    actions:
      - reportCheck

FoxxMD avatar Aug 26 '22 17:08 FoxxMD

Available in 0.12.1

FoxxMD avatar Sep 01 '22 13:09 FoxxMD

my own work has been very busy, but i want you to know i appreciate this :)

wchristian avatar Oct 03 '22 12:10 wchristian