async def register(self, ctx, mode): """Register the player to the elo embed_leaderboard. Example: !r N or !r N all This command will register the user into the game mode set in argument. The game mode needs to be the N in NvsN, and it needs to already exist. This command can be used only in the register channel. The command will fail if the mode doesn't exist (use !modes to check).""" game = get_game(ctx) name = ctx.author.id if name in game.leaderboard(mode): await ctx.send(embed=Embed(color=0x000000, description=f"There's already a played called <@{name}>.")) return if len(game.leaderboard(mode)) < game.limit_leaderboards: game.leaderboard(mode)[name] = Player(ctx.author.name, ctx.author.id) await ctx.send(embed=Embed(color=0x00FF00, description=f"<@{name}> has been registered.")) num = split_with_numbers(mode)[0] role = discord.utils.get( ctx.guild.roles, name=f"{num}vs{num} Elo Player") await ctx.author.add_roles(role) else: await ctx.send(embed=Embed(color=0x000000, description="This server doesn't have premium, hence, it is limited to 10 " "users only.\n Get premium here: https://discord.gg/E2ZBNSx to " "get unlimited users !"))
async def set_pick_mode(self, ctx, mode, new_mode): """Set the pick_mode to the new_mode set new mode: 0: random teams 1: balanced teams 2: random cap, picks 1-1 1-1 3: best cap, picks 1-1 1-1 4: random cap, picks 1-2 2-1 5: best cap, picks 1-2 2-1 """ game = get_game(ctx) new_mode = int(new_mode) if split_with_numbers(mode)[1] == 't': await ctx.send("Can't set a pick_mode for team vs team") return if new_mode not in range(6): await ctx.send("Wrong new_mode given, read help pick_mode") return pick_modes = ["random teams", "balanced random", "random cap (1-1)", "best cap (1-1)", "random cap (1-2 2-1)", "best cap (1-2 2-1)"] game.queues[mode].mode = new_mode if len(game.queues[mode].modes) <= 4: # backward compatibility game.queues[mode].modes.append(game.queues[mode].modes[2]) game.queues[mode].modes.append(game.queues[mode].modes[3]) game.queues[mode].pick_function = game.queues[mode].modes[new_mode] await ctx.send(f"Pick mode changed to {pick_modes[new_mode]} !")
async def join_with(self, ctx, *mentions): """Join the queue with your own team. Example in 4vs4: !jw @player1 @player2 @player3 """ mode = get_channel_mode(ctx) nb_players = int(split_with_numbers(mode)[0]) players = {await get_player_by_id(ctx, mode, ctx.author.id)} | \ {await get_player_by_mention(ctx, mode, m) for m in mentions} if nb_players != len(players): await send_error(ctx, f"You joined with {len(players)} player(s) but you need exactly {nb_players}") raise PassException() embed = Embed(title=f"Invitations for {mode} from {ctx.author.display_name}", description="To join with your team, everyone involved have to confirm by clicking on 👍.\n" "To deny, click on the 👎.") \ .add_field(name=f"Captain", value=ctx.author.mention) for i in range(len(mentions)): embed.add_field(name=f"Player n°{i + 1}", value=mentions[i]) msg = await ctx.send(embed=embed) await msg.add_reaction("👍") await msg.add_reaction("👎")
def add_game_to_be_played(self, queue, mode): """Add a game to undecided games.""" last_id = self.queues[mode].game_id self.undecided_games[mode][last_id] = queue self.queues[mode] = Queue(2 * int(split_with_numbers(mode)[0]), queue.mode, queue.map_mode, last_id) return "The teams have been made, a new queue is starting!"
def get_rank_name(self, mode, elo_points, player): """Return the name corresponding to the elo rank.""" if player.double_xp > 0: return "Premium" if player.nb_matches < 20: return "Unranked (20 games needed)" for name, rank in self.ranks[mode].items(): if elo_points in rank.range: return ' '.join(split_with_numbers(name)) + \ f" ({rank.start()} - {rank.stop()})" return "Unranked"
def add_mode(self, mode): """Add the mode in the set.""" if mode in self.available_modes: return False if not hasattr(self, "tmp_leaderboards"): setattr(self, "tmp_leaderboards", {}) if self.limit_leaderboards == 10: self.tmp_leaderboards[mode] = {} else: self.leaderboards[mode] = {} self.undecided_games[mode] = {} self.archive[mode] = {} self.ranks[mode] = {} self.cancels[mode] = {} # self.bans = {} pick_mode = 0 if split_with_numbers(mode)[1] == 's' else 6 self.queues[mode] = Queue(2 * int(split_with_numbers(mode)[0]), pick_mode, 0) return True
async def clear_queue(self, ctx): """Clear the current queue.""" game = get_game(ctx) mode = get_channel_mode(ctx) last_id = game.queues[mode].game_id if not game.queues[mode].has_queue_been_full: for player in game.queues[mode].players: if player in TIMEOUTS: TIMEOUTS[player].cancel() TIMEOUTS.pop(player, None) game.queues[mode] = Queue(2 * int(split_with_numbers(mode)[0]), game.queues[mode].mode, game.queues[mode].map_mode, last_id) await ctx.send( embed=Embed(color=0x00FF00, description="The queue is now empty"))
def cancel(self, mode, id): """Cancel the game and return true if it was correctly canceled.""" last_id = self.queues[mode].game_id if id == last_id: if not hasattr(self.queues[mode], "map_mode"): setattr(self.queues[mode], "map_mode", 0) self.queues[mode] = Queue(2 * int(split_with_numbers(mode)[0]), self.queues[mode].mode, self.queues[mode].map_mode, last_id) return True res = self.undecided_games[mode].pop(id, None) if res is None: return False # self.cancels[mode][id] = res return True
async def ban(self, ctx, mention, timeUnity, *reason): """Bans the player for a certain time. Example: !ban @Anddy 2h code very badly unity must be in s, m, h, d (secs, mins, hours, days). """ id = await get_id(ctx, mention) time = split_with_numbers(timeUnity) unity = "" if len(time) == 2: time, unity = time total_sec = await get_total_sec(ctx, time, unity) get_game(ctx).ban_player(id, total_sec, ' '.join(reason)) await ctx.send( embed=Embed(color=0x00FF00, description=f"{mention} has been banned ! Check !bans") )
async def register_all(self, ctx): """Register to every available modes in one command.""" game = get_game(ctx) name = ctx.author.id for mode in game.get_leaderboards(): if name not in game.leaderboard(mode): game.leaderboard(mode)[name] = Player( ctx.author.name, ctx.author.id) num = int(split_with_numbers(mode)[0]) role = discord.utils.get(ctx.guild.roles, name=f"{num}vs{num} Elo Player") # role may have been deleted... if role is not None: await ctx.author.add_roles(role) else: await ctx.message.guild.create_role(name=f"{num}vs{num} Elo Player", colour=discord.Colour(random.randint(0, 0xFFFFFF))) await ctx.author.add_roles(role) await ctx.send(embed=Embed(color=0x00FF00, description=f"<@{name}> has been registered for every mode."))
async def add_mode(self, ctx, mode): """Add a mode to the game modes. Example: !add_mode 4s Will add the mode solo 4vs4 into the available modes, a channel will be created and the embed_leaderboard will now have a 4s key. Can be used only in init channel by a Elo Admin role having user.""" split = split_with_numbers(mode) if len(split) == 2: num, vs_mode = split if num.isdigit() and int(num) > 0 and vs_mode in ("s", "t"): if get_game(ctx).add_mode(mode): guild = ctx.message.guild await create_mode_discord(num, {"s": "Solo elo", "t": "Teams elo"}[vs_mode], ctx) if not discord.utils.get(guild.roles, name=f"{num}vs{num} Elo Player"): await guild.create_role(name=f"{num}vs{num} Elo Player", colour=discord.Colour(random.randint(0, 0xFFFFFF))) await ctx.send(f"{num}vs{num} Elo Player role created") return await ctx.send(embed=Embed(color=0x000000, description="Couldn't add the game mode."))