async def send_account(channel: discord.TextChannel, a_player: classes.ActivePlayer): """ Actually send its account to the player. :param channel: Current match channel. :param a_player: Player to send the account to. """ msg = None # Try 3 times to send a DM: ctx = a_player.account.get_new_context(ContextWrapper.user(a_player.id)) for j in range(3): try: msg = await disp.ACC_UPDATE.send(ctx, account=a_player.account) break except discord.errors.Forbidden: pass if not msg: # Else validate the account and send it to staff channel instead await disp.ACC_CLOSED.send(channel, a_player.mention) await a_player.account.validate() msg = await disp.ACC_STAFF.send(ContextWrapper.channel( cfg.channels["staff"]), f'<@&{cfg.roles["admin"]}>', a_player.mention, account=a_player.account) # Set the account message, log the account: a_player.account.message = msg await disp.ACC_LOG.send(ContextWrapper.channel(cfg.channels["spam"]), a_player.name, a_player.id, a_player.account.id)
async def terminate_account(a_player: classes.ActivePlayer): """ Terminate the account: ask the user to log off and remove the reaction. :param a_player: Player whose account should be terminated. """ # Get account and terminate it acc = a_player.account acc.terminate() # Remove the reaction handler and update the account message await disp.ACC_UPDATE.edit(acc.message, account=acc) # If account was validated, ask the player to log off: if acc.is_validated and acc.message.channel.id != cfg.channels["staff"]: await disp.ACC_OVER.send(ContextWrapper.user(acc.a_player.id)) # If account was validated, update the db with usage if acc.is_validated: # Prepare data p_usage = { "id": acc.id, "time_start": acc.last_usage["time_start"], "time_stop": acc.last_usage["time_stop"], "match_id": a_player.match.id } # Update the account element await db.async_db_call(db.push_element, "accounts_usage", acc.id, {"usages": acc.last_usage}) try: # Update the player element await db.async_db_call(db.push_element, "accounts_usage", a_player.id, {"usages": p_usage}) except db.DatabaseError: # If the player element doesn't exist, create it data = dict() data["_id"] = a_player.id data["unique_usages"] = a_player.unique_usages data["usages"] = [p_usage] await db.async_db_call(db.set_element, "accounts_usage", a_player.id, data) # Reset the account state acc.clean() del _busy_accounts[acc.id] _available_accounts[acc.id] = acc
async def launch(ctx, id_list, tier): print("TIER 1") players = list() for p_id in id_list: player = Player.get(p_id) if not player: print(f"user {p_id}") user = await bot.fetch_user(p_id) player = Player(user.id, user.name) await db.async_db_call(db.set_element, "users", player.id, player.get_data()) await player.register(None) players.append(player) for p in players: lobby.add_to_lobby(p) if tier == 1: return print("TIER 2") await asyncio.sleep(1) match = players[0].match while match.status is not MatchStatus.IS_CAPTAIN: await asyncio.sleep(1) cap_1_ctx = ContextWrapper.wrap(ctx.channel) cap_1_ctx.message = ctx.message cap_1_ctx.author = ctx.guild.get_member(players[0].id) await match.on_volunteer(players[0]) cap_2_ctx = ContextWrapper.wrap(ctx.channel) cap_2_ctx.message = ctx.message cap_2_ctx.author = ctx.guild.get_member(players[1].id) await match.on_volunteer(players[1]) if tier == 2: return print("TIER 3") while match.status is not MatchStatus.IS_PICKING: await asyncio.sleep(1) picked = ContextWrapper.user(players[2].id) cap_1_ctx.message.mentions.clear() cap_1_ctx.message.mentions.append(picked.author) await match.command.pick(cap_1_ctx, [""]) if tier == 3: return print("TIER 4") while match.status is not MatchStatus.IS_FACTION: await asyncio.sleep(1) cap_2_ctx.message.mentions.clear() cap_1_ctx.message.mentions.clear() await match.command.pick(cap_2_ctx, ["VS"]) await match.command.pick(cap_1_ctx, ["TR"]) if tier == 4: return print("TIER 5") while match.status is not MatchStatus.IS_BASING: await asyncio.sleep(1) # We assume tester is an admin await match.command.base(ctx, ["ceres"]) if tier == 5: return print("TIER 6") while match.status is not MatchStatus.IS_WAITING: await asyncio.sleep(1) match.change_check("online") match.change_check("account") await match.command.ready(cap_1_ctx) await match.command.ready(cap_2_ctx)