| 243 | super(Sniper, self).__init__(bot, config) |
| 244 | |
| 245 | def initialize(self): |
| 246 | self.disabled = False |
| 247 | self.last_cell_check_time = time.time() |
| 248 | self.last_data_request_time = time.time() |
| 249 | self.inventory = inventory.items() |
| 250 | self.pokedex = inventory.pokedex() |
| 251 | self.debug = self.config.get('debug', False) |
| 252 | self.special_iv = self.config.get('special_iv', 0) |
| 253 | self.bullets = self.config.get('bullets', 1) |
| 254 | self.homing_shots = self.config.get('homing_shots', True) |
| 255 | self.mode = self.config.get('mode', SniperMode.DEFAULT) |
| 256 | self.order = self.config.get('order', SniperOrderMode.DEFAULT) |
| 257 | self.cooldown_enabled = self.config.get('cooldown_enabled', False) |
| 258 | self.loiter_after_snipe = self.config.get('loiter_after_snipe', False) |
| 259 | self.catch_list = self.config.get('catch', {}) |
| 260 | self.altitude = uniform(self.bot.config.alt_min, self.bot.config.alt_max) |
| 261 | self.sources = [SniperSource(data) for data in self.config.get('sources', [])] |
| 262 | self.no_snipe_until = None |
| 263 | |
| 264 | if not hasattr(self.bot,"sniper_cache"): |
| 265 | self.bot.sniper_cache = [] |
| 266 | |
| 267 | # Dont bother validating config if task is not even enabled |
| 268 | if self.enabled: |
| 269 | # Validate ordering |
| 270 | for ordering in self.order: |
| 271 | if ordering not in vars(SniperOrderMode).values(): |
| 272 | raise ValueError("Unrecognized ordering: '{}'".format(ordering)) |
| 273 | |
| 274 | # Validate mode and sources |
| 275 | if self.mode not in vars(SniperMode).values(): |
| 276 | raise ValueError("Unrecognized mode: '{}'".format(self.mode)) |
| 277 | else: |
| 278 | # Selected mode is valid. Validate sources if mode is URL |
| 279 | if self.mode == SniperMode.URL: |
| 280 | self._log("Validating sources: {}...".format(", ".join([source.url for source in self.sources]))) |
| 281 | |
| 282 | # Create a copy of the list so we can iterate and remove elements at the same time |
| 283 | for source in list(self.sources): |
| 284 | try: |
| 285 | source.validate() |
| 286 | self._log("Source '{}' is good!".format(source.url)) |
| 287 | # TODO: On ValueError, remember source and validate later (pending validation) |
| 288 | except (LookupError, ValueError) as exception: |
| 289 | self._error("Source '{}' contains errors. Details: {}. Removing from sources list...".format(source.url, exception)) |
| 290 | self.sources.remove(source) |
| 291 | |
| 292 | # Notify user if all sources are invalid and cant proceed |
| 293 | if not self.sources : |
| 294 | self._error("There is no source available. Disabling Sniper...") |
| 295 | self.disabled = True |
| 296 | |
| 297 | # Re-enable snipping if source is from telegram |
| 298 | if self.mode == SniperMode.TELEGRAM: |
| 299 | self.disabled = False |
| 300 | |
| 301 | def is_snipeable(self, pokemon): |
| 302 | pokeballs_count = self.inventory.get(Item.ITEM_POKE_BALL.value).count |