Some mxma specific tuning, fixes #71. Added some debugging to slow polling services.

This commit is contained in:
Ville Ranki 2020-03-30 22:04:41 +03:00
parent 6a9a1f845c
commit 2607afcde2
3 changed files with 47 additions and 35 deletions

View File

@ -177,7 +177,42 @@ without any authentication or api key.
See: https://github.com/taspinar/twitterscraper/tree/master/twitterscraper 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 Watches all messages in a room and if a url is found tries to fetch it and
spit out the title if found. spit out the title if found.
@ -201,7 +236,7 @@ Example:
* !url status * !url status
#### Cmd ### Cmd
Can be used to pre-configure shell commands run by bot. This is easy way to add 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. security issues to your bot so be careful.
@ -268,38 +303,6 @@ Commands:
* !wa [query] - Query wolfram alpha * !wa [query] - Query wolfram alpha
* !wa appid [appid] - Set appid (must be done as bot owner) * !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 ## Bot setup
* Create a Matrix user * Create a Matrix user

View File

@ -13,6 +13,8 @@ class PollingService(BotModule):
self.service_name = "Service" self.service_name = "Service"
self.poll_interval_min = 30 # TODO: Configurable self.poll_interval_min = 30 # TODO: Configurable
self.poll_interval_random = 30 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): async def matrix_poll(self, bot, pollcount):
if len(self.account_rooms): if len(self.account_rooms):
@ -27,7 +29,9 @@ class PollingService(BotModule):
# First poll # First poll
if not self.next_poll_time.get(roomid, None): if not self.next_poll_time.get(roomid, None):
self.next_poll_time[roomid] = now + timedelta(hours=-1) self.next_poll_time[roomid] = now + timedelta(hours=-1)
if not self.send_all:
send_messages = False 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): if now >= self.next_poll_time.get(roomid):
accounts = self.account_rooms[roomid] accounts = self.account_rooms[roomid]
for account in accounts: for account in accounts:
@ -50,6 +54,9 @@ class PollingService(BotModule):
await self.poll_implementation(bot, account, roomid, send_messages) await self.poll_implementation(bot, account, roomid, send_messages)
async def matrix_message(self, bot, room, event): async def matrix_message(self, bot, room, event):
if self.owner_only:
bot.must_be_owner(event)
args = event.body.split() args = event.body.split()
if len(args) == 2: if len(args) == 2:

View File

@ -10,6 +10,8 @@ class MatrixModule(PollingService):
self.service_name = 'MXMA' self.service_name = 'MXMA'
self.poll_interval_min = 5 self.poll_interval_min = 5
self.poll_interval_random = 2 self.poll_interval_random = 2
self.owner_only = True
self.send_all = True
async def poll_implementation(self, bot, account, roomid, send_messages): async def poll_implementation(self, bot, account, roomid, send_messages):
try: try: