@@ -182,13 +182,21 @@ def _run_job_error(self, job_id, exc, traceback=None):
182
182
183
183
184
184
class Collector (object ):
185
- __slots__ = 'backend_url' , 'bot_token' , 'scheduler' , 'known_jobs' , 'jobs_refresh_interval'
185
+ __slots__ = 'backend_url' , 'bot_token' , 'scheduler' , 'known_jobs' , 'jobs_refresh_interval' , 'user_id'
186
186
187
187
def __init__ (self , backend_url , bot_token , jobs_refresh_interval ):
188
188
self .backend_url = backend_url
189
189
self .bot_token = bot_token
190
190
self .jobs_refresh_interval = jobs_refresh_interval
191
191
self .known_jobs = {}
192
+ self ._fetch_user_id ()
193
+
194
+ def _fetch_user_id (self ):
195
+ r = requests .get ('{}/profile/?b={}' .format (self .backend_url , self .bot_token ))
196
+ if r .status_code != 200 :
197
+ raise Exception ("Invalid bot token or network error, got status {} while retrieving {}/profile" .format (r .status_code , self .backend_url ))
198
+ j = r .json ()
199
+ self .user_id = j ["user_id" ]
192
200
193
201
@abstractmethod
194
202
def jobs (self ):
@@ -204,8 +212,8 @@ def fetch_job_configs(self, protocol):
204
212
The data is cleaned up as much as possible, so that it only contains the things necessary for collectors
205
213
to do their job.
206
214
"""
207
- # find all the accounts we have access to:
208
215
requests_session = requests .Session ()
216
+ # find all the accounts we have access to:
209
217
r = requests_session .get ('{}/accounts/?b={}' .format (self .backend_url , self .bot_token ))
210
218
if r .status_code != 200 :
211
219
raise Exception ("Invalid bot token or network error, got status {} while retrieving {}/accounts" .format (r .status_code , self .backend_url ))
@@ -229,6 +237,9 @@ def fetch_job_configs(self, protocol):
229
237
# make sure that the protocol is enabled on the entity:
230
238
if protocol not in entity_info ["protocols" ]:
231
239
continue
240
+ # and that the bot id is our own, or not set: (indicating that it predates the time when this option became available - which should not matter after ~2020-01-01)
241
+ if entity_info ["protocols" ][protocol ].get ("bot" , None ) is not None and entity_info ["protocols" ][protocol ]["bot" ] != self .user_id :
242
+ continue
232
243
# and that credential is set:
233
244
if not entity_info ["protocols" ][protocol ]["credential" ]:
234
245
continue
0 commit comments