Skip to content

Commit

Permalink
Completed #24 (tested)
Browse files Browse the repository at this point in the history
- Moved close_premium_banner() to utils
- misc.ClipUploader now closes premium banner
  • Loading branch information
thelabcat committed Sep 20, 2024
1 parent 67b2599 commit 26c16e5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
21 changes: 1 addition & 20 deletions src/rumchat_actor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def __init__(self, init_message = "Hello, Rumble!", ignore_users = ["TheRumbleBo
assert "Chat" in self.driver.title

#Close the premium banner if it is there
self.__close_premium_banner()
utils.close_premium_banner(self.driver)

#Sign in to chat, unless we are already. While there is a sign-in button...
first_time = True
Expand Down Expand Up @@ -303,25 +303,6 @@ def streamer_main_page_url(self):

return self.__streamer_main_page_url

def __close_premium_banner(self):
"""If the premium banner is visible, close it"""
print("Looking to close Premium banner")
try:
close_button = self.driver.find_element(By.CSS_SELECTOR, "[data-js='premium-popup__close-button'][aria-label='Close']")
print("Close button found.", close_button.get_attribute('outerHTML'))

except selenium.common.exceptions.NoSuchElementException:
print("Close button not present, premium banner presumed already closed.")
return

print("Egg timer for premium banner to display")
time.sleep(static.Driver.premium_banner_delay)

close_button.click()
print("Clicked close button. Egg timer for banner to hide")
time.sleep(static.Driver.premium_banner_delay)
print("Premium banner closed.")

def get_sign_in_button(self):
"""Look for the sign in button"""
try:
Expand Down
5 changes: 4 additions & 1 deletion src/rumchat_actor/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.select import Select
from . import static
from . import static, utils

class ClipUploader():
"""Upload clips to Rumble automatically"""
Expand Down Expand Up @@ -44,6 +44,9 @@ def __init__(self, actor, clip_command, **kwargs):
#Load the upload page
self.driver.get(static.URI.upload_page)

#Close the premium banner if it is there
utils.close_premium_banner(self.driver)

#Wait for sign in
while "login" in self.driver.current_url:
if "username" in kwargs:
Expand Down
24 changes: 24 additions & 0 deletions src/rumchat_actor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,36 @@
#from pathlib import Path
from cocorum.utils import *
#from js2py import eval_js
import selenium
from selenium.webdriver.common.by import By
from . import static

def is_staff(user):
"""Check if a user is channel staff"""
return True in [badge in user.badges for badge in static.Moderation.staff_badges]

def close_premium_banner(driver):
"""If the premium banner is visible in a driver, close it"""
print("Looking to close Premium banner")
try:
close_button = driver.find_element(By.CSS_SELECTOR, "[data-js='premium-popup__close-button'][aria-label='Close']")
print("Close button found.")

except selenium.common.exceptions.NoSuchElementException:
print("Close button not present, premium banner presumed already closed.")
return

print("Egg timer for premium banner to display")
time.sleep(static.Driver.premium_banner_delay)

try:
close_button.click()
print("Clicked close button. Egg timer for banner to hide")
time.sleep(static.Driver.premium_banner_delay)
print("Premium banner closed.")
except selenium.common.exceptions.ElementClickInterceptedException:
print("Close button not clickable after wait, premium banner presumed already closed.")

# def calc_password_hashes(password, salts):
# """Hash a password given the salts"""
# with open(pjoin(Path(__file__).parent, pjoin("dom_scripts", "md5Ex.js")), 'r') as f:
Expand Down

0 comments on commit 26c16e5

Please sign in to comment.