From 8ab18265fa7b40bc044373c278fe642e8e20cd1d Mon Sep 17 00:00:00 2001 From: Auric Vente Date: Thu, 22 Feb 2024 11:29:33 -0600 Subject: [PATCH] Mods --- main.py | 37 ++++++++++++++++--------------------- requirements.txt | 3 ++- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/main.py b/main.py index 20794b6..482fdd5 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,7 @@ import traceback, subprocess, os, aiohttp, sys, random from bs4 import BeautifulSoup from datetime import datetime from pathlib import Path +import aiofiles HERE = Path(__file__).parent username = os.environ.get("GLUEBOT_USERNAME") @@ -30,6 +31,9 @@ def clean_lines(s): def random_int(min_val, max_val): return random.randint(min_val, max_val) +def get_path(name): + return str(Path(HERE, name)) + headers = { "User-Agent": "gluebot", "Origin": "https://deek.chat", @@ -132,17 +136,22 @@ async def on_message(ws, message): elif cmd == "bird" or cmd == "birds" or cmd == "birb" or cmd == "birbs" or cmd == "brb": update_time() - await gif_bird(None, room_id) + await random_bird(ws, room_id) elif cmd == "post" or cmd == "shitpost" or cmd == "4chan" or cmd == "anon" or cmd == "shit": update_time() await random_post(ws, room_id) -def get_input_path(name): - return str(Path(HERE, name)) +async def random_bird(ws, room_id): + birdfile = get_path("data/aves.txt") + + async with aiofiles.open(birdfile, mode="r", encoding="utf-8") as file: + birds = await file.readlines() + bird = random.choice(birds).strip() + await send_message(ws, f".i {bird} bird", room_id) async def gif_describe(who, room_id): - input_path = get_input_path("describe.jpg") + input_path = get_path("describe.jpg") command = [ gifmaker, @@ -156,7 +165,7 @@ async def gif_describe(who, room_id): await run_gifmaker(command, room_id) async def gif_wins(who, room_id): - input_path = get_input_path("wins.gif") + input_path = get_path("wins.gif") command = [ gifmaker, @@ -169,7 +178,7 @@ async def gif_wins(who, room_id): await run_gifmaker(command, room_id) async def gif_numbers(who, room_id): - input_path = get_input_path("numbers.png") + input_path = get_path("numbers.png") command = [ gifmaker, @@ -181,7 +190,7 @@ async def gif_numbers(who, room_id): await run_gifmaker(command, room_id) async def gif_date(who, room_id): - input_path = get_input_path("time.jpg") + input_path = get_path("time.jpg") command = [ gifmaker, @@ -193,20 +202,6 @@ async def gif_date(who, room_id): await run_gifmaker(command, room_id) -async def gif_bird(who, room_id): - input_path = get_input_path("bird.png") - - command = [ - gifmaker, - gm_common, - f"--input '{input_path}'", - "--words '[randomx]' --randomfile data/aves.txt --bgcolor 0,0,0", - "--filter anyhue2 --frames 3 --fontsize 42 --fillwords", - "--fontcolor light --bgcolor dark --outline font --opacity 0.9", - ] - - await run_gifmaker(command, room_id) - async def random_post(ws, room_id): boards = ["g", "an", "ck", "lit", "x", "tv", "v", "fit", "k", "o"] board = random.choice(boards) diff --git a/requirements.txt b/requirements.txt index b2c5a68..461af9b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ requests ~= 2.31.0 websockets ~= 12.0 aiohttp ~= 3.9.3 beautifulsoup4 ~= 4.12.3 -httpx ~= 0.27.0 \ No newline at end of file +httpx ~= 0.27.0 +aiofiles ~= 23.2.1 \ No newline at end of file