add queue pages
This commit is contained in:
parent
662f25fab8
commit
8b2fb4ef4c
1 changed files with 59 additions and 7 deletions
66
bot.py
66
bot.py
|
@ -12,6 +12,7 @@ import asyncio
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
import math
|
||||||
|
|
||||||
logger = logging.getLogger('disnake')
|
logger = logging.getLogger('disnake')
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
|
@ -19,7 +20,8 @@ handler = logging.FileHandler(filename='disnake.log', encoding='utf-8', mode='w'
|
||||||
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
|
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
|
|
||||||
queue = []
|
queue = ['https://www.youtube.com/watch?v=f5ACkTmHoSI&pp=ygUEcXVtdQ%3D%3D', 'https://www.youtube.com/watch?v=f5ACkTmHoSI&pp=ygUEcXVtdQ%3D%3D', 'https://www.youtube.com/watch?v=f5ACkTmHoSI&pp=ygUEcXVtdQ%3D%3D', 'https://www.youtube.com/watch?v=f5ACkTmHoSI&pp=ygUEcXVtdQ%3D%3D', 'https://www.youtube.com/watch?v=f5ACkTmHoSI&pp=ygUEcXVtdQ%3D%3D', 'https://www.youtube.com/watch?v=f5ACkTmHoSI&pp=ygUEcXVtdQ%3D%3D', 'https://www.youtube.com/watch?v=f5ACkTmHoSI&pp=ygUEcXVtdQ%3D%3D', 'https://www.youtube.com/watch?v=f5ACkTmHoSI&pp=ygUEcXVtdQ%3D%3D', 'https://www.youtube.com/watch?v=f5ACkTmHoSI&pp=ygUEcXVtdQ%3D%3D', 'https://www.youtube.com/watch?v=f5ACkTmHoSI&pp=ygUEcXVtdQ%3D%3D', 'https://www.youtube.com/watch?v=f5ACkTmHoSI&pp=ygUEcXVtdQ%3D%3D', 'https://www.youtube.com/watch?v=f5ACkTmHoSI&pp=ygUEcXVtdQ%3D%3D']
|
||||||
|
#queue = []
|
||||||
shuffle = False
|
shuffle = False
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
options = Options()
|
options = Options()
|
||||||
|
@ -107,13 +109,63 @@ async def getqueue(inter: disnake.AppCmdInter):
|
||||||
await inter.response.defer(ephemeral=True)
|
await inter.response.defer(ephemeral=True)
|
||||||
if not queue:
|
if not queue:
|
||||||
await inter.edit_original_response("There are no items in queue")
|
await inter.edit_original_response("There are no items in queue")
|
||||||
message = ""
|
message = f"Now Playing: <{queue[0]}>\n"
|
||||||
for idx, item in enumerate(queue):
|
for i in range(11):
|
||||||
if idx == 0:
|
if i == 0:
|
||||||
message = message + f"Now playing: <{item}>\n"
|
|
||||||
continue
|
continue
|
||||||
message = message + f"{idx}. <{item}>\n"
|
try:
|
||||||
await inter.edit_original_response(message[:2000]) #its possible for the queue to be longer then discords max allowed
|
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
|
||||||
|
return
|
||||||
|
|
||||||
@bot.slash_command(
|
@bot.slash_command(
|
||||||
name="toggleplayback",
|
name="toggleplayback",
|
||||||
|
|
Loading…
Reference in a new issue