import time
import emoji

# Put your commands here
COMMAND1 = "testing testing"
COMMAND2 = "roger roger"

BLUEON = str("blue on")
BLUEOFF = str("blue off")

REDON = str("red on")
REDOFF = str("red off")

GREENON = str("green on")
GREENOFF = str("green off")

YELLOWON = str("yellow on")
YELLOWOFF = str("yellow off")

CLOCK = str("update clock")
SCRAMBLE = str('scramble the 7')
HACKER = str('hack the 7')

SINGLEREADING = str('light')

def setup():
    import RPi.GPIO as GPIO

    import slackbot_wems.chris.light as lite
    import slackbot_wems.chris.segment7 as segment
    
    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)

    # Pin Setup
    GPIO.setup(17, GPIO.OUT) # BLUE LED
    GPIO.setup(27, GPIO.OUT) # RED LED
    GPIO.setup(5, GPIO.OUT) # GREEN LED
    GPIO.setup(22, GPIO.OUT) # YELLOW LED
    
    GPIO.setup(12, GPIO.OUT) # LDR 

setup = False

# Your handling code goes in this function
def handle_command(command):
    """
        Determine if the command is valid. If so, take action and return
        a response, if necessary.

    """

    if not setup:
        setup_gpio()
        setup = True

    response = ""
    if command.find(COMMAND1) >= 0:
        response = str("Surprise!")    
    elif command.find(COMMAND2) >= 0:
        response = (emoji.emojize('Python\n is\n :thumbs_up: :thumbs_up: :thumbs_up:'))

# Blue LED Commands
    elif command.find(BLUEON) >= 0:
        GPIO.output(17, True)
        response = emoji.emojize("" + "Turning :radio_button: ON...")

    elif command.find(BLUEOFF) >= 0:
        GPIO.output(17, False)
        response = emoji.emojize("" + "Turning :radio_button: OFF...")
    
# Red LED Commands
    elif command.find(REDON) >= 0:
        GPIO.output(27, True)
        response = emoji.emojize("" + "Turning :red_circle: ON...")

    elif command.find(REDOFF) >= 0:
        GPIO.output(27, False)
        response = emoji.emojize("" + "Turning :red_circle: OFF...")
   
# Green LED Commands
    elif command.find(GREENON) >= 0:
        GPIO.output(5, True)
        response = emoji.emojize("" + "Turning :green_apple: ON...")

    elif command.find(GREENOFF) >= 0:
        GPIO.output(5, False)
        response = emoji.emojize("" + "Turning :green_apple: OFF...")
   
# Yellow LED Commands
    elif command.find(YELLOWON) >= 0:
        GPIO.output(22, True)
        response = emoji.emojize("" + "Turning :sunny: ON...")

    elif command.find(YELLOWOFF) >= 0:
        GPIO.output(22, False)
        response = emoji.emojize("" + "Turning :sunny: OFF...")

# 7 Segment Commands
    elif command.find(CLOCK) >= 0:
        print('Updating the clock!')
        response = segment.updateClock()

    elif command.find(SCRAMBLE) >= 0:
        print(emoji.emojize(":egg: There is nothing better than scrambled eggs! :egg:"))
        response = segment.scramble()

    elif command.find(HACKER) >= 0:
        print('Message')
        response = segment.hacker()
    
    elif command.find(SINGLEREADING) >= 0:
        a = lite.printReading()
        a = int(a)
        time.sleep(1)
        print(a)
        response = ('Here is what the LDR Sensor said to me: ' + str(a)) 

    return response


