def reply_attachments(): if request.form['token'] != SLACK_REPLY_ATTACHMENTS_TOKEN: return ':(' user_id = request.form['user_id'] err, service_name, rest = split_service_name(request.form['text']) if err: return malformed_input_error_message(REPLY_ATTACHMENTS_FORMAT) err, service = lookup_service(service_name) if err: return unknown_social_media_service_error_message(service_name) err, reply_to_url, rest = split_url(rest) if err: return malformed_input_error_message(REPLY_ATTACHMENTS_FORMAT) err, attachments, content = split_attachments(rest) if err: return malformed_input_error_message(REPLY_ATTACHMENTS_FORMAT) action = SocialMediaAction.Reply(service, user_id, reply_to_url, content, attachments) err, message = action.handle() if err: return message log_action_to_slack(action) return ""
def reply(): if request.form['token'] != SLACK_REPLY_TOKEN: return ':(' user_id = request.form['user_id'] err, service_name, rest = split_service_name(request.form['text']) if err: return malformed_input_error_message(REPLY_FORMAT) err, service = lookup_service(service_name) if err: return unknown_social_media_service_error_message(service_name) err, reply_to_url, content = split_url(rest) if err: return malformed_input_error_message(REPLY_FORMAT) attachments = [] action = SocialMediaAction.Reply(service, user_id, reply_to_url, content, attachments) def the_rest(): err, message = action.handle() if err: return message log_action_to_slack(action) return elongate_request(the_rest, "Posting to " + service_name + " ...")
def make(): if request.form['token'] != SLACK_MAKE_TOKEN: return ':(' user_id = request.form['user_id'] err, service_name, content = split_service_name(request.form['text']) if err: return malformed_input_error_message(MAKE_FORMAT) err, service = lookup_service(service_name) if err: return unknown_social_media_service_error_message(service_name) attachments = [] action = SocialMediaAction.Make(service, user_id, content, attachments) action.handle() log_action_to_slack(action) return ""
def share(): if request.form['token'] != SLACK_SHARE_TOKEN: return ':(' user_id = request.form['user_id'] err, service_name, shared_post_url = split_service_name(request.form['text']) if err: return malformed_input_error_message(SHARE_FORMAT) err, service = lookup_service(service_name) if err: return unknown_social_media_service_error_message(service_name) action = SocialMediaAction.Share(service, user_id, shared_post_url) err, message = action.handle() if err: return message log_action_to_slack(action) return ""
def unshare(): if request.form['token'] != SLACK_UNSHARE_TOKEN: return ':(' user_id = request.form['user_id'] err, service_name, unshared_post_url = split_service_name(request.form['text']) if err: return malformed_input_error_message(UNSHARE_FORMAT) err, service = lookup_service(service_name) if err: return unknown_social_media_service_error_message(service_name) action = SocialMediaAction.Unshare(service, user_id, unshared_post_url) def the_rest(): err, message = action.handle() if err: return message log_action_to_slack(action) return elongate_request(the_rest, "Removing from " + service_name + " ...")
def delete(): if request.form['token'] != SLACK_DELETE_TOKEN: return ':(' user_id = request.form['user_id'] err, service_name, deleted_post_url = split_service_name(request.form['text']) if err: return malformed_input_error_message(DELETE_FORMAT) err, service = lookup_service(service_name) if err: return unknown_social_media_service_error_message(service_name) deleted_post_content = "" action = SocialMediaAction.Delete(service, user_id, deleted_post_url, deleted_post_content) err, message = action.handle() if err: return message log_action_to_slack(action) return ""
def make_attachments(): if request.form['token'] != SLACK_MAKE_ATTACHMENTS_TOKEN: return ':(' user_id = request.form['user_id'] err, service_name, rest = split_service_name(request.form['text']) if err: return malformed_input_error_message(MAKE_ATTACHMENTS_FORMAT) err, service = lookup_service(service_name) if err: return unknown_social_media_service_error_message(service_name) err, attachments, content = split_attachments(rest) if err: return malformed_input_error_message(MAKE_ATTACHMENTS_FORMAT) action = SocialMediaAction.Make(service, user_id, content, attachments) def the_rest(): err, message = action.handle() if err: return message log_action_to_slack(action) return elongate_request(the_rest, "Posting to " + service_name + " ...")