add per user queue limits
This commit is contained in:
parent
1aa2426213
commit
cb37e1c7b6
1 changed files with 13 additions and 0 deletions
13
bot.py
13
bot.py
|
@ -22,6 +22,7 @@ handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(me
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
|
|
||||||
queue = []
|
queue = []
|
||||||
|
user_queue = []
|
||||||
shuffle = False
|
shuffle = False
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
options = Options()
|
options = Options()
|
||||||
|
@ -75,8 +76,12 @@ def play_video(videourl):
|
||||||
)
|
)
|
||||||
async def play(inter: disnake.AppCmdInter, link: str):
|
async def play(inter: disnake.AppCmdInter, link: str):
|
||||||
await inter.response.defer(ephemeral=True)
|
await inter.response.defer(ephemeral=True)
|
||||||
|
if user_queue.count(inter.user.id) >= (int(os.getenv("MAX_QUEUE"))):
|
||||||
|
await inter.edit_original_response(f"You have reached the queue limit of {os.getenv('MAX_QUEUE')}, try again after one of your videos has played.")
|
||||||
|
return
|
||||||
if urlparse(link).netloc == 'youtube.com' or urlparse(link).netloc == 'www.youtube.com' or urlparse(link).netloc == 'youtu.be':
|
if urlparse(link).netloc == 'youtube.com' or urlparse(link).netloc == 'www.youtube.com' or urlparse(link).netloc == 'youtu.be':
|
||||||
queue.append(link)
|
queue.append(link)
|
||||||
|
user_queue.append(inter.user.id)
|
||||||
await inter.edit_original_response(f"added to queue!")
|
await inter.edit_original_response(f"added to queue!")
|
||||||
global queuetask
|
global queuetask
|
||||||
if queuetask.done():
|
if queuetask.done():
|
||||||
|
@ -199,6 +204,7 @@ async def skip(inter: disnake.AppCmdInter):
|
||||||
await queuetask
|
await queuetask
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
queue.pop(0)
|
queue.pop(0)
|
||||||
|
user_queue.pop(0)
|
||||||
if len(queue) < 1:
|
if len(queue) < 1:
|
||||||
driver.get(f"file://{os.getcwd()}/waitingforvideo.png")
|
driver.get(f"file://{os.getcwd()}/waitingforvideo.png")
|
||||||
driver.fullscreen_window()
|
driver.fullscreen_window()
|
||||||
|
@ -217,6 +223,7 @@ async def remove(inter: disnake.AppCmdInter, toremove: int):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
queue.pop(toremove)
|
queue.pop(toremove)
|
||||||
|
user_queue.pop(toremove)
|
||||||
await inter.edit_original_response("removed!")
|
await inter.edit_original_response("removed!")
|
||||||
|
|
||||||
async def queuehandler():
|
async def queuehandler():
|
||||||
|
@ -224,11 +231,17 @@ async def queuehandler():
|
||||||
global queue
|
global queue
|
||||||
while queue:
|
while queue:
|
||||||
if shuffle:
|
if shuffle:
|
||||||
|
seed = time.time()
|
||||||
|
random.seed(seed)
|
||||||
random.shuffle(queue)
|
random.shuffle(queue)
|
||||||
|
random.seed(seed)
|
||||||
|
random.shuffle(user_queue)
|
||||||
print(queue)
|
print(queue)
|
||||||
|
print(user_queue)
|
||||||
driver.maximize_window()
|
driver.maximize_window()
|
||||||
await loop.run_in_executor(None, play_video, queue[0])
|
await loop.run_in_executor(None, play_video, queue[0])
|
||||||
queue.pop(0)
|
queue.pop(0)
|
||||||
|
user_queue.pop(0)
|
||||||
driver.get(f"file://{os.getcwd()}/waitingforvideo.png")
|
driver.get(f"file://{os.getcwd()}/waitingforvideo.png")
|
||||||
driver.fullscreen_window()
|
driver.fullscreen_window()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue