FoxxMD / context-mod

an event-based, reddit moderation bot built on top of snoowrap and written in typescript
https://contextmod.dev
MIT License
49 stars 11 forks source link

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

Closed wchristian closed 1 year ago

wchristian commented 2 years ago

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.

FoxxMD commented 2 years ago

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.

wchristian commented 2 years ago

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
FoxxMD commented 2 years ago

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 commented 1 year ago

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

FoxxMD commented 1 year ago

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 commented 1 year ago

Available in 0.12.1

wchristian commented 1 year ago

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