def reports(): if not verify_request(request): return make_response("", 400) active_reports = Report.query.all() reports = [] for r in active_reports: if len(reports) >= 10: break anon_msg = utils.get_anon_message_from_id(r.msg_id) report_entry = get_block_view("views/reports/report_entry.json") report_entry = report_entry.replace("{REPORT_ID}", str(r.id)) report_entry = report_entry.replace("{REPORT_CONTENT}", r.report) report_entry = report_entry.replace("{User 1}", anon_msg.user_id) report_entry = report_entry.replace("{User 2}", anon_msg.target_id) report_entry = report_entry.replace("{REPORTED_AT}", "No report time" if r.reported_at is None else r.reported_at.strftime( "%B %d, %Y, %H:%M:%S%z")) reports.append(report_entry) reports_string = ",".join(reports) if len(reports) > 0: reports_string += "," response = get_block_view("views/reports/report_message.json") response = response.replace("{REPORTS}", reports_string) response = response.replace("{NUM_REPORTS}", str(len(reports))) return Response(response, mimetype='application/json')
def pair(): if not verify_request(request): return make_response("", 400) payload = request.form.to_dict() if retrieve_highest_permission_level(payload["user_id"]) < UserRoles.MOD: min_title = get_role_title(UserRoles.MOD) return make_response("You do not have permission to run /pair." " You require at least {} privileges to run /pair".format(min_title), 200) member_ids = client.conversations_members(channel=payload["channel_id"])["members"] groupings = [] current_group = [] for member_id in member_ids: current_group.append(member_id) if len(current_group) == app.config["PAIR_GROUP_SIZE"]: groupings.append(current_group) current_group = [] if len(current_group) > 0: index = -1 if len(groupings) > 0 else 0 groupings[index].extend(current_group) message = "Pairing Success Groups are:\n\n" for i, group in enumerate(groupings): message += "Group {}:\n".format(i + 1) message += "\n".join(group) message += "\n\n" return make_response(message, 200)
def stylecheck(): if not verify_request(request): return make_response("", 400) payload = request.form.to_dict() payload = payload['text'].split(' ') return make_response("Pair success", 200)
def slack_review(): if not verify_request(request): return make_response("", 400) # TODO: verify that the course given is valid # TODO: normalise the course argument e.g. math3611 -> MATH3611, mAth3611 -> MATH3611 # TODO: add in a multi-select menu feature to the review modal if a course argument is omitted review_init(request.form.get('user_id'), request.form.get('text')) review_modal(request.form.get('trigger_id'), request.form.get('text'), request.form.get('user_id')) return make_response("", 200)
def events(): """ Display a list of events using linkup Usage: /events <cse | unsw> [page number] """ # Verify request if not utils.verify_request(request): return make_response("", 400) # Parse request payload = request.form.to_dict() # Spawn a thread to service the request threading.Thread(target=handler.events, args=[payload]).start() return make_response("", 200)
def say(): """ Say something as the slackbot. Usage: /say message """ # Verify request if not utils.verify_request(request): return make_response("", 400) # Parse request payload = request.form.to_dict() # Spawn a thread to service the request threading.Thread(target=handler.say, args=[payload]).start() return make_response("", 200)
def cs_job_opportunities(): """ Lets you know about CS job opportunities from indeed Usage: /CSopportunities [OPTIONS, page_number=1, query="software internship"] """ # Verify request if not utils.verify_request(request): return make_response("", 400) # Parse request payload = request.form.to_dict() # Spawn a thread to service the request threading.Thread(target=handler.cs_job_opportunities, args=[payload]).start() return make_response("", 200)
def purge(): """ Mass delete unwanted messages. Usage: /purge <number of messages> [user, time_period, text_snippet] """ # Verify request if not utils.verify_request(request): return make_response("", 400) # Parse request payload = request.form.to_dict() # Spawn a thread to service the request threading.Thread(target=handler.purge, args=[payload]).start() return make_response("", 200)
def interactions(): """ The main route for enabling interactions with shortcuts, modals, or interactive components (such as buttons, select menus, and datepickers). To add an interaction, simply modify the code in the function app.slack_handler.interactions """ # Verify request if not verify_request(request): return make_response("", 400) # Parse request payload = json.loads(request.form.to_dict()["payload"]) if (payload['type'] == "view_submission" and 'trivia_start_' in payload['view']['callback_id']): trigger_id = payload["trigger_id"] try: game_id = payload['view']['callback_id'].replace('trivia_start_', '') trivia_q_number(game_id, int(payload['view']['state']['values']['number_questions']['number_questions']['value'])) trivia_player_list(game_id, payload['view']['state']['values']['users_playing']['users_playing']['selected_users']) if trivia_finalise(game_id, trigger_id): try: with app.app_context(): resp = jsonify({'response_action': 'push', 'view': trivia_customs(game_id, trigger_id)}) resp.headers['Authorization'] = slack_token return resp except Exception as err: print(err) except: trivia_failure(game_id, trigger_id) return make_response("", 200) elif payload['type'] == "view_submission" and 'custom_questions_' in payload['view']['callback_id']: trivia_custom_questions(payload['view']['callback_id'].replace('custom_questions_', ''), payload['view']['state']['values']) # can change if we want to be able to go back to the previous modal but this feels cleaner with app.app_context(): resp = jsonify({'response_action': 'clear'}) resp.headers['Authorization'] = slack_token return resp # Spawn a thread to service the request threading.Thread(target=handler.interactions, args=[payload]).start() return make_response("", 200)
def slack_karma(): if not verify_request(request): return make_response("", 400) karma_message(request.form.get('channel_id')) return make_response("", 200)
def slack_help(): if not verify_request(request): return make_response("", 400) help_modal(request.form.get('trigger_id'), request.form.get('user_id')) return make_response("", 200)