Created
October 1, 2021 08:41
-
-
Save ajeetraina/30462b027cb3453061edc206677e9776 to your computer and use it in GitHub Desktop.
Leave Game Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LeaveGameFunctionBuilder(BaseFunctionBuilder): | |
def __init__(self): | |
super().__init__(command_name='leave_game') | |
def register_command(self): | |
""" | |
Determines best public server to join to. | |
- Removes USER to the ROOM. | |
- Decrements playercount | |
- Publishes a notification | |
Arguments: | |
user, game | |
Returns: | |
None | |
Trigger example: | |
RG.TRIGGER leave_game user1 game1 | |
""" | |
def subcall(user_id, game_id, secret=None): | |
execute("HDEL", f"GAME:{game_id}", f"USER:{user_id}") | |
execute("HINCRBY", f"GAME:{game_id}", "playercount", -1) | |
( | |
GB('CommandReader') | |
.map(lambda x: subcall(*x[1:])) | |
.register(trigger=self.command_name, mode='sync') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment