From 3343cb674aaee8232ab2b778aba70e185bea2582 Mon Sep 17 00:00:00 2001 From: Auric Vente Date: Tue, 20 Feb 2024 00:57:49 -0600 Subject: [PATCH] Mods --- README.md | 7 ++++--- main.py | 24 ++++++++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 61dc166..c7f0525 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,11 @@ Modify `main.py` itself to edit what you need. Set the path to `gifmaker` and maybe change the `prefix`. -You could make an alias for gifmaker: +By default it points to `/usr/bin/gifmaker`. -```shell -alias gifmaker="/path/to/venv/bin/python /path/to/gifmaker/src/main.py" +```sh +#!/usr/bin/env bash +/path/to/gifmaker/venv/bin/python /path/to/gifmaker/src/main.py ``` --- diff --git a/main.py b/main.py index c344752..89fd812 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ import requests, websockets, asyncio, json, re, traceback, subprocess, os from datetime import datetime from pathlib import Path +HERE = Path(__file__).parent username = os.environ.get("GLUEBOT_USERNAME") password = os.environ.get("GLUEBOT_PASSWORD") @@ -29,7 +30,7 @@ token = None session = None delay = 5 -gifmaker = "gifmaker" +gifmaker = "/usr/bin/gifmaker" gm_common = "--font triplex --width 555 --nogrow --output /tmp/gifmaker" def update_time(): @@ -54,7 +55,7 @@ async def run(): message = await ws.recv() await on_message(ws, message) except KeyboardInterrupt: - return + exit(0) except websockets.exceptions.ConnectionClosedOK: print("WebSocket connection closed") except Exception as e: @@ -105,11 +106,16 @@ async def on_message(ws, message): update_time() await gif_date(None, room_id) +def get_input_path(name): + return str(Path(HERE, name)) + async def gif_describe(who, room_id): + input_path = get_input_path("describe.jpg") + command = [ gifmaker, gm_common, - "--input 'describe.jpg'", + f"--input '{input_path}'", f"--words '{who} is [Random] [x5]' --bgcolor 0,0,0", "--top 0 --fontsize 2.3 --filter random2", ] @@ -117,10 +123,12 @@ async def gif_describe(who, room_id): await run_command(command, room_id) async def gif_wins(who, room_id): + input_path = get_input_path("wins.gif") + command = [ gifmaker, gm_common, - "--input 'wins.gif'", + f"--input '{input_path}'", f"--words '{who} wins a ; [repeat] ; [RANDOM] ; [repeat]' --bgcolor 0,0,0 --boldness 2", "--bottom 0 --fontsize 1.4 --boldness 2 --filter anyhue2 --framelist 11,11,33,33", ] @@ -128,20 +136,24 @@ async def gif_wins(who, room_id): await run_command(command, room_id) async def gif_numbers(who, room_id): + input_path = get_input_path("numbers.png") + command = [ gifmaker, gm_common, - "--input 'numbers.png'", + f"--input '{input_path}'", "--top 0 --words '[number 1-3] [x3]' --fontcolor 0,0,0", ] await run_command(command, room_id) async def gif_date(who, room_id): + input_path = get_input_path("time.jpg") + command = [ gifmaker, gm_common, - "--input 'time.jpg'", + f"--input '{input_path}'", "--words 'Date: [date %A %d] ; [repeat] ; Time: [date %I:%M %p] ; [repeat]'", "--filter anyhue2 --bottom 0 --bgcolor 0,0,0", ]