diff options
Diffstat (limited to 'matrix-redact.py')
-rw-r--r-- | matrix-redact.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/matrix-redact.py b/matrix-redact.py new file mode 100644 index 0000000..8be0605 --- /dev/null +++ b/matrix-redact.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 + +""" +matrix-redact: Delete all messages and media a user has sent in a matrix room. +""" + +import asyncio +import argparse +import getpass +import sys +import subprocess +from nio import( + AsyncClient, + MatrixRoom, + LoginResponse, + responses +) +from typing import Optional + + +# TODO: select_room +async def select_room(client: AsyncClient, sync_response) -> MatrixRoom: + return None + +async def client_login() -> Optional[AsyncClient]: + uid = input("Full user ID (eg. @user:matrix.server.com): ") + upass = getpass.getpass(f"Enter the password for {uid}: ") + user, hserv = uid[1:].split(':', 1) + client = AsyncClient(f"https://{hserv}", uid) + + if not isinstance(await client.login(upass), LoginResponse): + print("could not login, returning None") + return None + print("login was successful, returning client.") + return client + +# TODO: redact_room +async def redact_room() -> None: + # TODO: ensure user is 100% sure (verify correct room, etc.). This is a permanent action + return None + +async def main(args) -> None: + client = None + + try: + client = await client_login() + if not client: + print("Could not login.") + sys.exit(1) + + sync_resp = await client.sync(timeout=30000, full_state=True) + room = select_room(client, sync_resp) + + except Exception as e: + print(f"Error: {e}") + finally: + if client: + print("logging out.") + await client.logout() + await client.close() + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + description="matrix-mcnt: Matrix Unread Message Count" + ) + + asyncio.run(main(parser.parse_args())) |