Skip to content

Instantly share code, notes, and snippets.

@ajeetraina
Created October 1, 2021 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajeetraina/30462b027cb3453061edc206677e9776 to your computer and use it in GitHub Desktop.
Save ajeetraina/30462b027cb3453061edc206677e9776 to your computer and use it in GitHub Desktop.
Leave Game Function
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