Skip to content

Instantly share code, notes, and snippets.

@nasamuffin
Created May 26, 2016 23:21
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 nasamuffin/acc69df08a73b14d09a722f9fc573761 to your computer and use it in GitHub Desktop.
Save nasamuffin/acc69df08a73b14d09a722f9fc573761 to your computer and use it in GitHub Desktop.
Grammar-police's logic
import json
import urlparse
import urllib
import re
def lambda_handler(event, context):
text = urlparse.parse_qs(event['postBody'])['text'][0]
username = urlparse.parse_qs(event['postBody'])['user_name'][0]
if username == "slackbot":
print("I don't even listen to myself.")
return
print(text)
# Natalie refuses to believe that in America, the $ comes before the number.
wrongDollars = re.search(r'([\d,]+)\$', text)
if wrongDollars:
return say("I think you mean $" + wrongDollars.group(1) + ".")
sneakPeak = re.search(r'sneak peak', text)
if sneakPeak:
return say('Generally mountains aren\'t very stealthy - did you mean "sneak peek"?')
plainAmazon = re.search(r'www\.amazon\.com([^>]*)', text)
if plainAmazon:
return say("Here's the Amazon Smile link: http://smile.amazon.com" + plainAmazon.group(1))
couldCareLess = re.search(r'could care less', text)
if couldCareLess:
return say("In fact, I have a feeling that you couldn't care less!")
# https://xkcd.com/37/
ass = re.search(r'(\w+)-ass (\w+)', text)
if ass:
return say("More like " + ass.group(1) + " ass-" + ass.group(2) + ", am I right?")
def say(text):
return {"text" : text, "username" : "grammarpolice"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment