async def open_queue(ctx):
    for queue_channel in db.queues_ref(ctx.guild.id).stream():
        channel = ctx.guild.get_channel(int(queue_channel.id))
        await channel.set_permissions(ctx.guild.default_role, overwrite=None)
        await queue_update(ctx.guild, int(queue_channel.id))

    await delete_queue_status_message(ctx.guild)
    db.update(db.guild_ref(ctx.guild.id), db.Key.queue_status, True)

    embed = discord.Embed(
        title=u"Join the voice channel for the queue you want",
        colour=discord.Colour.blue(),
        description=
        "Once in your waiting room feel free to join someone else's while you wait."
    )
    embed.set_author(
        name="Queues are Open!",
        icon_url=
        "https://cdn.discordapp.com/icons/812343984294068244/69241d42f3661678d61b3af3cfb04f45.png"
    )
    embed.set_footer(
        text=
        "If you leave a voice channel in this server you will be removed from the queue!"
    )

    message = await ctx.send(embed=embed)
    await message.pin()
    db.update(db.guild_ref(ctx.guild.id), db.Key.queue_status_message,
              [ctx.channel.id, message.id])
Exemple #2
0
async def on_reaction_add(reaction, user):
    if [reaction.message.channel.id, reaction.message.id] in \
            [queue.to_dict()[db.Key.queue_update_message.name] for queue in db.queues_ref(user.guild.id).stream()]:
        if user == client.user:
            return
        if reaction.emoji != "✅":
            await reaction.remove(user)
            return
        await bot.on_queue_message_react(reaction, user)
async def create_queue_role(guild: discord.Guild, queue_id: int):
    queue_name = db.get(db.queue_ref(guild.id, queue_id), db.Key.name)
    role = await guild.create_role(name=queue_role_name(queue_name),
                                   hoist=True)

    for queue_channel in db.queues_ref(guild.id).stream():
        channel = guild.get_channel(int(queue_channel.id))
        await channel.set_permissions(role, connect=False)

    return role
async def on_queue_message_react(reaction: discord.Reaction,
                                 user: discord.Member):
    queues = db.queues_ref(user.guild.id).where(
        db.Key.queue_update_message.name, "==",
        [reaction.message.channel.id, reaction.message.id]).stream()
    queue_id = None
    for queue in queues:
        queue_id = int(queue.id)
        break

    if queue_id is None:
        return

    if user.voice is None:
        await reaction.message.channel.send(
            "❌ You must be in a voice channel!", delete_after=5)
        await reaction.remove(user)
    else:
        await reaction.message.delete()
        queue_ref = db.queue_ref(user.guild.id, queue_id)
        queue = db.get(queue_ref, db.Key.queue, default=[])
        db.remove_array(queue_ref, db.Key.queue, queue[0])

        user_waiting = await user.guild.fetch_member(queue[0])
        await user_waiting.edit(voice_channel=user.voice.channel)
        await update_queue_position(user_waiting, 0)
        await queue_update(user.guild, queue_id)

        related_channel_ids = db.get(
            db.temp_channel_ref(user.guild.id, user.voice.channel.id),
            db.Key.related, [])

        for related_channel_id in related_channel_ids:
            related_channel = user.guild.get_channel(related_channel_id)
            await related_channel.set_permissions(user_waiting,
                                                  view_channel=True,
                                                  send_messages=True)

        role_name = queue_role_name(
            db.get(db.queue_ref(user.guild.id, queue_id), db.Key.name, ""))
        role = discord.utils.get(user.guild.roles, name=role_name)
        if role is not None:
            await user_waiting.remove_roles(role)
