marvin_general_actions

Make general actions for Marvin, one function for each action.

 1#! /usr/bin/env python3
 2# -*- coding: utf-8 -*-
 3
 4"""
 5Make general actions for Marvin, one function for each action.
 6"""
 7import datetime
 8import random
 9
10lastDateGreeted = None
11
12
13def getAllGeneralActions():
14    """
15    Return all general actions as an array.
16    """
17    return [
18        marvinMorning
19    ]
20
21
22def marvinMorning(row):
23    """
24    Marvin says Good morning after someone else says it
25    """
26    msg = None
27    phrases = [
28        "morgon",
29        "godmorgon",
30        "god morgon",
31        "morrn",
32        "morn"
33    ]
34
35    morning_phrases = [
36        "Godmorgon! :-)",
37        "Morgon allesammans",
38        "Morgon gott folk",
39        "Guten morgen",
40        "Morgon"
41    ]
42
43    global lastDateGreeted
44
45    for phrase in phrases:
46        if phrase in row:
47            if lastDateGreeted != datetime.date.today():
48                lastDateGreeted = datetime.date.today()
49                msg = random.choice(morning_phrases)
50    return msg
lastDateGreeted = None
def getAllGeneralActions():
14def getAllGeneralActions():
15    """
16    Return all general actions as an array.
17    """
18    return [
19        marvinMorning
20    ]

Return all general actions as an array.

def marvinMorning(row):
23def marvinMorning(row):
24    """
25    Marvin says Good morning after someone else says it
26    """
27    msg = None
28    phrases = [
29        "morgon",
30        "godmorgon",
31        "god morgon",
32        "morrn",
33        "morn"
34    ]
35
36    morning_phrases = [
37        "Godmorgon! :-)",
38        "Morgon allesammans",
39        "Morgon gott folk",
40        "Guten morgen",
41        "Morgon"
42    ]
43
44    global lastDateGreeted
45
46    for phrase in phrases:
47        if phrase in row:
48            if lastDateGreeted != datetime.date.today():
49                lastDateGreeted = datetime.date.today()
50                msg = random.choice(morning_phrases)
51    return msg

Marvin says Good morning after someone else says it