Compare commits
2 commits
mautrix-ss
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6afa75b638 | ||
|
|
195aeff39e |
1 changed files with 8 additions and 3 deletions
|
|
@ -472,16 +472,16 @@ async def main():
|
||||||
client.access_token = creds["access_token"]
|
client.access_token = creds["access_token"]
|
||||||
client.user_id = creds["user_id"]
|
client.user_id = creds["user_id"]
|
||||||
client.device_id = creds["device_id"]
|
client.device_id = creds["device_id"]
|
||||||
|
client.load_store()
|
||||||
session_restored = True
|
session_restored = True
|
||||||
except (json.JSONDecodeError, KeyError) as e:
|
except (json.JSONDecodeError, KeyError) as e:
|
||||||
print(f"⚠️ Credentials file is empty or corrupted ({e}). Discarding and forcing new login...")
|
print(f"⚠️ Credentials file is empty or corrupted ({e}). Discarding and forcing new login...")
|
||||||
|
|
||||||
# 2. If no session exists or restoration failed, log in and save the credentials
|
# 2. If no session exists or restoration failed, log in and save credentials
|
||||||
if not session_restored:
|
if not session_restored:
|
||||||
print(f"No valid session found. Logging in to {MATRIX_HOMESERVER}...")
|
print(f"No valid session found. Logging in to {MATRIX_HOMESERVER}...")
|
||||||
resp = await client.login(MATRIX_BOT_PASSWORD)
|
resp = await client.login(MATRIX_BOT_PASSWORD)
|
||||||
|
|
||||||
# Create the store directory if it doesn't exist
|
|
||||||
os.makedirs(os.path.dirname(CREDENTIALS_FILE), exist_ok=True)
|
os.makedirs(os.path.dirname(CREDENTIALS_FILE), exist_ok=True)
|
||||||
|
|
||||||
with open(CREDENTIALS_FILE, "w") as f:
|
with open(CREDENTIALS_FILE, "w") as f:
|
||||||
|
|
@ -492,8 +492,13 @@ async def main():
|
||||||
}, f)
|
}, f)
|
||||||
print(f"Logged in and saved credentials for {MATRIX_BOT_USER}.")
|
print(f"Logged in and saved credentials for {MATRIX_BOT_USER}.")
|
||||||
|
|
||||||
|
# Optional: Perform an initial full state sync ONCE on startup
|
||||||
|
print("Performing initial state sync...")
|
||||||
|
await client.sync(full_state=True)
|
||||||
|
|
||||||
|
# Start the continuous sync loop WITHOUT full_state=True and with a 20s timeout
|
||||||
print("Syncing...")
|
print("Syncing...")
|
||||||
await client.sync_forever(timeout=30000, full_state=True)
|
await client.sync_forever(timeout=20000, full_state=False)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue