def witness_match(args): """ Process witness event """ if len(args) != 4: return "Usage: /witness @winner winner_score loser_score", False witness = args[0] match = find_match(paired_matches, args[1]) if match is None: return "That user has no matches which need a witness", False if not match.accepted: return "Match has not been accepted yet", False winner = match.get_player(args[1]) loser = match.get_player() winner_score = int(args[2]) loser_score = int(args[3]) data, valid = csh_create_match(winner, loser, winner_score, loser_score, witness) if not valid: return "Sorry, " + data['error'] + \ " has no or invalid slack id configured. Please visit https://eac.csh.rit.edu/ to link", False response = post("https://" + app.config['SERVER_NAME'] + url_for("create_match"), json=data) if response.status_code != 200: match.add_player(winner) match.add_player(loser) paired_matches.append(match) return json.loads(response.text)['message'], False paired_matches.remove(match) return "Match has been witnessed and recorded", True
def cancel_match(args): """ Process cancel match event """ if len(args) != 1: return "Usage: /cancel", False paired = False match = find_match(unpaired_matches, args[0]) if match is None: match = find_match(paired_matches, args[0]) paired = True if match is None: return "Could not find match to cancel", False if paired: paired_matches.remove(match) else: unpaired_matches.remove(match) return "You have cancelled your challenge", True
def create_match(args): """ Process match creation event """ if len(args) != 2: return "Usage: /challenge @opponent", False if args[0] == args[1]: return "Sorry, you cannot challenge yourself", False if ldap_get_member_slack(args[0]) is None: return "Sorry, you do not have a valid slack id configured. " \ "Please visit https://eac.csh.rit.edu/ to link", False if ldap_get_member_slack(args[1]) is None: return "Sorry, they do not have a valid slack id configured. " \ "Please have them visit https://eac.csh.rit.edu/ to link", False if find_match(paired_matches, args[0]) is not None: return "Sorry, you currently have an ongoing match", False if find_match(unpaired_matches, args[0]) is not None: return "Sorry, you cannot issue multiple challenges. " \ "You must cancel your previous challenge before issuing another", False if find_match(paired_matches, args[1]) is not None: return "Sorry, they already have an ongoing match", False unpaired_matches.append(SlackMatch(args[0], args[1])) return "You have issued a challenge!", True
def accept_match(args): """ Process accept event """ if len(args) != 2: return "Usage: /accept @challenger", False if args[0] == args[1]: return "Sorry, you cannot accept your own challenge" match = find_match(unpaired_matches, args[1]) if match is None: return "You are not currently being challenged", False if match.contains_player(args[0]) is None: return "You are not currently being challenged", False match.accept() paired_matches.append(match) unpaired_matches.remove(match) return "You have accepted the challenge!", True