add queue pages
This commit is contained in:
parent
662f25fab8
commit
27f0bc28ce
1 changed files with 56 additions and 6 deletions
62
bot.py
62
bot.py
|
@ -12,6 +12,7 @@ import asyncio
|
|||
from dotenv import load_dotenv
|
||||
import os
|
||||
import logging
|
||||
import math
|
||||
|
||||
logger = logging.getLogger('disnake')
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
@ -107,13 +108,62 @@ async def getqueue(inter: disnake.AppCmdInter):
|
|||
await inter.response.defer(ephemeral=True)
|
||||
if not queue:
|
||||
await inter.edit_original_response("There are no items in queue")
|
||||
message = ""
|
||||
for idx, item in enumerate(queue):
|
||||
if idx == 0:
|
||||
message = message + f"Now playing: <{item}>\n"
|
||||
message = f"Now Playing: <{queue[0]}>\n"
|
||||
for i in range(11):
|
||||
if i == 0:
|
||||
continue
|
||||
message = message + f"{idx}. <{item}>\n"
|
||||
await inter.edit_original_response(message[:2000]) #its possible for the queue to be longer then discords max allowed
|
||||
try:
|
||||
message = message + f"{i}. <{queue[i]}>\n"
|
||||
except IndexError:
|
||||
break
|
||||
message = message + f"1 of {math.ceil((len(queue)-1)/10) if (len(queue)-1)/10 > 1 else 1}"
|
||||
if math.ceil((len(queue)-1)/10) > 1:
|
||||
await inter.edit_original_response(message, components=[disnake.ui.Button(label=">>", style=disnake.ButtonStyle.primary, custom_id="Forward"),])
|
||||
else:
|
||||
await inter.edit_original_response(message)
|
||||
|
||||
@bot.listen("on_button_click")
|
||||
async def button_listener(inter: disnake.MessageInteraction):
|
||||
ogmsg = inter.message.content
|
||||
page = ogmsg.split("\n")
|
||||
page = page[-1].split(" of ")
|
||||
if inter.component.custom_id == "Forward":
|
||||
message = f"Now Playing: <{queue[0]}>\n"
|
||||
offset = int(int(page[0]) * 10)
|
||||
for i in range(11):
|
||||
if i == 0:
|
||||
continue
|
||||
try:
|
||||
message = message + f"{int(i+offset)}. <{queue[int(i+offset)]}>\n"
|
||||
except IndexError:
|
||||
break
|
||||
message = message + f"{int(page[0])+1} of {math.ceil((len(queue)-1)/10) if (len(queue)-1)/10 > 1 else 1}"
|
||||
if (int(page[0])+1) >= int(page[1]):
|
||||
await inter.response.edit_message(message, components=[disnake.ui.Button(label="<<", style=disnake.ButtonStyle.primary, custom_id="Backward"),])
|
||||
else:
|
||||
await inter.response.edit_message(message, components=[disnake.ui.Button(label="<<", style=disnake.ButtonStyle.primary, custom_id="Backward"),
|
||||
disnake.ui.Button(label=">>", style=disnake.ButtonStyle.primary, custom_id="Forward"),])
|
||||
return
|
||||
if inter.component.custom_id == "Backward":
|
||||
message = f"Now Playing: <{queue[0]}>\n"
|
||||
offset = int((int(page[0]) - 2) * 10)
|
||||
for i in range(11):
|
||||
if i == 0:
|
||||
continue
|
||||
try:
|
||||
message = message + f"{int(i+offset)}. <{queue[int(i+offset)]}>\n"
|
||||
except IndexError:
|
||||
break
|
||||
message = message + f"{int(page[0])-1} of {math.ceil((len(queue)-1)/10) if (len(queue)-1)/10 > 1 else 1}"
|
||||
if (int(page[0])-1) <= 1 and int(page[1] == 1):
|
||||
await inter.response.edit_message(message)
|
||||
elif (int(page[0])-1) <= 1 and int(page[1] > 1):
|
||||
await inter.response.edit_message(message, components=[disnake.ui.Button(label=">>", style=disnake.ButtonStyle.primary, custom_id="Forward"),])
|
||||
else:
|
||||
await inter.response.edit_message(message, components=[disnake.ui.Button(label="<<", style=disnake.ButtonStyle.primary, custom_id="Backward"),
|
||||
disnake.ui.Button(label=">>", style=disnake.ButtonStyle.primary, custom_id="Forward"),])
|
||||
await inter.response.edit_message(message, components=[])
|
||||
return
|
||||
|
||||
@bot.slash_command(
|
||||
name="toggleplayback",
|
||||
|
|
Loading…
Reference in a new issue