def message_react(token, message_id, react_id): global data global valid_tokens global channels try: u_id = decodeToken(token) #check if react_id is valid at the start if react_id != 1: raise ValueError("Invalid react ID!") message = getMessage(message_id) channel = getMessageChannel(message_id) isUserChan(u_id, channel) for react in message["reacts"]: for react_users in react[ "u_ids"]: #check that the user hasn't already reacted if react_users == u_id: raise ValueError( "User already has an active react for this message!") for react in message["reacts"]: if react["react_id"] == react_id: react["u_ids"].append(u_id) #add the reaction return {} message["reacts"].append({ "react_id": react_id, "u_ids": [u_id] }) # genereate the react and ass return {} except ValueError as e: raise e except AccessError as e: raise e
def message_unpin(token, message_id): global data global valid_tokens global channels try: u_id = decodeToken(token) message = getMessage(message_id) channel = getMessageChannel(message_id) isUserChan(u_id, channel) #Will raise error if fails for members in data: if members["u_id"] == u_id: if int(members["permission_id"]) == 1 or int(members["permission_id"]) == 2: #check user is admin ############ ADMIN OR OWNER? if message["is_pinned"]: #check if pinned message["is_pinned"] = False return {} raise ValueError("Message is not pinned!") raise ValueError("User does not have permission to unpin!") except ValueError as e: raise e except AccessError as e: raise e
def message_send(token, channel_id, message): global data global valid_tokens global channels try: u_id = decodeToken(token) channel = getChannel(channel_id) isUserChan(u_id, channel) #Will raise error if fails if len(message) > 1000: raise ValueError( "Message can not be greather than 1000 character limit") elif len(message) == 0: #this appears to be handled by front end... raise ValueError("Message can not be empty") else: return addMessage(channel, message, u_id) except ValueError as e: raise e except AccessError as e: raise e
def message_unreact(token, message_id, react_id): global channels try: u_id = decodeToken(token) #check if react_id is valid at the start if react_id != 1: raise ValueError("Invalid react ID!") channel = getMessageChannel(message_id) message = getMessage(message_id) isUserChan(u_id, channel) #Will raise error if fails for react in message["reacts"]: for react_users in react["u_ids"]: #check that the user hasn't already reacted if react_users == u_id: react["u_ids"].remove(u_id) return {} raise ValueError("User already has no active react for this message!") except ValueError as e: raise e except AccessError as e: raise e