Skip to main content

Halcyon is an easy to use matrix library

Project description

Halcyon on and on

Halcyon is a Matrix bot library with the goal of being easy to install and use. The library takes inspiration from discord.py and the Slack libraries. Encryption is on the roadmap, and with the goal of being transparent to the user. Check the roadmap in notes.md, and see information of the token format in tokenFormat.md

Ask questions in the matrix chat #halcyon:blackline.xyz or in GitHub issues.

Current features

  • A nice CLI tool to generate Halcyon tokens
  • Login with token or username/password
  • Fetch for new messages every x seconds using await
  • Event hooks for
    • on_message(self, message)
    • on_message_edit(self, message)
    • on_room_invite(self, room)
    • on_room_leave(self, roomID)
  • Action hooks
    • send_message(self, roomID, body, textFormat=None, replyTo=None, isNotice=False)
    • async def join_room(self, roomID)
  • Room and message objects for incoming events events
  • Documentation

Getting started

  1. Create a matrix account for the bot
  2. Install Halcyon using python3 -m pip install halcyon or download it from the Releases tab in Github
  3. Generate a token using python3 -m halcyon -s homeserver.xyz -u @user:homeserver.xyz -p yourP@$$w0rd
  4. Start with the demo code below

Example bot code

See more example and message object info in usage.md

import halcyon
import requests, json

client = halcyon.Client()

@client.event
async def on_room_invite(room):
    """On room invite, autojoin and say hello"""
    print("Someone invited us to join " + room.name)
    await client.join_room(room.id)
    await client.send_message(room.id, body="Hello humans")


@client.event
async def on_message(message):
    """If we see a message with the phrase 'give me random', do a reply message with 32 random characters"""
    print(message.event.id)
    if "give me random" in message.content.body:
        body = "This looks random: " + requests.get("https://random.wesring.com").json()["value"]
        await client.send_message(message.room.id, body=body, replyTo=message.event.id)


if __name__ == '__main__':
    client.run(halcyonToken="eyJ0eXAiO...")

CLI usage

halcyon can be called from the CLI to do some management of the account.
See the help message with python3 -m halcyon -h Right now it can be used to

  1. generate a new token
  2. decode an existing token
  3. revoke a single token
  4. revoke all tokens
usage: halcyon [-h] [-s SERVER] [-u USERNAME] [-p PASSWORD] [--include-password] [--decode DECODE] [--pretty] [--revoke REVOKE] [--revoke-all-tokens REVOKE_ALL_TOKENS]

By this, you can generate a halcyonToken for your project, for example python3 -m halcyon -s matrix.org -u @kevin:matrix.org -p on&on&on1337

optional arguments:
  -h, --help            show this help message and exit
  -s SERVER, --server SERVER
                        Homeserver the user belongs to ex: matrix.org
  -u USERNAME, --username USERNAME
                        Your full username ex: @kevin:matrix.org
  -p PASSWORD, --password PASSWORD
                        Your full password for your matrix account
  --include-password    Save your username and password in the token for reauth (Not required right now since matrix tokens do not expire)
  --decode DECODE       Decode an existing token that you pass in
  --pretty              Pretty print the decoded token
  --revoke REVOKE       Revoke an existing token
  --revoke-all-tokens REVOKE_ALL_TOKENS
                        Revoke an all existing token for the account

Have fun creating

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

halcyon-1.0.4.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

halcyon-1.0.4-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file halcyon-1.0.4.tar.gz.

File metadata

  • Download URL: halcyon-1.0.4.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for halcyon-1.0.4.tar.gz
Algorithm Hash digest
SHA256 ee5ec7e398bcb830f7792e7015df6feb6415b028408cd25342fb5bc8623bdfca
MD5 77e9f16ef4714bcad08ab4615e606659
BLAKE2b-256 83b3dd000b5bcae975b56ade1bd3ea934cda02c1d01996e5b37452be2b26d29c

See more details on using hashes here.

File details

Details for the file halcyon-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: halcyon-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for halcyon-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9fcc96521fcdf1f0b5f921565b286541c42cc3c2e9d937bf7b06395b9c1ec4ed
MD5 e1960512ff0369769f0836cf635fd225
BLAKE2b-256 a0299b422854b6a165dd55491b7a63025a0428d4314388b0b25c4f779dd5aaa1

See more details on using hashes here.

Supported by

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