async def add(ctx, id, *args): server_id = str(ctx.message.guild.id) data = read_json("src/teams.json") for t in data[server_id]: if str(t.get("id")) == id: players = t.get("players") lc_players = lowercase_players(players) if ctx.author.name.lower() not in lc_players: await ctx.send(em.get("non_member")) elif len(players) == max_players.get(t.get("game")): await ctx.send(em.get("team_full")) elif len(args) != len(set(lowercase_players(args))): await ctx.send(em.get("duplicate_player")) elif len(args) + len(players) > max_players.get(t.get("game")): await ctx.send(em.get("too_many_players")) else: new_players = [] for p in args: if p.lower() not in lc_players: players.append(p) new_players.append(p) else: await ctx.send("{} is already part of the team!".format(p)) write_json(data) if len(new_players) > 0: await ctx.send( "{} have been added to Team {}.".format( ", ".join(new_players), id ) ) if len(new_players) > 1 else await ctx.send( "{} has been added to Team {}.".format(new_players[0], id) ) await ctx.send(embed=embed_team(t)) return await ctx.send(em.get("team_not_found"))
async def create(ctx, game, time, *args): if game not in game_format: await ctx.send(em.get("select_game")) return elif not (pattern.match(time)): await ctx.send(em.get("time")) return elif len(args) != len(set(lowercase_players(args))): await ctx.send(em.get("duplicate_player")) return elif len(args) >= max_players.get(game): await ctx.send(em.get("too_many_players")) return server_id = str(ctx.message.guild.id) data = read_json("src/teams.json") players = [ctx.author.name] if len(args) > 0: for p in args: players.append(p) if server_id in data: server_teams = data.get(server_id) count = len(server_teams) id = int(server_teams[count - 1].get("id")) + 1 if count > 0 else 1 new_team = {"id": id, "game": game, "time": time, "players": players} server_teams.append(new_team) else: id = 1 new_team = {"id": 1, "game": game, "time": time, "players": players} data[server_id] = [new_team] write_json(data) await ctx.send("Created Team {}.".format(id)) await ctx.send(embed=embed_team(new_team))
async def edit(ctx, id, time): if not (pattern.match(time)): await ctx.send(em.get("time")) return server_id = str(ctx.message.guild.id) data = read_json("src/teams.json") for t in data[server_id]: if str(t.get("id")) == id: if ctx.author.name.lower() not in lowercase_players(t.get("players")): await ctx.send(em.get("non_member")) return t.update({"time": time}) write_json(data) await ctx.send("Team {}'s start time changed to {}.".format(id, time)) await ctx.send(embed=embed_team(t)) return await ctx.send(em.get("team_not_found"))
async def join(ctx, *args): server_id = str(ctx.message.guild.id) data = read_json("src/teams.json") for id in args: for t in data[server_id]: found = False if str(t.get("id")) == id: found = True if ctx.author.name.lower() in lowercase_players(t.get("players")): await ctx.send("You are already a part of Team {}!".format(id)) break if len(t.get("players")) >= max_players.get(t.get("game")): await ctx.send("Team {} is full!".format(id)) break t.get("players").append(ctx.author.name) write_json(data) await ctx.send(embed=embed_team(t)) break if not found: await ctx.send(em.get("team_not_found"))
async def remove(ctx, id, *args): server_id = str(ctx.message.guild.id) data = read_json("src/teams.json") for t in data[server_id]: if str(t.get("id")) == id: players = t.get("players") if ctx.author.name.lower() not in lowercase_players(players): await ctx.send(em.get("non_member")) elif len(args) != len(set(args)): await ctx.send(em.get("duplicate_player")) else: removed_players = [] args = [int(n) - 1 for n in args] for n in args: if 0 <= n < len(players): removed_players.append(players[n]) else: await ctx.send( "Player {} is not part of the team!".format(n + 1) ) players = [p for n, p in enumerate(players) if n not in args] t["players"] = players if len(players) == 0: data[server_id].remove(t) await ctx.send("All players removed from Team {}.".format(id)) elif len(removed_players) > 0: await ctx.send( "{} have been removed from Team {}.".format( ", ".join(removed_players), id ) ) if len(removed_players) > 1 else await ctx.send( "{} has been removed from Team {}.".format( removed_players[0], id ) ) await ctx.send(embed=embed_team(t)) write_json(data) return await ctx.send(em.get("team_not_found"))
async def leave(ctx, *args): server_id = str(ctx.message.guild.id) data = read_json("src/teams.json") for id in args: for t in data[server_id]: found = False if str(t.get("id")) == id: found = True if ctx.author.name.lower() not in lowercase_players(t.get("players")): await ctx.send("You are not a part of Team {}!".format(id)) else: remove_player(t.get("players"), ctx.author.name) if len(t.get("players")) == 0: data[server_id].remove(t) await ctx.send("All players removed from Team {}.".format(id)) else: await ctx.send("You have been removed from Team {}.".format(id)) await ctx.send(embed=embed_team(t)) write_json(data) break if not found: await ctx.send(em.get("team_not_found"))