Merge pull request #110 from berlincount/poll_only_enabled

Only talk to external services when enabled explicitly
This commit is contained in:
Ville Ranki 2020-11-15 22:26:50 +02:00 committed by GitHub
commit 0dafd62a61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 14 additions and 38 deletions

View File

@ -13,7 +13,6 @@ google-auth-httplib2 = "*"
google-auth-oauthlib = "*" google-auth-oauthlib = "*"
requests = "*" requests = "*"
igramscraper = "*" igramscraper = "*"
twitterscraper = "*"
httpx = "*" httpx = "*"
PyYAML = "==5.3" PyYAML = "==5.3"
wolframalpha = "*" wolframalpha = "*"

View File

@ -123,6 +123,8 @@ Commands:
* !googlecal del [calendar id] - Delete calendar from room (Must be done as room admin) * !googlecal del [calendar id] - Delete calendar from room (Must be done as room admin)
* !googlecal list - List calendars in this room * !googlecal list - List calendars in this room
NOTE: disabled by default
### Cron ### Cron
Can schedule things to be done. 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: 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) * 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) * 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/ See: https://github.com/realsirjoe/instagram-scraper/
#### Twitter NOTE: disabled by default
Polls twitter account(s). Uses twitter scraper library
without any authentication or api key.
See: https://github.com/taspinar/twitterscraper/tree/master/twitterscraper
#### Matrix Messaging API (mxma) #### Matrix Messaging API (mxma)
@ -269,6 +266,8 @@ Example:
* !url status * !url status
NOTE: Disabled by default, i.e. you also need to enable it before activating it
### 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
@ -373,6 +372,8 @@ bot ownership)
* !flog rmlive - disable live field log for this room * !flog rmlive - disable live field log for this room
* !flog timezone 3 - set timezone (relative to UTC, see API docs) * !flog timezone 3 - set timezone (relative to UTC, see API docs)
NOTE: disabled by default
### Jitsi ### Jitsi
If enabled, Jitsi calls created with Matrix clients will be sent as text messages If enabled, Jitsi calls created with Matrix clients will be sent as text messages

View File

@ -17,7 +17,7 @@ class PollingService(BotModule):
self.send_all = False # Set to true to send all received items, even on first sync 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 self.enabled and len(self.account_rooms):
await self.poll_all_accounts(bot) await self.poll_all_accounts(bot)
async def poll_all_accounts(self, bot): async def poll_all_accounts(self, bot):

View File

@ -21,6 +21,7 @@ class MatrixModule(BotModule):
self.logged_flights = [] self.logged_flights = []
self.logged_flights_date = "" self.logged_flights_date = ""
self.first_poll = True self.first_poll = True
self.enabled = False
async def matrix_poll(self, bot, pollcount): async def matrix_poll(self, bot, pollcount):
if len(self.api_key) > 0: if len(self.api_key) > 0:

View File

@ -27,6 +27,7 @@ class MatrixModule(BotModule):
self.bot = None self.bot = None
self.service = None self.service = None
self.calendar_rooms = dict() # Contains room_id -> [calid, calid] .. self.calendar_rooms = dict() # Contains room_id -> [calid, calid] ..
self.enabled = False
def matrix_start(self, bot): def matrix_start(self, bot):
super().matrix_start(bot) super().matrix_start(bot)

View File

@ -15,6 +15,7 @@ class MatrixModule(PollingService):
super().__init__(name) super().__init__(name)
self.instagram = Instagram() self.instagram = Instagram()
self.service_name = 'Instagram' self.service_name = 'Instagram'
self.enabled = False
async def poll_implementation(self, bot, account, roomid, send_messages): async def poll_implementation(self, bot, account, roomid, send_messages):
try: try:

View File

@ -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)

View File

@ -34,6 +34,8 @@ class MatrixModule(BotModule):
"BOTH": "Spamming this channel with both title and description", "BOTH": "Spamming this channel with both title and description",
} }
self.enabled = False
def matrix_start(self, bot): def matrix_start(self, bot):
""" """
Register callback for all RoomMessageText events on startup Register callback for all RoomMessageText events on startup