Skip to main content

Super early lib for interacting with Matrix

Project description

matrix-bot-lib

Requires python >= 3.10

TODO

  • e2e crypto
  • Better models and validation -> Refactor EventMetadata and EventMessage -> Better (more loose?) signature for EventData

How to use

import os
from getpass import getpass
from shlex import join as cmd_join
from matrix_bot_lib import MatrixBot

async def main() -> None:
    BOT_USER = "@dtuhax-bot:xn--sb-lka.org"
    BOT_PASS = getpass(f'Password for {BOT_USER}: ')

    bot = MatrixBot(BOT_USER)
    await bot.login(BOT_PASS)

    @bot.on_message
    async def recv_msg(room_id: str, content: dict, metadata: dict):
        match content:
            case {'body': msg_txt, 'msgtype': 'm.text'}:
                print(f'Message: {msg_txt}')

    @bot.on_reaction
    async def recv_react(room_id: str, content: dict, metadata: dict):
        """ MSC2677 """
        match content:
            case {'m.relates_to': {'rel_type': 'm.annotation', 'key': emoji}}:
                print(f'Reaction: {emoji}')  # e.g. '🚪'

    await bot.run(full_sync=False)

if __name__ == '__main__':
    import asyncio
    asyncio.run(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matrix_bot_lib-0.1.8.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

matrix_bot_lib-0.1.8-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file matrix_bot_lib-0.1.8.tar.gz.

File metadata

  • Download URL: matrix_bot_lib-0.1.8.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for matrix_bot_lib-0.1.8.tar.gz
Algorithm Hash digest
SHA256 0bf2c145e63f813dcfd07de38e97b58283eee9e310ff8afb4468983d9a41f1dd
MD5 feb397de012fc1ba0eb21d08e8fddebd
BLAKE2b-256 57149275a75928d0100866ab266eb0bfca195c503a299534a5814e752285984b

See more details on using hashes here.

Provenance

The following attestation bundles were made for matrix_bot_lib-0.1.8.tar.gz:

Publisher: release.yml on NicolaiSoeborg/matrix-bot-lib

Attestations:

File details

Details for the file matrix_bot_lib-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for matrix_bot_lib-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 e60d7ed524a9d6ff01a43eca710aed65b8270f13e0d5bc33e635d2075641962a
MD5 c4e1e4c7bf4b97b64c35998a7e26cc0d
BLAKE2b-256 beaac2230995dab99c62c151231a971ac867a7f6046f7bf4c21f9f09319c8dda

See more details on using hashes here.

Provenance

The following attestation bundles were made for matrix_bot_lib-0.1.8-py3-none-any.whl:

Publisher: release.yml on NicolaiSoeborg/matrix-bot-lib

Attestations:

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page