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])
async def delete_queue_status_message(guild: discord.Guild): old_message = db.get(db.guild_ref(guild.id), db.Key.queue_status_message, [0, 0]) channel = guild.get_channel(old_message[0]) if channel is not None: try: await delete_message(await channel.fetch_message(old_message[1])) except discord.errors.NotFound: pass
async def _set(ctx: SlashContext, create_assistant_room_channel=None, assistant_room_chats_category=None, queue_updates_channel=None): await ctx.respond(eat=True) message = "" if create_assistant_room_channel is not None: if isinstance(create_assistant_room_channel, discord.channel.VoiceChannel): db.update(db.guild_ref(ctx.guild.id), db.Key.create_assistant_room_channel, create_assistant_room_channel.id) message += info_message( "Create assistant room channel changed successfully!\n") else: message += error_message( "The assistant room channel must be a voice channel.\n") if assistant_room_chats_category is not None: if isinstance(assistant_room_chats_category, discord.channel.CategoryChannel): db.update(db.guild_ref(ctx.guild.id), db.Key.assistant_room_chats_category, assistant_room_chats_category.id) message += info_message( "Assistant room chats category changed successfully!\n") else: message += error_message( "The assistant room chats category must be a category.\n") if queue_updates_channel is not None: if isinstance(queue_updates_channel, discord.channel.TextChannel): db.update(db.guild_ref(ctx.guild.id), db.Key.queue_updates_channel, queue_updates_channel.id) message += info_message( "Queue updates channel changed successfully!\n") else: message += error_message( "The queue updates channel must be a text channel.\n") if len(message) > 0: await response(ctx, message)
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])
async def queue_update(guild: discord.Guild, queue_id: int): queue = db.get(db.queue_ref(guild.id, queue_id), db.Key.queue, default=[]) queue_name = db.get(db.queue_ref(guild.id, queue_id), db.Key.name, default="Lab") queue_update_channel = guild.get_channel( db.get(db.guild_ref(guild.id), db.Key.queue_updates_channel)) await delete_queue_update_message(guild, queue_id) embed = discord.Embed(title=u"Next in queue:", colour=discord.Colour.blue()) embed.set_author( name=f"{queue_name.title()} Queue", icon_url= "https://cdn.discordapp.com/icons/812343984294068244/69241d42f3661678d61b3af3cfb04f45.png" ) if len(queue) > 0: regex = re.compile(r" \(\d+\)") user = await guild.fetch_member(queue[0]) embed.description = user.display_name embed.set_thumbnail(url=user.avatar_url) embed.set_footer(text="To move them to your room click ✅") for i in range(len(queue)): user = await guild.fetch_member(queue[i]) await update_queue_position(user, i + 1, regex=regex) else: embed.description = "The queue is empty." message = await queue_update_channel.send(embed=embed) if len(queue) > 0: await message.add_reaction("✅") db.update(db.queue_ref(guild.id, queue_id), db.Key.queue_update_message, [queue_update_channel.id, message.id])
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)