[((32, 4, 32, 26), 'RPi.GPIO.setmode', 'GPIO.setmode', ({(32, 17, 32, 25): 'GPIO.BCM'}, {}), '(GPIO.BCM)', True, 'import RPi.GPIO as GPIO\n'), ((33, 4, 33, 27), 'RPi.GPIO.setwarnings', 'GPIO.setwarnings', ({(33, 21, 33, 26): '(False)'}, {}), '(False)', True, 'import RPi.GPIO as GPIO\n'), ((36, 4, 36, 28), 'RPi.GPIO.setup', 'GPIO.setup', ({(36, 15, 36, 17): '(17)', (36, 19, 36, 27): 'GPIO.OUT'}, {}), '(17, GPIO.OUT)', True, 'import RPi.GPIO as GPIO\n'), ((37, 4, 37, 28), 'RPi.GPIO.setup', 'GPIO.setup', ({(37, 15, 37, 17): '(27)', (37, 19, 37, 27): 'GPIO.OUT'}, {}), '(27, GPIO.OUT)', True, 'import RPi.GPIO as GPIO\n'), ((38, 4, 38, 27), 'RPi.GPIO.setup', 'GPIO.setup', ({(38, 15, 38, 16): '(5)', (38, 18, 38, 26): 'GPIO.OUT'}, {}), '(5, GPIO.OUT)', True, 'import RPi.GPIO as GPIO\n'), ((39, 4, 39, 28), 'RPi.GPIO.setup', 'GPIO.setup', ({(39, 15, 39, 17): '(22)', (39, 19, 39, 27): 'GPIO.OUT'}, {}), '(22, GPIO.OUT)', True, 'import RPi.GPIO as GPIO\n'), ((41, 4, 41, 28), 'RPi.GPIO.setup', 'GPIO.setup', ({(41, 15, 41, 17): '(12)', (41, 19, 41, 27): 'GPIO.OUT'}, {}), '(12, GPIO.OUT)', True, 'import RPi.GPIO as GPIO\n'), ((61, 20, 61, 86), 'emoji.emojize', 'emoji.emojize', ({(61, 34, 61, 85): '"""Python\n is\n :thumbs_up: :thumbs_up: :thumbs_up:"""'}, {}), '("""Python\n is\n :thumbs_up: :thumbs_up: :thumbs_up:""")', False, 'import emoji\n'), ((65, 8, 65, 29), 'RPi.GPIO.output', 'GPIO.output', ({(65, 20, 65, 22): '(17)', (65, 24, 65, 28): '(True)'}, {}), '(17, True)', True, 'import RPi.GPIO as GPIO\n'), ((66, 19, 66, 69), 'emoji.emojize', 'emoji.emojize', ({(66, 33, 66, 68): "'' + 'Turning :radio_button: ON...'"}, {}), "('' + 'Turning :radio_button: ON...')", False, 'import emoji\n'), ((69, 8, 69, 30), 'RPi.GPIO.output', 'GPIO.output', ({(69, 20, 69, 22): '(17)', (69, 24, 69, 29): '(False)'}, {}), '(17, False)', True, 'import RPi.GPIO as GPIO\n'), ((70, 19, 70, 70), 'emoji.emojize', 'emoji.emojize', ({(70, 33, 70, 69): "'' + 'Turning :radio_button: OFF...'"}, {}), "('' + 'Turning :radio_button: OFF...')", False, 'import emoji\n'), ((74, 8, 74, 29), 'RPi.GPIO.output', 'GPIO.output', ({(74, 20, 74, 22): '(27)', (74, 24, 74, 28): '(True)'}, {}), '(27, True)', True, 'import RPi.GPIO as GPIO\n'), ((75, 19, 75, 67), 'emoji.emojize', 'emoji.emojize', ({(75, 33, 75, 66): "'' + 'Turning :red_circle: ON...'"}, {}), "('' + 'Turning :red_circle: ON...')", False, 'import emoji\n'), ((78, 8, 78, 30), 'RPi.GPIO.output', 'GPIO.output', ({(78, 20, 78, 22): '(27)', (78, 24, 78, 29): '(False)'}, {}), '(27, False)', True, 'import RPi.GPIO as GPIO\n'), ((79, 19, 79, 68), 'emoji.emojize', 'emoji.emojize', ({(79, 33, 79, 67): "'' + 'Turning :red_circle: OFF...'"}, {}), "('' + 'Turning :red_circle: OFF...')", False, 'import emoji\n'), ((83, 8, 83, 28), 'RPi.GPIO.output', 'GPIO.output', ({(83, 20, 83, 21): '(5)', (83, 23, 83, 27): '(True)'}, {}), '(5, True)', True, 'import RPi.GPIO as GPIO\n'), ((84, 19, 84, 68), 'emoji.emojize', 'emoji.emojize', ({(84, 33, 84, 67): "'' + 'Turning :green_apple: ON...'"}, {}), "('' + 'Turning :green_apple: ON...')", False, 'import emoji\n'), ((87, 8, 87, 29), 'RPi.GPIO.output', 'GPIO.output', ({(87, 20, 87, 21): '(5)', (87, 23, 87, 28): '(False)'}, {}), '(5, False)', True, 'import RPi.GPIO as GPIO\n'), ((88, 19, 88, 69), 'emoji.emojize', 'emoji.emojize', ({(88, 33, 88, 68): "'' + 'Turning :green_apple: OFF...'"}, {}), "('' + 'Turning :green_apple: OFF...')", False, 'import emoji\n'), ((92, 8, 92, 29), 'RPi.GPIO.output', 'GPIO.output', ({(92, 20, 92, 22): '(22)', (92, 24, 92, 28): '(True)'}, {}), '(22, True)', True, 'import RPi.GPIO as GPIO\n'), ((93, 19, 93, 62), 'emoji.emojize', 'emoji.emojize', ({(93, 33, 93, 61): "'' + 'Turning :sunny: ON...'"}, {}), "('' + 'Turning :sunny: ON...')", False, 'import emoji\n'), ((96, 8, 96, 30), 'RPi.GPIO.output', 'GPIO.output', ({(96, 20, 96, 22): '(22)', (96, 24, 96, 29): '(False)'}, {}), '(22, False)', True, 'import RPi.GPIO as GPIO\n'), ((97, 19, 97, 63), 'emoji.emojize', 'emoji.emojize', ({(97, 33, 97, 62): "'' + 'Turning :sunny: OFF...'"}, {}), "('' + 'Turning :sunny: OFF...')", False, 'import emoji\n'), ((102, 19, 102, 40), 'slackbot_wems.chris.segment7.updateClock', 'segment.updateClock', ({}, {}), '()', True, 'import slackbot_wems.chris.segment7 as segment\n'), ((106, 19, 106, 37), 'slackbot_wems.chris.segment7.scramble', 'segment.scramble', ({}, {}), '()', True, 'import slackbot_wems.chris.segment7 as segment\n'), ((105, 14, 105, 87), 'emoji.emojize', 'emoji.emojize', ({(105, 28, 105, 86): '""":egg: There is nothing better than scrambled eggs! :egg:"""'}, {}), "(':egg: There is nothing better than scrambled eggs! :egg:')", False, 'import emoji\n'), ((110, 19, 110, 35), 'slackbot_wems.chris.segment7.hacker', 'segment.hacker', ({}, {}), '()', True, 'import slackbot_wems.chris.segment7 as segment\n'), ((113, 12, 113, 31), 'slackbot_wems.chris.light.printReading', 'lite.printReading', ({}, {}), '()', True, 'import slackbot_wems.chris.light as lite\n'), ((115, 8, 115, 21), 'time.sleep', 'time.sleep', ({(115, 19, 115, 20): '(1)'}, {}), '(1)', False, 'import time\n')]