This commit is contained in:
Auric Vente 2024-02-23 20:02:54 -06:00
parent 19ac6fca34
commit c2b1bdee91
1 changed files with 13 additions and 23 deletions

36
main.py
View File

@ -112,12 +112,9 @@ def auth():
exit(1) exit(1)
data = {"name": username, "password": password, "submit": "log+in"} data = {"name": username, "password": password, "submit": "log+in"}
res = requests.post(url + "/login/submit", headers=headers, res = requests.post(url + "/login/submit", headers=headers, data=data, allow_redirects=False)
data=data, allow_redirects=False) token = re.search("(?:api_token)=[^;]+", res.headers.get("Set-Cookie")).group(0)
token = re.search("(?:api_token)=[^;]+", session = re.search("(?:session_id)=[^;]+", res.headers.get("Set-Cookie")).group(0)
res.headers.get("Set-Cookie")).group(0)
session = re.search(
"(?:session_id)=[^;]+", res.headers.get("Set-Cookie")).group(0)
headers["Cookie"] = token + "; " + session headers["Cookie"] = token + "; " + session
@ -191,7 +188,7 @@ async def on_message(ws, message):
elif cmd == "date" or cmd == "data" or cmd == "time" or cmd == "datetime": elif cmd == "date" or cmd == "data" or cmd == "time" or cmd == "datetime":
update_time() update_time()
await gif_date(None, room_id) await gif_date(room_id)
elif cmd == "bird" or cmd == "birds" or cmd == "birb" or cmd == "birbs" or cmd == "brb": elif cmd == "bird" or cmd == "birds" or cmd == "birb" or cmd == "birbs" or cmd == "brb":
update_time() update_time()
@ -255,12 +252,9 @@ async def gif_numbers(arg, room_id):
else: else:
num = random_int(0, nums[0]) num = random_int(0, nums[0])
if num == -1: if num == -1: num = string_to_number(arg)
num = string_to_number(arg)
if num == -1:
num = random_int(0, 999)
if num == -1: num = random_int(0, 999)
input_path = get_path("numbers.png") input_path = get_path("numbers.png")
command = [ command = [
@ -274,7 +268,7 @@ async def gif_numbers(arg, room_id):
await run_gifmaker(command, room_id) await run_gifmaker(command, room_id)
async def gif_date(who, room_id): async def gif_date(room_id):
input_path = get_path("time.jpg") input_path = get_path("time.jpg")
command = [ command = [
@ -313,8 +307,7 @@ async def random_post(ws, room_id):
# Select a random post # Select a random post
post = posts[random_int(0, len(posts) - 1)] post = posts[random_int(0, len(posts) - 1)]
html = post.get("com", "") html = post.get("com", "")
if not html: if not html: return
return
# Parse HTML using BeautifulSoup # Parse HTML using BeautifulSoup
soup = BeautifulSoup(html, "html.parser") soup = BeautifulSoup(html, "html.parser")
@ -330,9 +323,9 @@ async def random_post(ws, room_id):
# Get text content and limit to 500 characters # Get text content and limit to 500 characters
text = soup.get_text(separator="\n")[:500].strip() text = soup.get_text(separator="\n")[:500].strip()
text = clean_lines(text) text = clean_lines(text)
if not text: return
if text: await send_message(ws, text, room_id)
await send_message(ws, text, room_id)
except Exception as err: except Exception as err:
print(f"Error: {err}") print(f"Error: {err}")
@ -365,14 +358,11 @@ async def upload(path, room_id):
} }
ext = get_extension(path) ext = get_extension(path)
ext = "jpeg" if ext == "jpg" else ext
if ext == "jpg":
ext = "jpeg"
url = "https://deek.chat/message/send/" + str(room_id) url = "https://deek.chat/message/send/" + str(room_id)
data = aiohttp.FormData() data = aiohttp.FormData()
data.add_field(name="files[]", value=open(path, "rb"), data.add_field(name="files[]", value=open(path, "rb"), filename=path.name, content_type=f"image/{ext}")
filename=path.name, content_type=f"image/{ext}")
try: try:
async with aiohttp.ClientSession(cookies=cookies) as sess: async with aiohttp.ClientSession(cookies=cookies) as sess: