|
| 1 | +# PART 4: USER-SPECIFIED TRIGGERS |
| 2 | + |
| 3 | +def makeTrigger(triggerMap, triggerType, params, name): |
| 4 | + """ |
| 5 | + Takes in a map of names to trigger instance, the type of trigger to make, |
| 6 | + and the list of parameters to the constructor, and adds a new trigger |
| 7 | + to the trigger map dictionary. |
| 8 | +
|
| 9 | + triggerMap: dictionary with names as keys (strings) and triggers as values |
| 10 | + triggerType: string indicating the type of trigger to make (ex: "TITLE") |
| 11 | + params: list of strings with the inputs to the trigger constructor (ex: ["world"]) |
| 12 | + name: a string representing the name of the new trigger (ex: "t1") |
| 13 | +
|
| 14 | + Modifies triggerMap, adding a new key-value pair for this trigger. |
| 15 | +
|
| 16 | + Returns a new instance of a trigger (ex: TitleTrigger, AndTrigger). |
| 17 | + """ |
| 18 | + |
| 19 | + if triggerType == "TITLE": |
| 20 | + triggerMap[name] = TitleTrigger(params[0]) |
| 21 | + |
| 22 | + elif triggerType == "SUBJECT": |
| 23 | + triggerMap[name] = SubjectTrigger(params[0]) |
| 24 | + |
| 25 | + elif triggerType == "SUMMARY": |
| 26 | + triggerMap[name] = SummaryTrigger(params[0]) |
| 27 | + |
| 28 | + elif triggerType == "NOT": |
| 29 | + triggerMap[name] = NotTrigger(triggerMap[params[0]]) |
| 30 | + |
| 31 | + elif triggerType == "AND": |
| 32 | + triggerMap[name] = AndTrigger(triggerMap[params[0]], triggerMap[params[1]]) |
| 33 | + |
| 34 | + elif triggerType == "OR": |
| 35 | + triggerMap[name] = OrTrigger(triggerMap[params[0]], triggerMap[params[1]]) |
| 36 | + |
| 37 | + elif triggerType == "PHRASE": |
| 38 | + triggerMap[name] = PhraseTrigger(' '.join(params)) |
| 39 | + return triggerMap[name] |
| 40 | + |
0 commit comments