fix for package

main
Yorick van Pelt 2024-04-22 09:21:17 +02:00
parent 1d6f176902
commit c2aceb9a19
Signed by: yorick
GPG Key ID: D8D3CC6D951384DE
7 changed files with 66 additions and 3 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
*/__pycache__/
/config.toml
**/__pycache__/
/result

View File

@ -15,10 +15,13 @@ dependencies = [
"linkify_it_py"
]
[project.entry-points.console_scripts]
yobot = "yobot.cli:main"
[tool.setuptools.packages.find]
include = [
"yobot",
"yobot.plugins",
]
[tool.ruff]

24
yobot/cli.py Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env python
import sys
import yobot.repl
import yobot.bot
import asyncio
def main() -> None:
if len(sys.argv) < 2:
print("usage: $0 repl|bot")
sys.exit(1)
match sys.argv[1]:
case "repl":
asyncio.run(yobot.repl.main())
case "bot":
asyncio.run(yobot.bot.main())
case _:
print("usage: $0 repl|bot")
sys.exit(1)
if __name__ == "__main__":
main()

View File

34
yobot/plugins/s2k.py Normal file
View File

@ -0,0 +1,34 @@
import httpx
from asyncio import timeout
from yobot.interface import ILine, IServer, IPlugin
async def req(token: str, project: int, station: int):
async with httpx.AsyncClient() as client:
headers = {
"Accept": "application/json",
"Authorization": f"Bearer {token}",
}
r = await client.get(f"https://api-v2.acrcloud.com/api/bm-bd-projects/{project}/channels/{station}/realtime_results", headers=headers)
j = r.json()
if "music" not in j["data"]["metadata"]:
return r"snob2000 now playing: ¯\_(ツ)_/¯"
m = j["data"]["metadata"]["music"][0]
title = m["title"]
artist = " & ".join([a["name"] for a in m["artists"]])
return f"snob2000 np: {artist} - {title}"
class Plugin(IPlugin):
def __init__(self, config: dict) -> None:
super().__init__(config)
async def handle(self, bot: IServer, line: ILine) -> None:
msg = line.params[1]
if msg == "!s2k":
async with timeout(10):
np = await req(**self.config)
await bot.reply(line, np)

View File

@ -124,7 +124,7 @@ class Plugin(IPlugin):
async def twitter(self, url: str) -> str:
url = re.sub(
r"^https?://twitter\.com/", self.config["nitter_domain"] + "/", url
r"^https?://twitter\.com/", self.config["nitter_domain"] + "/", url,
)
res = await self.generic(url)
return re.sub(r"\| nitter$", "| twitter", res)

View File

@ -27,8 +27,8 @@ class Srv(IServer):
s = await ainput("<user> ")
await self.line_read(
ILine(
source="user", tags={}, command="PRIVMSG", params=["#test", s]
)
source="user", tags={}, command="PRIVMSG", params=["#test", s],
),
)
except EOFError:
pass