This commit is contained in:
Auric Vente 2024-02-20 00:57:49 -06:00
parent ad4b62bba2
commit 3343cb674a
2 changed files with 22 additions and 9 deletions

View File

@ -32,10 +32,11 @@ Modify `main.py` itself to edit what you need.
Set the path to `gifmaker` and maybe change the `prefix`. 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 ```sh
alias gifmaker="/path/to/venv/bin/python /path/to/gifmaker/src/main.py" #!/usr/bin/env bash
/path/to/gifmaker/venv/bin/python /path/to/gifmaker/src/main.py
``` ```
--- ---

24
main.py
View File

@ -2,6 +2,7 @@ import requests, websockets, asyncio, json, re, traceback, subprocess, os
from datetime import datetime from datetime import datetime
from pathlib import Path from pathlib import Path
HERE = Path(__file__).parent
username = os.environ.get("GLUEBOT_USERNAME") username = os.environ.get("GLUEBOT_USERNAME")
password = os.environ.get("GLUEBOT_PASSWORD") password = os.environ.get("GLUEBOT_PASSWORD")
@ -29,7 +30,7 @@ token = None
session = None session = None
delay = 5 delay = 5
gifmaker = "gifmaker" gifmaker = "/usr/bin/gifmaker"
gm_common = "--font triplex --width 555 --nogrow --output /tmp/gifmaker" gm_common = "--font triplex --width 555 --nogrow --output /tmp/gifmaker"
def update_time(): def update_time():
@ -54,7 +55,7 @@ async def run():
message = await ws.recv() message = await ws.recv()
await on_message(ws, message) await on_message(ws, message)
except KeyboardInterrupt: except KeyboardInterrupt:
return exit(0)
except websockets.exceptions.ConnectionClosedOK: except websockets.exceptions.ConnectionClosedOK:
print("WebSocket connection closed") print("WebSocket connection closed")
except Exception as e: except Exception as e:
@ -105,11 +106,16 @@ async def on_message(ws, message):
update_time() update_time()
await gif_date(None, room_id) await gif_date(None, room_id)
def get_input_path(name):
return str(Path(HERE, name))
async def gif_describe(who, room_id): async def gif_describe(who, room_id):
input_path = get_input_path("describe.jpg")
command = [ command = [
gifmaker, gifmaker,
gm_common, gm_common,
"--input 'describe.jpg'", f"--input '{input_path}'",
f"--words '{who} is [Random] [x5]' --bgcolor 0,0,0", f"--words '{who} is [Random] [x5]' --bgcolor 0,0,0",
"--top 0 --fontsize 2.3 --filter random2", "--top 0 --fontsize 2.3 --filter random2",
] ]
@ -117,10 +123,12 @@ async def gif_describe(who, room_id):
await run_command(command, room_id) await run_command(command, room_id)
async def gif_wins(who, room_id): async def gif_wins(who, room_id):
input_path = get_input_path("wins.gif")
command = [ command = [
gifmaker, gifmaker,
gm_common, gm_common,
"--input 'wins.gif'", f"--input '{input_path}'",
f"--words '{who} wins a ; [repeat] ; [RANDOM] ; [repeat]' --bgcolor 0,0,0 --boldness 2", 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", "--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) await run_command(command, room_id)
async def gif_numbers(who, room_id): async def gif_numbers(who, room_id):
input_path = get_input_path("numbers.png")
command = [ command = [
gifmaker, gifmaker,
gm_common, gm_common,
"--input 'numbers.png'", f"--input '{input_path}'",
"--top 0 --words '[number 1-3] [x3]' --fontcolor 0,0,0", "--top 0 --words '[number 1-3] [x3]' --fontcolor 0,0,0",
] ]
await run_command(command, room_id) await run_command(command, room_id)
async def gif_date(who, room_id): async def gif_date(who, room_id):
input_path = get_input_path("time.jpg")
command = [ command = [
gifmaker, gifmaker,
gm_common, gm_common,
"--input 'time.jpg'", f"--input '{input_path}'",
"--words 'Date: [date %A %d] ; [repeat] ; Time: [date %I:%M %p] ; [repeat]'", "--words 'Date: [date %A %d] ; [repeat] ; Time: [date %I:%M %p] ; [repeat]'",
"--filter anyhue2 --bottom 0 --bgcolor 0,0,0", "--filter anyhue2 --bottom 0 --bgcolor 0,0,0",
] ]