Open ludwikc opened 3 weeks ago
import discord
from discord.ext import commands
class QueueCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.queue = [] # This will store the user IDs of the speakers
self.current_speaker = None
@commands.Cog.listener()
async def on_ready(self):
print("QueueCog is ready")
@commands.command(name="queue")
async def join_queue(self, ctx):
"""Adds the user to the speaker queue."""
if ctx.author.id not in self.queue:
self.queue.append(ctx.author.id)
await ctx.send(f"{ctx.author.mention} has been added to the queue.")
await self.display_queue(ctx)
if len(self.queue) == 1:
await self.notify_next_speaker(ctx)
else:
await ctx.send(f"{ctx.author.mention}, you are already in the queue.")
@commands.Cog.listener()
async def on_voice_state_update(self, member, before, after):
"""Handles the user unmuting themselves and updates the queue."""
if member.id == self.current_speaker and before.self_mute and not after.self_mute:
# The current speaker has unmuted themselves, remove them from the queue
self.queue.pop(0)
self.current_speaker = None
# Notify the next speaker if there's anyone left in the queue
if self.queue:
channel = discord.utils.get(member.guild.text_channels, name=member.voice.channel.name)
await self.notify_next_speaker(channel)
await self.display_queue(channel)
async def notify_next_speaker(self, ctx):
"""Notifies the next person in line that it's their turn to speak."""
if self.queue:
self.current_speaker = self.queue[0]
next_user = self.bot.get_user(self.current_speaker)
await ctx.send(f"{next_user.mention} is next in line to speak. Please unmute yourself.")
async def display_queue(self, ctx):
"""Displays the current queue lineup."""
if self.queue:
lineup = "\n".join([f"<@{user_id}>" for user_id in self.queue])
await ctx.send(f"Current lineup:\n{lineup}")
else:
await ctx.send("The queue is empty.")
# This function is required for the bot to load the cog
def setup(bot):
bot.add_cog(QueueCog(bot)) ```
Feature Request:
High-Level Requirements for Discord Bot - Speaker Queue Management
General Functionality
• The bot will manage a queue of speakers during a Discord call, ensuring an orderly flow of conversation. • The bot will start with all participants muted, except for the moderator (you). • Users will join the queue by typing the /queue command in the chat. • The queue operates on a First-In-First-Out (FIFO) basis, meaning the first person to join the queue will be the first allowed to speak.
Queue Management
• Joining the Queue: • Users can join the speaking queue by typing /queue in the text chat. • Upon joining, the bot adds the user to the end of the queue. • The bot will immediately display the updated queue lineup in the text chat, listing all users currently in the queue. • Notification for Next Speaker: • When it’s the next user’s turn to speak (i.e., the user at the front of the queue), the bot will notify them by tagging them in the text chat with a message like “@user, you are next in line to speak.” • The bot will send this notification immediately after the previous speaker unmutes themselves. • Unmuting and Queue Removal: • The bot will automatically detect when the user unmutes themselves. • Upon detecting the unmute action, the bot will remove the user from the queue. • After removing the user from the queue, the bot will notify the next person in line that it’s their turn and display the updated queue lineup in the chat.
Queue Display
• Queue Updates: • Each time a user joins the queue, unmutes themselves, or a new speaker is announced, the bot will display the full queue lineup in the chat. • The queue display should list all users currently in the queue, in order.
Re-joining the Queue
• Users can rejoin the queue after they’ve spoken by typing /queue again. • Upon rejoining, the user will be placed at the end of the queue.
Manual Controls and Future Enhancements
• Manual Queue Management: • For now, manual muting and other actions will be handled by the moderator (you). Automatic mute management is not required in this version. • Future Enhancements: • Future versions of the bot may include additional admin controls, such as the ability to clear the queue, remove specific users, or reset the queue.