def index(): if not request.args: message = """ Welcome to SlackTeX! Check me out on <a href="https://github.com/nicolewhite/slacktex">GitHub</a>. """ return message slack = Slack() token = request.args["token"] latex = request.args["text"] channel_id = request.args["channel_id"] user_id = request.args["user_id"] if token != slack.SLASH_COMMAND_TOKEN: return "Unauthorized." latex = quote(latex) latex_url = "http://chart.apis.google.com/chart?cht=tx&chl={latex}".format(latex=latex) payload = {"channel": channel_id} user = slack.find_user_info(user_id) payload.update(user) attachments = [{"image_url": latex_url, "fallback": "Oops. Something went wrong."}] payload.update({"attachments": attachments}) slack.post_latex_to_webhook(payload) return "Success!", 200
def meme(): if not request.args: message = """ Welcome to Slack Meme! Check me out on <a href="https://github.com/nicolewhite/slack-meme">GitHub</a>. """ return message memegen = Memegen() memeifier = Memeifier() slack = Slack() token = request.args["token"] text = request.args["text"] channel_id = request.args["channel_id"] user_id = request.args["user_id"] if token != slack.SLASH_COMMAND_TOKEN: return "Unauthorized." if text.strip() == "": return memegen.error() if text[:9] == "templates": return memegen.list_templates() preview = True if text[:7] == "preview" else False text = text.replace("preview", "", 1) if preview else text template, top, bottom = parse_text_into_params(text) valid_templates = [x[0] for x in memegen.get_templates()] if template in valid_templates: meme_url = memegen.build_url(template, top, bottom) elif memeifier.image_exists(template): meme_url = memeifier.build_url(template, top, bottom) else: return memegen.error() if preview: return meme_url payload = {"channel": channel_id} user = slack.find_user_info(user_id) payload.update(user) attachments = [{ "image_url": meme_url, "fallback": "Oops. Something went wrong." }] payload.update({"attachments": attachments}) try: slack.post_meme_to_webhook(payload) except Exception as e: return e return "Success!", 200
def meme(): if not request.args: message = """ Welcome to Slack Meme! Check me out on <a href="https://github.com/nicolewhite/slack-meme">GitHub</a>. """ return message memegen = Memegen() memeifier = Memeifier() slack = Slack() token = request.args["token"] text = request.args["text"] channel_id = request.args["channel_id"] user_id = request.args["user_id"] if token != slack.SLASH_COMMAND_TOKEN: return "Unauthorized." if text.strip() == "": return memegen.error() if text[:9] == "templates": return memegen.list_templates() preview = True if text[:7] == "preview" else False text = text.replace("preview", "", 1) if preview else text template, top, bottom = parse_text_into_params(text) valid_templates = [x[0] for x in memegen.get_templates()] if template in valid_templates: meme_url = memegen.build_url(template, top, bottom) elif memeifier.image_exists(template): meme_url = memeifier.build_url(template, top, bottom) else: return memegen.error() print(meme_url) if preview: return meme_url payload = {"channel": channel_id} user = slack.find_user_info(user_id) payload.update(user) attachments = [{"image_url": meme_url, "fallback": "Oops. Something went wrong."}] payload.update({"attachments": attachments}) try: slack.post_meme_to_webhook(payload) except Exception as e: return e return "Success!", 200
def meme(): if not request.args: message = """ Welcome to Slack Meme! Check me out on <a href="https://github.com/nicolewhite/slack-meme">GitHub</a>. """ return message memegen = Memegen() memeifier = Memeifier() slack = Slack() token = request.args["token"] text = request.args["text"] channel_id = request.args["channel_id"] user_id = request.args["user_id"] if token != slack.SLASH_COMMAND_TOKEN: return "Unauthorized." if text[:9] == "templates": return memegen.get_help() preview = True if text[:7] == "preview" else False text = text.replace("preview", "", 1) if preview else text template, top, bottom = parse_text_into_params(text) valid_templates = [x[0] for x in memegen.get_templates()] if template in valid_templates: meme_url = memegen.build_url(template, top, bottom) elif memeifier.image_exists(template): meme_url = memeifier.build_url(template, top, bottom) else: return "That template doesn't exist. Type `/meme templates` to see valid templates or provide your own as a URL." if preview: return meme_url payload = {"text": meme_url, "channel": channel_id} user = slack.find_user_info(user_id) payload.update(user) try: slack.post_meme_to_webhook(payload) except Exception as e: return e return "Success!", 200
def meme(): if not request.args: message = """ Welcome to Slack Meme! Check me out on <a href="https://github.com/nicolewhite/slack-meme">GitHub</a>. """ return message memegen = Memegen() memeifier = Memeifier() slack = Slack() token = request.args["token"] text = request.args["text"] channel_id = request.args["channel_id"] user_id = request.args["user_id"] if token != slack.SLASH_COMMAND_TOKEN: return "Unauthorized." if text[:9] == "templates": return memegen.get_help() preview = True if text[:7] == "preview" else False text = text.replace("preview", "", 1) if preview else text template, top, bottom = parse_text_into_params(text) valid_templates = [x[0] for x in memegen.get_templates()] if template in valid_templates: meme_url = memegen.build_url(template, top, bottom) elif memeifier.image_exists(template): meme_url = memeifier.build_url(template, top, bottom) else: return "That template doesn't exist. Type `/meme templates` to see valid templates or provide your own as a URL." if preview: return meme_url payload = {"text": meme_url, "channel": channel_id} user = slack.find_user_info(user_id) payload.update(user) try: slack.post_meme_to_webhook(payload) except Exception as e: return e return "Success!", 200
def meme(): memegen = Memegen() slack = Slack() if not request.args: return memegen.help() token = request.args["token"] text = request.args["text"].strip() channel_id = request.args["channel_id"] user_id = request.args["user_id"] if token != slack.SLASH_COMMAND_TOKEN: return "Unauthorized." if text.lower() in ("help", ""): return memegen.help() if text.lower() == "templates": return memegen.list_templates() try: template, top, bottom = parse_text_into_params(text) except ValueError: return "Bad command: `%s`\n" % text + memegen.help() valid_templates = [x[0] for x in memegen.get_templates()] if template in valid_templates: meme_url = memegen.build_url(template, top, bottom) elif image_exists(template): meme_url = memegen.build_url("custom", top, bottom, template) else: return memegen.bad_template(template) payload = {"channel": channel_id} user = slack.find_user_info(user_id) payload.update(user) attachments = [{"image_url": meme_url, "fallback": "; ".join([top, bottom])}] payload.update({"attachments": attachments}) try: slack.post_meme_to_webhook(payload) except Exception as e: return e return "Success!", 200
def index(): if not request.args: message = """ Welcome to SlackTeX! Check me out on <a href="https://github.com/nicolewhite/slacktex">GitHub</a>. """ return message slack = Slack() token = request.args["token"] latex = request.args["text"] channel_id = request.args["channel_id"] user_id = request.args["user_id"] if token != slack.SLASH_COMMAND_TOKEN: return "Unauthorized." asciify = { u'\u201c': '"', u'\u201d': '"', u'\u2018': "'", u'\u2019': "'", u'\u2026': "...", } for unicodeChar, asciiReplacement in asciify.iteritems(): latex = latex.replace(unicodeChar, asciiReplacement) latex = quote(latex.encode("utf-8")) latex_url = "http://chart.apis.google.com/chart?cht=tx&chl={latex}".format( latex=latex) payload = {"channel": channel_id} user = slack.find_user_info(user_id) payload.update(user) attachments = [{ "image_url": latex_url, "fallback": "Oops. Something went wrong." }] payload.update({"attachments": attachments}) slack.post_latex_to_webhook(payload) return "", 200
def meme(): memegen = Memegen() slack = Slack() if not request.args: return memegen.help() token = request.args["token"] text = request.args["text"].strip() channel_id = request.args["channel_id"] user_id = request.args["user_id"] if token != slack.SLASH_COMMAND_TOKEN: return "Unauthorized." if text.lower() in ("help", ""): return memegen.help() if text.lower() == "templates": return memegen.list_templates() template, top, bottom = parse_text_into_params(text) valid_templates = [x[0] for x in memegen.get_templates()] if template in valid_templates: meme_url = memegen.build_url(template, top, bottom) elif image_exists(template): meme_url = memegen.build_url("custom", top, bottom, template) else: return memegen.bad_template(template) payload = {"channel": channel_id} user = slack.find_user_info(user_id) payload.update(user) attachments = [{"image_url": meme_url, "fallback": "; ".join([top, bottom])}] payload.update({"attachments": attachments}) try: slack.post_meme_to_webhook(payload) except Exception as e: return e return "Success!", 200
def meme(): memegen = Memegen() memeifier = Memeifier() slack = Slack() token = request.args["token"] text = request.args["text"] channel_id = request.args["channel_id"] user_id = request.args["user_id"] if token != slack.SLASH_COMMAND_TOKEN: return "Unauthorized." if text[:9] == "templates": return memegen.get_help() if text[:9] == "list": return memegen.get_help() template, top, bottom = parse_text_into_params(text) valid_templates = [x[0] for x in memegen.get_templates()] if template in valid_templates: meme_url = memegen.build_url(template, top, bottom) elif memeifier.image_exists(template): meme_url = memeifier.build_url(template, top, bottom) else: return "That template doesn't exist. Type `/meme list` to see valid templates or provide your own as a URL." payload = { "channel": channel_id, "attachments": [{ "text": "", "fields": [{ "text": "" }], "image_url": meme_url }] } user = slack.find_user_info(user_id) payload.update(user) slack.post_meme_to_webhook(payload) return "Success!", 200
def index(): if not request.args: message = """ Welcome to SlackTeX! Check me out on <a href="https://github.com/nicolewhite/slacktex">GitHub</a>. """ return message slack = Slack() token = request.args["token"] latex = request.args["text"] channel_id = request.args["channel_id"] user_id = request.args["user_id"] if token != slack.SLASH_COMMAND_TOKEN: return "Unauthorized." asciify = { u'\u201c': '"', u'\u201d': '"', u'\u2018': "'", u'\u2019': "'", u'\u2026': "...", } for unicodeChar, asciiReplacement in asciify.iteritems(): latex = latex.replace(unicodeChar, asciiReplacement) latex = quote(latex.encode("utf-8")) latex_url = "http://chart.apis.google.com/chart?cht=tx&chl={latex}".format(latex=latex) payload = {"channel": channel_id} user = slack.find_user_info(user_id) payload.update(user) attachments = [{"image_url": latex_url, "fallback": "Oops. Something went wrong."}] payload.update({"attachments": attachments}) slack.post_latex_to_webhook(payload) return "", 200
def meme(): meme = Memegen() slack = Slack() token = request.args["token"] if token != slack.SLASH_COMMAND_TOKEN: return "Unauthorized." text = request.args["text"] if text[:9] == "templates": return meme.get_help() try: template, top, bottom = meme.parse_text_into_params(text) except: return "Your syntax should be in the form `/meme [template]; [top]; [bottom];. Type `/meme templates` to see valid templates." valid_templates = [x["name"] for x in meme.get_templates()] if template not in valid_templates: return "That template doesn't exist. Type `/meme templates` to see valid templates." meme_url = meme.build_url(template, top, bottom) channel_id = request.args["channel_id"] payload = {"text": meme_url, "channel": channel_id} user_id = request.args["user_id"] user = slack.find_user_info(user_id) payload.update(user) slack.post_meme_to_webhook(payload) return "Success!", 200
def meme(): if not request.args: message = """ Welcome to Slack Meme! Check me out on <a href="https://github.com/nicolewhite/slack-meme">GitHub</a>. """ return message memegen = Memegen() slack = Slack() token = request.args["token"] text = request.args["text"] channel_id = request.args["channel_id"] user_id = request.args["user_id"] if token != slack.SLASH_COMMAND_TOKEN: return "Unauthorized." if text.strip() == "": return memegen.error() if text[:9] == "templates": return memegen.list_templates() if text[:6] == "search": command, search, ignore = parse_text_into_params(text) return memegen.search_templates(search) if text[:9] == "shortcuts": return memegen.list_shortcuts() if text[:6] == "create": name, url, description = parse_text_into_params(text) if name and url: set_shortcut(name, url, description) return "Success! Now you can use it with: `/meme %s;<top>;<bottom>`" % (name) else: return "You need to pass name and url at least to create a shortcut: `/meme create;<name>;<url>;<description>`" template, top, bottom = parse_text_into_params(text) templates_not_shortcuts = [t[0] for t in memegen.get_templates() if not t[3]] if template in templates_not_shortcuts: meme_url = memegen.build_url(template, top, bottom) elif get_shortcut(template): meme_url = memegen.build_url("custom", top, bottom, get_shortcut(template)) print meme_url elif image_exists(template): print template meme_url = memegen.build_url("custom", top, bottom, template) print meme_url else: return memegen.error() payload = {"channel": channel_id} user = slack.find_user_info(user_id) payload.update(user) attachments = [{"image_url": meme_url, "fallback": "Oops. Something went wrong."}] payload.update({"attachments": attachments}) try: slack.post_meme_to_webhook(payload) except Exception as e: return e return "Success!", 200