async def close_queue(ctx):
    for queue_channel in db.queues_ref(ctx.guild.id).stream():
        channel = ctx.guild.get_channel(int(queue_channel.id))
        await channel.set_permissions(ctx.guild.default_role, connect=False)

    await delete_queue_status_message(ctx.guild)
    db.update(db.guild_ref(ctx.guild.id), db.Key.queue_status, False)

    embed = discord.Embed(
        title=u"Come back next time",
        colour=discord.Colour.blue(),
        description=
        "Turn on notifications for this channel to be notified when the queues open again!"
    )
    embed.set_author(
        name="Queues are Closed",
        icon_url=
        "https://cdn.discordapp.com/icons/812343984294068244/69241d42f3661678d61b3af3cfb04f45.png"
    )

    message = await ctx.send(embed=embed)
    await message.pin()
    db.update(db.guild_ref(ctx.guild.id), db.Key.queue_status_message,
              [ctx.channel.id, message.id])
Exemple #6
0
async def on_voice_state_update(ctx, before, after):
    new_channel = after.channel
    old_channel = before.channel

    if new_channel is not None:
        create_assistant_room_channel_id = db.get(
            db.guild_ref(ctx.guild.id), db.Key.create_assistant_room_channel)
        create_waiting_room_channel_ids = [
            int(channel.id)
            for channel in db.queues_ref(ctx.guild.id).stream()
        ]

        if new_channel.id in create_waiting_room_channel_ids + [
                create_assistant_room_channel_id
        ]:
            room_name = bot.room_name(ctx.display_name)
            temp_channel = await bot.create_temp_channel(
                ctx.guild, room_name, "voice", new_channel.category)

            await ctx.edit(voice_channel=temp_channel)

            if new_channel.id == create_assistant_room_channel_id:
                category_id = db.get(db.guild_ref(ctx.guild.id),
                                     db.Key.assistant_room_chats_category)
                category = discord.utils.get(ctx.guild.categories,
                                             id=category_id)
                await bot.create_temp_channel(ctx.guild,
                                              room_name,
                                              "text",
                                              category=category,
                                              parent_id=temp_channel.id)
            elif new_channel.id in create_waiting_room_channel_ids:
                queue_name = db.get(db.queue_ref(ctx.guild.id, new_channel.id),
                                    db.Key.name,
                                    default="")
                role = discord.utils.get(ctx.guild.roles,
                                         name=bot.queue_role_name(queue_name))
                if role is None:
                    role = await bot.create_queue_role(ctx.guild,
                                                       new_channel.id)
                await ctx.add_roles(role)
                db.append_array(db.queue_ref(ctx.guild.id, new_channel.id),
                                db.Key.queue, ctx.id)
                queue = db.get(db.queue_ref(ctx.guild.id, new_channel.id),
                               db.Key.queue,
                               default=[])
                if len(queue) == 1:
                    await bot.queue_update(ctx.guild, new_channel.id)
                else:
                    await bot.update_queue_position(ctx, len(queue))

    else:
        queues = db.queues_ref(ctx.guild.id).where(db.Key.queue.name,
                                                   "array_contains",
                                                   ctx.id).stream()

        for queue in queues:
            db.remove_array(db.queue_ref(ctx.guild.id, int(queue.id)),
                            db.Key.queue, ctx.id)

            queue_list = queue.to_dict()[db.Key.queue.name]
            await bot.update_queue_position(ctx, 0)
            if len(queue_list) > 0 and queue_list[0] == ctx.id:
                await bot.queue_update(ctx.guild, int(queue.id))

            role_name = bot.queue_role_name(queue.to_dict()[db.Key.name.name])
            role = discord.utils.get(ctx.guild.roles, name=role_name)
            if role is not None:
                await ctx.remove_roles(role)

    if old_channel is not None:
        temp_channel_ids = [
            int(temp_channel.id)
            for temp_channel in db.temp_channels_ref(ctx.guild.id).stream()
        ]
        if old_channel.id in temp_channel_ids:
            if len(old_channel.members) == 0:
                await bot.delete_temp_channel(ctx.guild, old_channel.id)
            else:
                related_channel_ids = db.get(
                    db.temp_channel_ref(ctx.guild.id, old_channel.id),
                    db.Key.related, [])
                for related_channel_id in related_channel_ids:
                    related_channel = ctx.guild.get_channel(related_channel_id)
                    await related_channel.set_permissions(ctx, overwrite=None)

                    if isinstance(related_channel, discord.TextChannel):
                        await related_channel.purge(limit=100)