async def leave(context: commands.Context, *args): channel_did = str(context.channel.id) game: Game = DatabaseFacade.get_game_by_channel_did(channel_did) if game is not None: if len(args) > 0: await context.send("Usage: !leave") return player_did = str(context.author.id) leaver = DatabaseFacade.get_player_by_did(player_did=player_did) if leaver.id == game.creator_id: await context.send("The creator cannot leave the game; use !delete" " to remove the game instead.") return DatabaseFacade.remove_player_from_game(game.id, leaver) game_channel_id: int = int(game.channel_id) game_channel: TextChannel = bot.get_channel(game_channel_id) await game_channel.set_permissions(context.author, read_messages=False) print("leave functioned properly so far....") await context.send( content=f"User {context.author.name} has left the game") print("sent message on channel", context.channel.id) return
async def kick(context: commands.Context, mentioned: User, *args): channel_did = str(context.channel.id) game: Game = DatabaseFacade.get_game_by_channel_did(channel_did) if game is not None: if len(args) > 0: await context.send("usage: !kick <@user>\nCan only be used by the" " creator of the game") return else: caller_did = str(context.author.id) caller = DatabaseFacade.get_player_by_did(caller_did) if caller.id != game.creator_id: await context.send("!kick can only be used by the creator.") return mentioned_did = str(mentioned.id) kicked = DatabaseFacade.get_player_by_did(mentioned_did) if kicked.id == game.creator.id: await context.send("!kick cannot be used to remove the creator" ) return success = DatabaseFacade.remove_player_from_game(game.id, kicked) if not success: await context.send( f"Cannot kick user {mentioned.name}; user is not in game") return game_channel: TextChannel = bot.get_channel(context.channel.id) await game_channel.set_permissions(mentioned, read_messages=False) await context.send( content=f"User {mentioned.name} has been kicked.")