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