Update docs and remove sync_token.py
This commit is contained in:
parent
1eacb2926e
commit
cbf5545bba
2 changed files with 2 additions and 55 deletions
18
README.md
18
README.md
|
@ -31,9 +31,8 @@ client provides this token the next time it syncs (using the `since` parameter
|
|||
on the `AsyncClient.sync` method), the homeserver will only return new event
|
||||
*since* those specified by the given token.
|
||||
|
||||
This token is saved in the database created by `storage.py` so even if the bot
|
||||
quits unexpectantly, it will continue syncing where it left off next time it
|
||||
is started.
|
||||
This token is saved and provided again automatically by using the
|
||||
`client.sync_forever(...)` method.
|
||||
|
||||
### `config.py`
|
||||
|
||||
|
@ -53,19 +52,6 @@ to put or retrieve data from it. Table definitions should be specified in
|
|||
`_run_migrations`. There's currently no defined method for how migrations
|
||||
should work though.
|
||||
|
||||
The `sync_token` table should be left in tact so that the bot can save its
|
||||
progress when syncing events from the homeserver.
|
||||
|
||||
### `sync_token.py`
|
||||
|
||||
A simple class that can load and save a sync token to/from the database.
|
||||
|
||||
A `SyncToken` is an instance of a sync token, which is simply a string
|
||||
retrieved from a matrix homeserver when querying the `/sync` endpoint (which
|
||||
clients use to retrieve new events). It is given to the next call of the
|
||||
`/sync` endpoint in order to specify the starting point in the event timeline
|
||||
you would like to receive messages from.
|
||||
|
||||
### `callbacks.py`
|
||||
|
||||
Holds callback methods which get run when the bot get a certain type of event
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class SyncToken(object):
|
||||
"""A SyncToken is an instance of a sync token, which is a token retrieved from a matrix
|
||||
homeserver. It is given to the /sync endpoint in order to specify at which point in the
|
||||
event timeline you would like to receive messages after
|
||||
"""
|
||||
|
||||
def __init__(self, store):
|
||||
"""
|
||||
Args:
|
||||
store (Storage): An object to access the storage layer
|
||||
"""
|
||||
self.store = store
|
||||
self.token = None
|
||||
|
||||
# Attempt to load a token from the provided storage layer
|
||||
self._load()
|
||||
|
||||
def _load(self):
|
||||
"""Load the latest sync token from the database"""
|
||||
self.store.cursor.execute("SELECT token FROM sync_token")
|
||||
rows = self.store.cursor.fetchone()
|
||||
|
||||
if rows:
|
||||
self.token = rows[0]
|
||||
|
||||
def update(self, token):
|
||||
"""Update the sync token in the database and the object
|
||||
|
||||
Args:
|
||||
token (str): A sync token from a sync response sent by a matrix homeserver
|
||||
"""
|
||||
self.token = token
|
||||
self.store.cursor.execute("INSERT OR REPLACE INTO sync_token "
|
||||
"(dedupe_id, token) VALUES (1, ?)", (token,))
|
||||
self.store.conn.commit()
|
Loading…
Reference in a new issue