Condition trees

DMDirc logo

This page was written for DMDirc version 0.6.

The contents may not be applicable to earlier or later versions.

Introduction

Condition trees allow you to control the way in which action conditions are checked once an action has been triggered. You may specify that some specific conditions must be succeed, some must fail, or a combination of the two. Condition trees are specified in the Action Editor Dialog, which also allows you to select between two default condition trees — one which requires every condition to succeed, and one that only requires that one (or more) succeeds.

Syntax

Condition trees consist of several parts:

  • Condition identifiers are numbers, starting at 0, which refer to the status of a condition.
  • Brackets allow you to control the order in which a tree is evaluated
  • Operators apply boolean functions to identifiers or brackets

There are three operators:

  • Not (!) negates the following identifier or bracket, e.g. !3 will evaluate to true if condition 3 evaluates to false
  • And (&) returns true if both of its operands evaluate to true, e.g. 3&4 will be true if both condition 3 and 4 are true
  • Or (|) returns true if either of its operands is true, e.g. 3|4 will return true if condition 3 is true, condition 4 is true, or both are true.

If there are no brackets to indicate otherwise, DMDirc reads conditions from left to right. When writing condition trees, DMDirc always adds brackets around and and or operations to avoid ambiguity. Whitespace is ignored when reading in trees, and is never output. For example, 3 | 4 & 5 will be treated (and outputted) as ((3|4)&5).

Examples

The following examples describe an action designed to kick people from a channel for saying certain words. The response and triggers are not relevant to the condition tree and are omitted for brevity.

  • Kick people who say badword1 or badword2 in #goodies
    • Conditions:
      1. Channel name equals #goodies
      2. Message content contains badword1
      3. Message content contains badword2
    • Condition tree: (0&(1|2))

  • Kick anyone who says badword unless their nickname is boss1 and the channel is #boss
    • Conditions:
      1. Message content contains badword
      2. User nickname equals boss1
      3. Channel name equals #boss
    • Condition tree: (0&!(1&2))

  • Kick anyone who says word1 or word2, but not both
    • Conditions:
      1. Message content contains word1
      2. Message content contains word2
    • Condition tree: (0|1)&!(0&1)

Useful constructs

Condition trees only allow the three operators described above (and, or and not), but these can be combined to have the same effect as any other boolean operator. This section lists these operators and their equivalent using only and, or and not operators. The examples use 0 and 1 for the operands, substitute your condition numbers as appropriate.

Operator Description Equivalent
XOR Exclusive or Exactly one operand must be true ((0|1)&!(0&1))
NOR Not or Both operands must be false (!0&!1)
NAND Not and Either one or neither of the operands can be true, but not both. !(0&1)
XNOR Exclusive not or Both or neither of the operands must be true ((!0|1)&(0|!1))
Implication If the left operand is true then the right must be (!0|1)
 
documentation/actions/conditiontrees.txt · Last modified: 2010/01/05 19:57 (external edit)