Merge pull request #110 from berlincount/poll_only_enabled
Only talk to external services when enabled explicitly
This commit is contained in:
commit
0dafd62a61
1
Pipfile
1
Pipfile
|
@ -13,7 +13,6 @@ google-auth-httplib2 = "*"
|
|||
google-auth-oauthlib = "*"
|
||||
requests = "*"
|
||||
igramscraper = "*"
|
||||
twitterscraper = "*"
|
||||
httpx = "*"
|
||||
PyYAML = "==5.3"
|
||||
wolframalpha = "*"
|
||||
|
|
15
README.md
15
README.md
|
@ -123,6 +123,8 @@ Commands:
|
|||
* !googlecal del [calendar id] - Delete calendar from room (Must be done as room admin)
|
||||
* !googlecal list - List calendars in this room
|
||||
|
||||
NOTE: disabled by default
|
||||
|
||||
### Cron
|
||||
|
||||
Can schedule things to be done.
|
||||
|
@ -187,7 +189,7 @@ New posts are sent to room. Polls only randomly every 30 to 60 minutes to keep
|
|||
|
||||
Commands:
|
||||
|
||||
Prefix with selected service, for example "!ig add accountname" or "!twitter list"
|
||||
Prefix with selected service, for example "!ig add accountname" or "!teamup list"
|
||||
|
||||
* add [accountname] - Add account to this room (Must be done as room admin)
|
||||
* del [accountname] - Delete account from room (Must be done as room admin)
|
||||
|
@ -203,12 +205,7 @@ without any authentication or api key.
|
|||
|
||||
See: https://github.com/realsirjoe/instagram-scraper/
|
||||
|
||||
#### Twitter
|
||||
|
||||
Polls twitter account(s). Uses twitter scraper library
|
||||
without any authentication or api key.
|
||||
|
||||
See: https://github.com/taspinar/twitterscraper/tree/master/twitterscraper
|
||||
NOTE: disabled by default
|
||||
|
||||
#### Matrix Messaging API (mxma)
|
||||
|
||||
|
@ -269,6 +266,8 @@ Example:
|
|||
|
||||
* !url status
|
||||
|
||||
NOTE: Disabled by default, i.e. you also need to enable it before activating it
|
||||
|
||||
### Cmd
|
||||
|
||||
Can be used to pre-configure shell commands run by bot. This is easy way to add
|
||||
|
@ -373,6 +372,8 @@ bot ownership)
|
|||
* !flog rmlive - disable live field log for this room
|
||||
* !flog timezone 3 - set timezone (relative to UTC, see API docs)
|
||||
|
||||
NOTE: disabled by default
|
||||
|
||||
### Jitsi
|
||||
|
||||
If enabled, Jitsi calls created with Matrix clients will be sent as text messages
|
||||
|
|
|
@ -17,7 +17,7 @@ class PollingService(BotModule):
|
|||
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):
|
||||
if self.enabled and len(self.account_rooms):
|
||||
await self.poll_all_accounts(bot)
|
||||
|
||||
async def poll_all_accounts(self, bot):
|
||||
|
|
|
@ -21,6 +21,7 @@ class MatrixModule(BotModule):
|
|||
self.logged_flights = []
|
||||
self.logged_flights_date = ""
|
||||
self.first_poll = True
|
||||
self.enabled = False
|
||||
|
||||
async def matrix_poll(self, bot, pollcount):
|
||||
if len(self.api_key) > 0:
|
||||
|
|
|
@ -27,6 +27,7 @@ class MatrixModule(BotModule):
|
|||
self.bot = None
|
||||
self.service = None
|
||||
self.calendar_rooms = dict() # Contains room_id -> [calid, calid] ..
|
||||
self.enabled = False
|
||||
|
||||
def matrix_start(self, bot):
|
||||
super().matrix_start(bot)
|
||||
|
|
|
@ -15,6 +15,7 @@ class MatrixModule(PollingService):
|
|||
super().__init__(name)
|
||||
self.instagram = Instagram()
|
||||
self.service_name = 'Instagram'
|
||||
self.enabled = False
|
||||
|
||||
async def poll_implementation(self, bot, account, roomid, send_messages):
|
||||
try:
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
import sys
|
||||
import traceback
|
||||
|
||||
from twitterscraper import query_tweets_from_user
|
||||
|
||||
from modules.common.pollingservice import PollingService
|
||||
|
||||
|
||||
# https://github.com/taspinar/twitterscraper/tree/master/twitterscraper
|
||||
|
||||
class MatrixModule(PollingService):
|
||||
def __init__(self, name):
|
||||
super().__init__(name)
|
||||
self.service_name = 'Twitter'
|
||||
|
||||
async def poll_implementation(self, bot, account, roomid, send_messages):
|
||||
try:
|
||||
tweets = query_tweets_from_user(account, limit=1)
|
||||
self.logger.info(f'Polling twitter account {account} - got {len(tweets)} tweets')
|
||||
for tweet in tweets:
|
||||
if tweet.tweet_id not in self.known_ids:
|
||||
if send_messages:
|
||||
await bot.send_html(bot.get_room_by_id(roomid),
|
||||
f'<a href="https://twitter.com{tweet.tweet_url}">Twitter {account}</a>: {tweet.text}',
|
||||
f'Twitter {account}: {tweet.text} - https://twitter.com{tweet.tweet_url}')
|
||||
self.known_ids.add(tweet.tweet_id)
|
||||
except Exception:
|
||||
self.logger.error('Polling twitter account failed:')
|
||||
traceback.print_exc(file=sys.stderr)
|
|
@ -34,6 +34,8 @@ class MatrixModule(BotModule):
|
|||
"BOTH": "Spamming this channel with both title and description",
|
||||
}
|
||||
|
||||
self.enabled = False
|
||||
|
||||
def matrix_start(self, bot):
|
||||
"""
|
||||
Register callback for all RoomMessageText events on startup
|
||||
|
|
Loading…
Reference in New Issue