async def queue(self, ctx): """ disp queue """ if lobby.get_lobby_len() > cfg.general["lobby_size"]: await disp.UNKNOWN_ERROR.send(ctx, "Lobby Overflow") return if lobby.is_lobby_stuck(): await disp.LB_QUEUE.send(ctx, names_in_lobby=lobby.get_all_names_in_lobby()) await disp.LB_STUCK.send(ctx) return await disp.LB_QUEUE.send(ctx, names_in_lobby=lobby.get_all_names_in_lobby())
async def lobby(self, ctx, *args): if ctx.channel.id != cfg.channels["lobby"]: await disp.WRONG_CHANNEL.send(ctx, ctx.command.name, f'<#{cfg.channels["lobby"]}>') return if len(args) > 0 and args[0] == "restore": for mention in ctx.message.mentions: try: p_id = mention.id player = Player.get(int(p_id)) if player and not lobby.is_lobby_stuck( ) and player.is_registered and not player.is_lobbied: lobby.add_to_lobby(player) except ValueError: pass await disp.LB_QUEUE.send( ctx, names_in_lobby=lobby.get_all_names_in_lobby()) return if len(args) > 0 and args[0] == "save": lb = lobby.get_all_ids_in_lobby() await db.async_db_call(db.set_field, "restart_data", 0, {"last_lobby": lb}) await disp.LB_SAVE.send(ctx) return if len(args) > 0 and args[0] == "get": lb = lobby.get_all_ids_in_lobby() await disp.LB_GET.send(ctx, " ".join([str(p_id) for p_id in lb])) return await disp.WRONG_USAGE.send(ctx, ctx.command.name)
async def timeout(self, ctx, *args): if len(args) == 1 and args[0] == "help": await disp.RM_TIMEOUT_HELP.send(ctx) return if len(ctx.message.mentions) != 1: await disp.RM_MENTION_ONE.send(ctx) return player = Player.get(ctx.message.mentions[0].id) if not player: # player isn't even registered in the system... player = Player(ctx.message.mentions[0].id, ctx.message.mentions[0].name) await db.async_db_call(db.set_element, "users", player.id, player.get_data()) if player.is_lobbied: lobby.remove_from_lobby(player) await disp.RM_LOBBY.send( ContextWrapper.channel(cfg.channels["lobby"]), player.mention, names_in_lobby=lobby.get_all_names_in_lobby()) if player.match: await disp.RM_IN_MATCH.send(ctx) return if len(args) == 0: if player.is_timeout: await disp.RM_TIMEOUT_INFO.send( ctx, dt.utcfromtimestamp( player.timeout).strftime("%Y-%m-%d %H:%M UTC")) return await roles.role_update(player) await roles.perms_muted(False, player.id) await disp.RM_TIMEOUT_NO.send(ctx) return # =timeout @player remove if len(args) == 1 and args[0] == 'remove': player.timeout = 0 await player.db_update("timeout") await disp.RM_TIMEOUT_FREE.send(ctx, player.mention) await roles.role_update(player) await roles.perms_muted(False, player.id) return # Check if command is correct (=timeout @player 12 d) time = tools.time_calculator(" ".join(args)) if time == 0: await disp.RM_TIMEOUT_INVALID.send(ctx) return end_time = tools.timestamp_now() + time player.timeout = end_time await roles.role_update(player) await player.db_update("timeout") await roles.perms_muted(True, player.id) await disp.RM_TIMEOUT.send( ctx, player.mention, dt.utcfromtimestamp(end_time).strftime("%Y-%m-%d %H:%M UTC"))
async def leave(self, ctx): """ Leave queue """ player = Player.get(ctx.message.author.id) if not player: await disp.LB_NOT_IN.send(ctx) return if player.is_lobbied: lobby.remove_from_lobby(player) await disp.LB_REMOVED.send(ctx, names_in_lobby=lobby.get_all_names_in_lobby()) return await disp.LB_NOT_IN.send(ctx)
async def clear(self, ctx): if ctx.channel.id == cfg.channels["lobby"]: # clear lobby if lobby.clear_lobby(): await disp.LB_CLEARED.send( ctx, names_in_lobby=lobby.get_all_names_in_lobby()) return await disp.LB_EMPTY.send(ctx) return # clear a match channel if ctx.channel.id in cfg.channels["matches"]: match = Match.get(ctx.channel.id) await match.command.clear(ctx) return await disp.WRONG_CHANNEL_2.send(ctx, ctx.command.name, f"<#{ctx.channel.id}>")
async def info(self, ctx): if ctx.channel.id == cfg.channels["lobby"]: match_list = list() for ch in cfg.channels["matches"]: match_list.append(Match.get(ch)) await disp.GLOBAL_INFO.send(ctx, lobby=lobby.get_all_names_in_lobby(), match_list=match_list) return if ctx.channel.id in cfg.channels["matches"]: match = Match.get(ctx.channel.id) await match.command.info(ctx) return await disp.WRONG_CHANNEL_2.send(ctx, ctx.command.name, f"<#{ctx.channel.id}>")
async def unregister(self, ctx): if not await _check_channels(ctx, cfg.channels["register"]): return player = await get_check_player(ctx) if not player: return if player.is_lobbied: lobby.remove_from_lobby(player) await disp.RM_LOBBY.send( ContextWrapper.channel(cfg.channels["lobby"]), player.mention, names_in_lobby=lobby.get_all_names_in_lobby()) if not player.match: try: await db.async_db_call(db.remove_element, "users", player.id) except db.DatabaseError: pass # ignored if not yet in db await roles.remove_roles(player.id) player.remove() await disp.RM_OK.send(ctx) return await disp.RM_IN_MATCH.send(ctx)
async def remove(self, ctx): if ctx.channel.id == cfg.channels["lobby"]: player = await get_check_player(ctx) if not player: return if player.is_lobbied: lobby.remove_from_lobby(player) await disp.RM_LOBBY.send( ContextWrapper.channel(cfg.channels["lobby"]), player.mention, names_in_lobby=lobby.get_all_names_in_lobby()) return await disp.RM_NOT_LOBBIED.send(ctx) return # if ctx.channel.id == cfg.channels["register"]: # player = await get_check_player(ctx) # if not player: # return # #TODO: remove ig names else: await disp.WRONG_CHANNEL_2.send(ctx, ctx.command.name, f"<#{ctx.channel.id}>")