mirror of
https://github.com/MichaByte/OnBoard-Live.git
synced 2026-01-29 13:32:12 -05:00
wip
This commit is contained in:
parent
8308b22d89
commit
960e437706
2 changed files with 10 additions and 7 deletions
|
|
@ -27,12 +27,16 @@ async def update_active():
|
||||||
global active_stream
|
global active_stream
|
||||||
global active_streams
|
global active_streams
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
|
try:
|
||||||
|
await db.connect()
|
||||||
|
except: pass
|
||||||
streams_raw = (await client.get("http://localhost:9997/v3/paths/list")).json()[
|
streams_raw = (await client.get("http://localhost:9997/v3/paths/list")).json()[
|
||||||
"items"
|
"items"
|
||||||
]
|
]
|
||||||
streams = []
|
streams = []
|
||||||
for stream in streams_raw:
|
for stream in streams_raw:
|
||||||
streams.append({"name": stream["name"], "ready": stream["ready"]})
|
print(stream)
|
||||||
|
streams.append({"name": stream["name"], "ready": stream["ready"], "person_name": (await db.user.find_first_or_raise(where={"id":(await db.stream.find_first_or_raise(where={"key": str(stream["name"])})).user_id})).name.split(" ")[0]}) # type: ignore
|
||||||
for stream in streams:
|
for stream in streams:
|
||||||
if stream["ready"] and stream not in active_streams:
|
if stream["ready"] and stream not in active_streams:
|
||||||
active_streams.append(stream)
|
active_streams.append(stream)
|
||||||
|
|
@ -55,10 +59,7 @@ async def update_active():
|
||||||
)
|
)
|
||||||
new_stream = choice(active_streams)
|
new_stream = choice(active_streams)
|
||||||
print(f"found new stream to make active: {new_stream}")
|
print(f"found new stream to make active: {new_stream}")
|
||||||
try:
|
|
||||||
await db.connect()
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
print(f"trying to find user associated with stream {active_stream['name']}")
|
print(f"trying to find user associated with stream {active_stream['name']}")
|
||||||
old_active_stream_user = await db.user.find_first(where={"id": (await db.stream.find_first(where={"key": str(active_stream["name"])})).user_id}) # type: ignore
|
old_active_stream_user = await db.user.find_first(where={"id": (await db.stream.find_first(where={"key": str(active_stream["name"])})).user_id}) # type: ignore
|
||||||
await bolt.client.chat_postMessage(channel="C07ERCGG989", text=f"Hey <@{old_active_stream_user.slack_id}>, you're no longer in focus!") # type: ignore
|
await bolt.client.chat_postMessage(channel="C07ERCGG989", text=f"Hey <@{old_active_stream_user.slack_id}>, you're no longer in focus!") # type: ignore
|
||||||
|
|
@ -148,7 +149,7 @@ async def get_stream_by_key(stream_key: str):
|
||||||
|
|
||||||
@api.get("/api/v1/active_stream")
|
@api.get("/api/v1/active_stream")
|
||||||
async def get_active_stream():
|
async def get_active_stream():
|
||||||
return active_stream["name"] if "name" in active_stream else ""
|
return str(active_stream["name"]) + "," + str(active_stream["person_name"]) if "name" in active_stream else ""
|
||||||
|
|
||||||
|
|
||||||
@bolt.event("app_home_opened")
|
@bolt.event("app_home_opened")
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
}[]
|
}[]
|
||||||
| null = null;
|
| null = null;
|
||||||
$: activeStream = "";
|
$: activeStream = "";
|
||||||
|
$: activeStreamerName = "";
|
||||||
$: oldActiveStream = "";
|
$: oldActiveStream = "";
|
||||||
let newData: {
|
let newData: {
|
||||||
ready: boolean;
|
ready: boolean;
|
||||||
|
|
@ -22,7 +23,8 @@
|
||||||
const activeStreamResponse = await fetch(
|
const activeStreamResponse = await fetch(
|
||||||
"http://localhost:8000/api/v1/active_stream",
|
"http://localhost:8000/api/v1/active_stream",
|
||||||
);
|
);
|
||||||
activeStream = (await activeStreamResponse.text()).replaceAll('"', "");
|
activeStream = (await activeStreamResponse.text()).replaceAll('"', "").split(",")[0];
|
||||||
|
activeStreamerName = (await activeStreamResponse.text()).replaceAll('"', "").split(",")[1];
|
||||||
// if (oldActiveStream !== null && oldActiveStream !== activeStream) {
|
// if (oldActiveStream !== null && oldActiveStream !== activeStream) {
|
||||||
// window.location.reload();
|
// window.location.reload();
|
||||||
// }
|
// }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue