communication(atlasbot): reduce spam and use atlasbot user
This commit is contained in:
parent
1f554e583a
commit
0f1f34c52a
@ -53,7 +53,6 @@ data:
|
||||
req("POST", path, token, body={"msgtype": "m.text", "body": text})
|
||||
|
||||
history = collections.defaultdict(list) # room_id -> list of str (short transcript)
|
||||
greeted = set()
|
||||
|
||||
def ollama_reply(room_id: str, prompt: str) -> str:
|
||||
try:
|
||||
@ -74,6 +73,11 @@ data:
|
||||
|
||||
def sync_loop(token: str, room_id: str):
|
||||
since = None
|
||||
try:
|
||||
res = req("GET", "/_matrix/client/v3/sync?timeout=0", token, timeout=10)
|
||||
since = res.get("next_batch")
|
||||
except Exception:
|
||||
pass
|
||||
while True:
|
||||
params = {"timeout": 30000}
|
||||
if since:
|
||||
@ -90,15 +94,11 @@ data:
|
||||
for rid, data in res.get("rooms", {}).get("invite", {}).items():
|
||||
try:
|
||||
join_room(token, rid)
|
||||
send_msg(token, rid, "Atlas online.")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# messages
|
||||
for rid, data in res.get("rooms", {}).get("join", {}).items():
|
||||
if rid not in greeted and room_id and rid == room_id:
|
||||
greeted.add(rid)
|
||||
send_msg(token, rid, "Atlas online.")
|
||||
timeline = data.get("timeline", {}).get("events", [])
|
||||
for ev in timeline:
|
||||
if ev.get("type") != "m.room.message":
|
||||
@ -113,7 +113,7 @@ data:
|
||||
# Only respond if bot is mentioned or in a DM
|
||||
joined_count = data.get("summary", {}).get("m.joined_member_count")
|
||||
is_dm = joined_count is not None and joined_count <= 2
|
||||
mentioned = f"@{USER}" in body or "atlas" in body.lower()
|
||||
mentioned = f"@{USER}" in body
|
||||
history[rid].append(f"{sender}: {body}")
|
||||
if is_dm or mentioned:
|
||||
reply = ollama_reply(rid, body)
|
||||
|
||||
@ -29,14 +29,14 @@ spec:
|
||||
- name: MATRIX_BASE
|
||||
value: http://othrys-synapse-matrix-synapse:8008
|
||||
- name: AUTH_BASE
|
||||
value: http://matrix-authentication-service:8080
|
||||
value: http://othrys-synapse-matrix-synapse:8008
|
||||
- name: BOT_USER
|
||||
value: atlas
|
||||
value: atlasbot
|
||||
- name: BOT_PASS
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: atlasbot-mas-credentials-runtime
|
||||
key: password
|
||||
name: atlasbot-credentials-runtime
|
||||
key: bot-password
|
||||
- name: CHAT_API_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user