Compare commits
No commits in common. "febb7556cfdfaa615ea4d7ce65595544bee38560" and "689629aa37ee931cd6ac02139a19125b5037394b" have entirely different histories.
febb7556cf
...
689629aa37
1 changed files with 16 additions and 64 deletions
80
bot.py
80
bot.py
|
@ -3,7 +3,6 @@ from selenium import webdriver
|
|||
from selenium.webdriver.common.keys import Keys
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.wait import WebDriverWait
|
||||
from selenium.common.exceptions import NoSuchElementException, ElementNotVisibleException, TimeoutException
|
||||
from time import sleep
|
||||
import time
|
||||
import disnake
|
||||
|
@ -25,13 +24,12 @@ logger.addHandler(handler)
|
|||
|
||||
queue = []
|
||||
user_queue = []
|
||||
skip_list = []
|
||||
shuffle = False
|
||||
load_dotenv()
|
||||
options = Options()
|
||||
options.profile = webdriver.FirefoxProfile(os.getenv("PROFILE_PATH"))
|
||||
driver = webdriver.Firefox(options=options)
|
||||
intents = disnake.Intents.all()
|
||||
intents = disnake.Intents.default()
|
||||
intents.message_content = False
|
||||
bot = commands.Bot(intents=intents, command_prefix=".", test_guilds=[int(os.getenv("GUILD_ID"))])
|
||||
|
||||
|
@ -43,28 +41,29 @@ async def on_ready():
|
|||
def play_video(videourl):
|
||||
driver.get(videourl)
|
||||
try:
|
||||
elem = WebDriverWait(driver, 8, 0.2, None).until(lambda x: x.find_element(By.CLASS_NAME, "ytp-fullscreen-button"))
|
||||
elem = WebDriverWait(driver, 5, 0.2, None).until(lambda x: x.find_element(By.CLASS_NAME, "ytp-fullscreen-button"))
|
||||
sleep(1)
|
||||
elem.send_keys(Keys.RETURN)
|
||||
except (NoSuchElementException,TimeoutException) as e:
|
||||
print(e)
|
||||
except Exception:
|
||||
return #if this errors there is no fullscreen options, such as playlists, so skip the link
|
||||
try:
|
||||
elem = driver.find_element(By.XPATH, '//button[@data-tooltip-target-id="ytp-autonav-toggle-button"][@aria-label="Autoplay is on"]')
|
||||
elem.send_keys(Keys.RETURN)
|
||||
except (NoSuchElementException,ElementNotVisibleException,TimeoutException):
|
||||
except Exception:
|
||||
pass
|
||||
#TODO: see if this is actually needed
|
||||
try:
|
||||
elem = WebDriverWait(driver, 10, 0.2, (ElementNotVisibleException)).until(lambda x: x.find_element(By.XPATH, '//button[@aria-label="Dismiss"]').is_displayed())
|
||||
elem.send_keys(Keys.RETURN)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
elem = WebDriverWait(driver, 5, 0.2, (NoSuchElementException,ElementNotVisibleException)).until(lambda x: x.find_element(By.XPATH, '//button[@aria-label="Dismiss"]'))
|
||||
elem.send_keys(Keys.RETURN)
|
||||
except (NoSuchElementException,ElementNotVisibleException,TimeoutException) as e:
|
||||
print(e)
|
||||
try:
|
||||
elem = WebDriverWait(driver, (float(os.getenv("MAX_MIN")) * 60), 1, None).until(lambda x: x.find_element(By.CLASS_NAME, "html5-endscreen").is_displayed())
|
||||
except (NoSuchElementException,ElementNotVisibleException,TimeoutException) as e:
|
||||
print(e)
|
||||
sleep(1)
|
||||
endscreen = driver.find_element(By.CLASS_NAME, "html5-endscreen")
|
||||
timeout = (float(os.getenv("MAX_MIN")) * 60) + time.time()
|
||||
except Exception:
|
||||
return #same as above
|
||||
while str(endscreen.get_attribute('style')) == "display: none;" and time.time() < timeout:
|
||||
pass
|
||||
sleep(1)
|
||||
return
|
||||
|
||||
|
@ -193,7 +192,6 @@ async def toggleplayback(inter: disnake.AppCmdInter):
|
|||
@bot.slash_command(
|
||||
name="skip",
|
||||
description="skips the current video",
|
||||
default_member_permissions=disnake.Permissions(8192),
|
||||
)
|
||||
async def skip(inter: disnake.AppCmdInter):
|
||||
await inter.response.defer(ephemeral=False)
|
||||
|
@ -204,7 +202,6 @@ async def skip(inter: disnake.AppCmdInter):
|
|||
except asyncio.CancelledError:
|
||||
queue.pop(0)
|
||||
user_queue.pop(0)
|
||||
skip_list.clear()
|
||||
if len(queue) < 1:
|
||||
driver.get(f"file://{os.getcwd()}/waitingforvideo.png")
|
||||
driver.fullscreen_window()
|
||||
|
@ -212,51 +209,6 @@ async def skip(inter: disnake.AppCmdInter):
|
|||
queuetask = asyncio.create_task(queuehandler())
|
||||
await inter.edit_original_response("skipped")
|
||||
|
||||
@bot.slash_command(
|
||||
name="voteskip",
|
||||
description="vote to skip the current video",
|
||||
)
|
||||
async def voteskip(inter: disnake.AppCmdInter):
|
||||
await inter.response.defer(ephemeral=False)
|
||||
if not inter.user.voice:
|
||||
await inter.edit_original_response("You are not in the voice channel")
|
||||
return
|
||||
if inter.user.id in skip_list:
|
||||
await inter.edit_original_response("You have already voted to skip this video")
|
||||
return
|
||||
vc = inter.user.voice.channel.members #this could be better due to potential for abuse, but it's fine for now
|
||||
print(inter.user.voice.channel.name)
|
||||
broadcaster = False
|
||||
for m in vc:
|
||||
if m.voice.self_video or m.voice.self_stream:
|
||||
broadcaster = True
|
||||
break
|
||||
if not broadcaster:
|
||||
await inter.edit_original_response("No one is playing video so how can this be the correct vc?")
|
||||
return
|
||||
skip_list.append(inter.user.id)
|
||||
print(len(skip_list))
|
||||
print(math.floor(len(vc)/2))
|
||||
print(vc)
|
||||
if len(skip_list) >= (math.floor(len(vc)/2)):
|
||||
global queuetask
|
||||
queuetask.cancel()
|
||||
try:
|
||||
await queuetask
|
||||
except asyncio.CancelledError:
|
||||
queue.pop(0)
|
||||
user_queue.pop(0)
|
||||
skip_list.clear()
|
||||
if len(queue) < 1:
|
||||
driver.get(f"file://{os.getcwd()}/waitingforvideo.png")
|
||||
driver.fullscreen_window()
|
||||
else:
|
||||
queuetask = asyncio.create_task(queuehandler())
|
||||
await inter.edit_original_response("skipped as sufficient votes were reached")
|
||||
else:
|
||||
await inter.edit_original_response(f"**{inter.user.display_name}** has voted to skip the video, {len(skip_list)}/{math.floor(len(vc)/2)}")
|
||||
|
||||
|
||||
@bot.slash_command(
|
||||
name="remove",
|
||||
description="removes a video from the queue",
|
||||
|
@ -283,10 +235,10 @@ async def queuehandler():
|
|||
random.shuffle(user_queue)
|
||||
print(queue)
|
||||
print(user_queue)
|
||||
driver.maximize_window()
|
||||
await loop.run_in_executor(None, play_video, queue[0])
|
||||
queue.pop(0)
|
||||
user_queue.pop(0)
|
||||
skip_list.clear()
|
||||
driver.get(f"file://{os.getcwd()}/waitingforvideo.png")
|
||||
driver.fullscreen_window()
|
||||
|
||||
|
|
Loading…
Reference in a new issue