Skip to content

Instantly share code, notes, and snippets.

@usamadar
Created February 11, 2017 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usamadar/057867579bbc586473824b9367e3d625 to your computer and use it in GitHub Desktop.
Save usamadar/057867579bbc586473824b9367e3d625 to your computer and use it in GitHub Desktop.
from random import randint
# --------------- Helpers that build all of the responses ----------------------
th = []
def populate():
global th
th.append("Some kids pee their name in the snow. Chuck Norris can pee his name into concrete.")
th.append("Chuck Norris doesn't sleep, he waits")
th.append("Chuck Norris calendar goes straight from March 31st to April 2nd. No one fools Chuck Norris.")
th.append("Chuck Norris is the only person in the world that can actually email a roundhouse kick.")
th.append("Chuck Norris' tears cure cancer. Too bad he has never cried.")
th.append("Jesus can walk on water, but Chuck Norris can swim through dry land.")
th.append("Chuck Norris once shot an enemy plane down with his finger by yelling, Bang!")
th.append("Chuck Norris doesn't read books. He stares them down until he gets the information he wants.")
th.append("The quickest way to a man's heart is with Chuck Norris' fist.")
th.append("Chuck Norris once heard that nothing can kill him, so he tracked down nothing and killed it.")
th.append("Chuck Norris makes fire by rubbing 2 ice cubes together.")
th.append("When Chuck Norris was born he drove his mom home from the hospital.")
th.append("Chuck Norris threw a grenade and killed 50 people, then it exploded.")
th.append("Big foot claims he saw Chuck Norris.")
th.append("Chuck Norris can kill two stones with one bird.")
th.append("Chuck Norris can make a happy meal cry.")
th.append("Chuck Norris makes onions cry.")
th.append("Mistakes learn from Chuck Norris")
th.append("Chuck Norris can dial your phone number on the microwave.")
th.append("Chuck Norris doesnt wear a watch. He decides what time it is.")
th.append("The Incredible Hulk is Green because he envies Chuck Norris")
th.append("Chuck Norris recorded a 6 hour vine video and uploaded it in 6 seconds")
th.append("Chuck Norris knows Victoria's secret.")
th.append("When Chuck Norris turned 18, his parents moved out.")
def build_speechlet_response(title, output, card_text, reprompt_text, should_end_session):
return {
'outputSpeech': {
'type': 'PlainText',
'text': output
},
'card': {
'type': 'Simple',
'title': "" + title,
'content': "" + card_text
},
'reprompt': {
'outputSpeech': {
'type': 'PlainText',
'text': reprompt_text
}
},
'shouldEndSession': should_end_session
}
def build_response(session_attributes, speechlet_response):
return {
'version': '1.0',
'sessionAttributes': session_attributes,
'response': speechlet_response
}
# --------------- Functions that control the skill's behavior ------------------
def tellFact():
session_attributes = {}
num = randint(0, len(th) - 1)
fact_num = str(num+1)
card_title = "Chuck Norris Fan Fact #" + fact_num +". "
card_text = th[num]
speech_output = card_title + card_text
should_end_session = True
return build_response(session_attributes, build_speechlet_response(
card_title, speech_output,card_text, "", should_end_session))
def initialize():
return tellFact()
# --------------- Events ------------------
def on_launch(launch_request, session):
populate()
return initialize()
def on_intent(intent_request, session):
intent = intent_request['intent']
intent_name = intent_request['intent']['name']
if intent_name == "TellFact":
return tellFact()
else:
raise ValueError("Invalid intent")
# --------------- Main handler ------------------
def lambda_handler(event, context):
application_id = event['session']['application']['applicationId']
if (application_id != "amzn1.ask.skill.cc041990-0e05-4794-8c7a-8e265ea8dd86"):
raise ValueError("Invalid Application ID")
if event['request']['type'] == "LaunchRequest":
return on_launch(event['request'], event['session'])
elif event['request']['type'] == "IntentRequest":
return on_intent(event['request'], event['session'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment