Add !bottleclip <icon> <ears> command
This commit is contained in:
parent
07cab2d2d1
commit
581665fa95
3 changed files with 65 additions and 0 deletions
62
main.py
62
main.py
|
@ -5,6 +5,7 @@ import os
|
|||
import sys
|
||||
from time import sleep
|
||||
|
||||
import aiohttp
|
||||
import aiomqtt
|
||||
import pytz
|
||||
from discord import Intents
|
||||
|
@ -26,6 +27,11 @@ if not webhook_url:
|
|||
print("DISCORD_WEBHOOK_URL unset")
|
||||
sys.exit(1)
|
||||
|
||||
bottleclip_git_token = os.getenv("BOTTLECLIP_GIT_TOKEN")
|
||||
if not bottleclip_git_token:
|
||||
print("BOTTLECLIP_GIT_TOKEN unset")
|
||||
sys.exit(1)
|
||||
|
||||
timezone = pytz.timezone("Europe/Amsterdam")
|
||||
|
||||
# Discord bot stuff
|
||||
|
@ -107,6 +113,62 @@ async def np(ctx):
|
|||
await ctx.send("Now playing: Darude - Sandstorm")
|
||||
|
||||
|
||||
# !bottleclip
|
||||
@HobbyBot.command(description="Generate a bottle-clip STL file suitable for printing")
|
||||
async def bottleclip(ctx, icon: str, ears: bool = False):
|
||||
git_api = "https://git.bitlair.nl/api/v1"
|
||||
owner = "bitlair"
|
||||
repo = "bottle-clip"
|
||||
flow = "stl.yaml"
|
||||
auth = {
|
||||
"Authorization": f"Bearer {bottleclip_git_token}",
|
||||
}
|
||||
|
||||
icons = {
|
||||
"thing-logos/glider.dxf",
|
||||
"thing-logos/Club_mate_logo.dxf",
|
||||
"thing-logos/chaosknoten.dxf",
|
||||
"thing-logos/camprocket.dxf",
|
||||
"pixel-cats/laying-left.svg",
|
||||
"pixel-cats/laying-right.svg",
|
||||
"pixel-cats/sitting-left.svg",
|
||||
"pixel-cats/sitting-right.svg",
|
||||
"pixel-cats/spooked-left.svg",
|
||||
"pixel-cats/spooked-right.svg",
|
||||
"pixel-cats/standing-left.svg",
|
||||
"pixel-cats/standing-right.svg",
|
||||
}
|
||||
if icon not in icons:
|
||||
await ctx.reply(f"arg1 must be one of {', '.join(icons)}")
|
||||
return
|
||||
|
||||
async with ctx.typing():
|
||||
async with aiohttp.ClientSession() as sess:
|
||||
dispatch_body = {
|
||||
"inputs": {
|
||||
"label": ctx.author.nick,
|
||||
"icon": icon,
|
||||
"ears": "true" if ears else "false",
|
||||
},
|
||||
"ref": "main",
|
||||
"return_run_info": True,
|
||||
}
|
||||
async with sess.post(
|
||||
f"{git_api}/repos/{owner}/{repo}/actions/workflows/{flow}/dispatches",
|
||||
headers=auth,
|
||||
json=dispatch_body,
|
||||
) as response:
|
||||
if response.status != 201:
|
||||
await ctx.reply("Meh, stuk")
|
||||
return
|
||||
r = await response.json()
|
||||
run_number = r["run_number"]
|
||||
|
||||
await ctx.reply(
|
||||
f"https://git.bitlair.nl/bitlair/bottle-clip/actions/runs/{run_number}"
|
||||
)
|
||||
|
||||
|
||||
def webhook_message(msg):
|
||||
webhook = DiscordWebhook(url=webhook_url, rate_limit_retry=True, content=msg)
|
||||
webhook.execute()
|
||||
|
|
|
@ -5,6 +5,7 @@ description = "Bitlair Discord Bot"
|
|||
readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
dependencies = [
|
||||
"aiohttp>=3.11.18",
|
||||
"aiomqtt>=2.4.0",
|
||||
"discord-py>=2.5.2",
|
||||
"discord-webhook>=1.4.1",
|
||||
|
|
2
uv.lock
generated
2
uv.lock
generated
|
@ -186,6 +186,7 @@ name = "discord-bot"
|
|||
version = "0.1.0"
|
||||
source = { virtual = "." }
|
||||
dependencies = [
|
||||
{ name = "aiohttp" },
|
||||
{ name = "aiomqtt" },
|
||||
{ name = "discord-py" },
|
||||
{ name = "discord-webhook" },
|
||||
|
@ -194,6 +195,7 @@ dependencies = [
|
|||
|
||||
[package.metadata]
|
||||
requires-dist = [
|
||||
{ name = "aiohttp", specifier = ">=3.11.18" },
|
||||
{ name = "aiomqtt", specifier = ">=2.4.0" },
|
||||
{ name = "discord-py", specifier = ">=2.5.2" },
|
||||
{ name = "discord-webhook", specifier = ">=1.4.1" },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue