Some mxma specific tuning, fixes #71. Added some debugging to slow polling services.
This commit is contained in:
parent
6a9a1f845c
commit
2607afcde2
71
README.md
71
README.md
|
@ -177,7 +177,42 @@ without any authentication or api key.
|
|||
|
||||
See: https://github.com/taspinar/twitterscraper/tree/master/twitterscraper
|
||||
|
||||
#### Url
|
||||
#### Matrix Messaging API (mxma)
|
||||
|
||||
This is a simple API to ask bot to send messages in Matrix using JSON file from external service.
|
||||
|
||||
You'll need an API endpoint (webserver) that contains a message queue. It must respond with following JSON to a HTTP GET request:
|
||||
|
||||
```json
|
||||
{
|
||||
"messages":[
|
||||
{
|
||||
"to": "@example:matrix.org",
|
||||
"title": "Room Title",
|
||||
"message": "Hello from Hemppa"
|
||||
},
|
||||
{
|
||||
"to": "@another:matrix.user",
|
||||
"title": "Room 2 Title",
|
||||
"message": "Second message"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Normally you want to clear the messages when the endpoint is GETted or the messages will repeat
|
||||
every time bot updates itself.
|
||||
|
||||
These messages are sent to given Matrix users in private message with given room title.
|
||||
Messages are sent "best effort" - if sending fails, it will be logged to bot output log.
|
||||
|
||||
Then just:
|
||||
|
||||
* !mxma add http://url.to.the/endpoint.json
|
||||
|
||||
mxma requires all commands to be run as bot owner.
|
||||
|
||||
### Url
|
||||
|
||||
Watches all messages in a room and if a url is found tries to fetch it and
|
||||
spit out the title if found.
|
||||
|
@ -201,7 +236,7 @@ Example:
|
|||
|
||||
* !url status
|
||||
|
||||
#### Cmd
|
||||
### Cmd
|
||||
|
||||
Can be used to pre-configure shell commands run by bot. This is easy way to add
|
||||
security issues to your bot so be careful.
|
||||
|
@ -268,38 +303,6 @@ Commands:
|
|||
* !wa [query] - Query wolfram alpha
|
||||
* !wa appid [appid] - Set appid (must be done as bot owner)
|
||||
|
||||
### Matrix Messaging API
|
||||
|
||||
This is a simple API to ask bot to send messages in Matrix using JSON file from external service.
|
||||
|
||||
You'll need an API endpoint (webserver) that contains a message queue. It must respond with following JSON to a HTTP GET request:
|
||||
|
||||
```json
|
||||
{
|
||||
"messages":[
|
||||
{
|
||||
"to": "@example:matrix.org",
|
||||
"title": "Room Title",
|
||||
"message": "Hello from Hemppa"
|
||||
},
|
||||
{
|
||||
"to": "@another:matrix.user",
|
||||
"title": "Room 2 Title",
|
||||
"message": "Second message"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Normally you want to clear the messages when the endpoint is GETted or the messages will repeat
|
||||
every time bot updates itself.
|
||||
|
||||
These messages are sent to given Matrix users in private message with given room title.
|
||||
Messages are sent "best effort" - if sending fails, it will be logged to bot output log.
|
||||
|
||||
Then just:
|
||||
* !mxma add http://url.to.the/endpoint.json
|
||||
|
||||
## Bot setup
|
||||
|
||||
* Create a Matrix user
|
||||
|
|
|
@ -13,6 +13,8 @@ class PollingService(BotModule):
|
|||
self.service_name = "Service"
|
||||
self.poll_interval_min = 30 # TODO: Configurable
|
||||
self.poll_interval_random = 30
|
||||
self.owner_only = False # Set to true if service can be run only by bot owner
|
||||
self.send_all = False # Set to true to send all received items, even on first sync
|
||||
|
||||
async def matrix_poll(self, bot, pollcount):
|
||||
if len(self.account_rooms):
|
||||
|
@ -27,7 +29,9 @@ class PollingService(BotModule):
|
|||
# First poll
|
||||
if not self.next_poll_time.get(roomid, None):
|
||||
self.next_poll_time[roomid] = now + timedelta(hours=-1)
|
||||
send_messages = False
|
||||
if not self.send_all:
|
||||
send_messages = False
|
||||
self.logger.debug(f'Polling all accounts for room {roomid} - but this is first sync so I wont send messages')
|
||||
if now >= self.next_poll_time.get(roomid):
|
||||
accounts = self.account_rooms[roomid]
|
||||
for account in accounts:
|
||||
|
@ -50,6 +54,9 @@ class PollingService(BotModule):
|
|||
await self.poll_implementation(bot, account, roomid, send_messages)
|
||||
|
||||
async def matrix_message(self, bot, room, event):
|
||||
if self.owner_only:
|
||||
bot.must_be_owner(event)
|
||||
|
||||
args = event.body.split()
|
||||
|
||||
if len(args) == 2:
|
||||
|
|
|
@ -10,6 +10,8 @@ class MatrixModule(PollingService):
|
|||
self.service_name = 'MXMA'
|
||||
self.poll_interval_min = 5
|
||||
self.poll_interval_random = 2
|
||||
self.owner_only = True
|
||||
self.send_all = True
|
||||
|
||||
async def poll_implementation(self, bot, account, roomid, send_messages):
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue