Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Μ
µtrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Teckids
Projekt Hack-n-Fun
Libs
µtrix
Commits
29eb7740
Verified
Commit
29eb7740
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Implement mynit support
parent
c758b8a8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mytrix.py
+36
-5
36 additions, 5 deletions
mytrix.py
with
36 additions
and
5 deletions
mytrix.py
+
36
−
5
View file @
29eb7740
# Copyright 2020, 2021 Dominik George <dominik.george@teckids.org>
# Copyright 2020, 2021
, 2022
Dominik George <dominik.george@teckids.org>
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# you may not use this file except in compliance with the License.
...
@@ -16,13 +16,22 @@ import ntptime
...
@@ -16,13 +16,22 @@ import ntptime
import
re
import
re
import
urequests
import
urequests
if
"
mynit
"
in
locals
:
_MYTRIX_MYNIT_SCHEMA
=
{
"
homeserver
"
:
(
"
URL of Matrix homeserver
"
,
"
str
"
,
None
,
""
,
"
_mytrix_mynit_update
"
),
"
matrix_id
"
:
(
"
Matrix ID
"
,
"
str
"
,
None
,
""
,
"
_mytrix_mynit_update
"
),
"
access_token
"
:
(
"
Access token
"
,
"
str
"
,
None
,
""
,
"
_mytrix_mynit_update
"
),
}
mynit
.
register
(
"
matrix
"
,
"
Matrix
"
,
_MYTRIX_MYNIT_SCHEMA
)
del
_MYTRIX_MYNIT_SCHEMA
class
Matrix
:
class
Matrix
:
"""
Implements Matrix client functionality and state keeping
"""
"""
Implements Matrix client functionality and state keeping
"""
sync_limit
=
1
sync_limit
=
1
def
__init__
(
self
,
homeserver
,
matrix_id
,
access_token
,
txn_id
=
None
):
def
__init__
(
self
,
homeserver
=
None
,
matrix_id
=
None
,
access_token
=
None
,
txn_id
=
None
):
"""
Configure the Matrix client.
"""
Configure the Matrix client.
The arguments homeserver, matrix_id and access_token configure access to the Matrix network.
The arguments homeserver, matrix_id and access_token configure access to the Matrix network.
...
@@ -32,9 +41,18 @@ class Matrix:
...
@@ -32,9 +41,18 @@ class Matrix:
if defaults to the current UNIX timestamp, retrieved by an NTP request. For details on transaction
if defaults to the current UNIX timestamp, retrieved by an NTP request. For details on transaction
IDs, see the Matrix documentation.
IDs, see the Matrix documentation.
"""
"""
self
.
homeserver
=
homeserver
self
.
matrix_id
=
matrix_id
if
"
mynit
"
in
locals
:
self
.
access_token
=
access_token
if
(
homeserver
,
matrix_id
,
access_token
)
!=
(
None
,
None
,
None
):
raise
TypeError
(
"
No arguments must be passed if mynit is used
"
)
self
.
_mynit_update
()
else
:
self
.
homeserver
=
homeserver
self
.
matrix_id
=
matrix_id
self
.
access_token
=
access_token
if
not
self
.
homeserver
or
not
self
.
matrix_id
or
not
self
.
access_token
:
raise
TypeError
(
"
homeserver, matrix_id and access_token must be set
"
)
if
txn_id
is
None
:
if
txn_id
is
None
:
self
.
_txn_id
=
ntptime
.
time
()
self
.
_txn_id
=
ntptime
.
time
()
...
@@ -43,6 +61,11 @@ class Matrix:
...
@@ -43,6 +61,11 @@ class Matrix:
self
.
_from_cache
=
{}
self
.
_from_cache
=
{}
def
_mynit_update
(
self
):
self
.
homeserver
=
mynit
[
"
matrix
"
][
"
homeserver
"
]
self
.
matrix_id
=
mynit
[
"
matrix
"
][
"
matrix_id
"
]
self
.
access_token
=
mynit
[
"
matrix
"
][
"
access_token
"
]
def
_request
(
self
,
method
,
endpoint
,
query_data
=
None
,
json_data
=
None
):
def
_request
(
self
,
method
,
endpoint
,
query_data
=
None
,
json_data
=
None
):
"""
Send an HTTP request using urequests.
"""
"""
Send an HTTP request using urequests.
"""
url
=
"
%s/_matrix/client%s
"
%
(
self
.
homeserver
,
endpoint
)
url
=
"
%s/_matrix/client%s
"
%
(
self
.
homeserver
,
endpoint
)
...
@@ -230,3 +253,11 @@ class Matrix:
...
@@ -230,3 +253,11 @@ class Matrix:
return
dm_rooms
[
mxid
][
0
]
return
dm_rooms
[
mxid
][
0
]
return
self
.
_create_dm_room
(
mxid
,
dm_rooms
)
return
self
.
_create_dm_room
(
mxid
,
dm_rooms
)
_mytrix_instances
=
[]
def
_mytrix_mynit_update
():
for
i
in
_mytrix_instances
:
i
.
_mynit_update
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment