From 0e1af96e7506cca54395ab0c4b85e5bc376ff279 Mon Sep 17 00:00:00 2001 From: NatrixAeria Date: Tue, 20 Oct 2020 04:21:55 +0200 Subject: Add move command --- commands.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/commands.py b/commands.py index 7ef8d7b..989411d 100644 --- a/commands.py +++ b/commands.py @@ -23,6 +23,17 @@ async def answer(ctx: commands.Context, msg: str, *args, **kwargs): def is_admin_channel(ctx: commands.Context): return ctx.message.channel.id == ctx.bot.admin_channel +async def get_members(guild, channel): + futures = [] + insts = [] + for i in channel.voice_states.keys(): + inst = guild.get_member(i) + if inst is None: + futures.append(guild.fetch_member(i)) + else: + insts.append(inst) + return insts + await await_n(futures) + @commands.command(help='display this help message', aliases=('hepl', 'h', '?')) async def help(ctx: commands.Context): @@ -71,7 +82,7 @@ async def shuffle(ctx: commands.Context, channel_size=2): if not channels: return False meta_channel, lobby_channel = channels - members = await await_n(map(ctx.guild.fetch_member, lobby_channel.voice_states.keys())) + members = await get_members(ctx.guild, lobby_channel) if not members: await answer(ctx, 'error: nobody wants to get shuffeled :(') return False @@ -117,8 +128,9 @@ async def shuffle(ctx: commands.Context, channel_size=2): for member2 in group: if member1 != member2: ctx.bot.oldgroups.add(frozenset((member1.id, member2.id))) - random.shuffle(futures) + await await_n(futures) + futures = [] for group in groups: for member in group: futures.append(ctx.bot.send_panel(ctx, member, group)) @@ -225,6 +237,7 @@ async def list(ctx: commands.Context): else: await answer(ctx, 'there is no tutor :/') + @commands.command( help='get the scoreboard', aliases=('scores', 'score', 'points') @@ -239,6 +252,7 @@ async def scoreboard(ctx: commands.Context): embed = discord.Embed(title=config.SCOREBOARD_TITLE, type="rich", description=text, colour=discord.Colour.purple()) await ctx.send(embed=embed) + @commands.command( help='reset the scoreboard', aliases=(), @@ -249,4 +263,23 @@ async def reset(ctx: commands.Context): await answer(ctx, 'resetted the scoreboard') +@commands.command( + help='move members from channel1 to channel2', + aliases=('mvoe', 'omve', 'moev'), +) +async def move(ctx: commands.Context, id1=0, id2=0): + if not is_admin_channel(ctx): return + if not id1 or not id2: + return await answer(ctx, 'you must provide 2 ids') + c = [] + for i in (id1, id2): + c.append(ctx.guild.get_channel(i) or await ctx.guild.fetch_channel(i)) + c1, c2 = c + futures = [] + for member in await get_members(ctx.guild, c1): + futures.append(member.move_to(c2)) + await await_n(futures) + await answer(ctx, 'moved everyone 😊') + + bot_commands = [cmd for cmd in locals().values() if isinstance(cmd, commands.Command)] -- cgit v1.2.3