示例#1
0
    def request_snipe(self, update, pkm, lat, lng):
        snipeSuccess = False
        try:
            id = Pokemons.id_for(pkm)
        except:
            self.sendMessage(chat_id=update.message.chat_id, parse_mode='Markdown', text="Invaild Pokemon")
            return

        #Set Telegram Snipe to true and let sniper do its work
        TelegramSnipe.ENABLED = True
        TelegramSnipe.ID = int(id)
        TelegramSnipe.POKEMON_NAME = str(pkm)
        TelegramSnipe.LATITUDE = float(lat)
        TelegramSnipe.LONGITUDE = float(lng)
        
        outMsg = 'Catching pokemon: ' + TelegramSnipe.POKEMON_NAME + ' at Latitude: ' + str(TelegramSnipe.LATITUDE) + ' Longitude: ' + str(TelegramSnipe.LONGITUDE) + '\n'
        self.sendMessage(chat_id=update.message.chat_id, parse_mode='Markdown', text="".join(outMsg))
示例#2
0
    def _is_vip_pokemon(self, pokemon):
        if 'pokemon_id' not in pokemon:
            if not 'name' in pokemon:
                return False
            pokemon['pokemon_id'] = Pokemons.id_for(pokemon['name'])
        # having just a name present in the list makes them vip
        # Not seen pokemons also will become vip if it's not disabled in config
        if self.bot.config.vips.get(Pokemons.name_for(pokemon['pokemon_id'])) == {}:
            return True
        if (not inventory.pokedex().seen(pokemon['pokemon_id'])):
            return True
        # If we must treat family of VIP as VIP
        if self.config.get('treat_family_of_vip_as_vip', False):
            if self._is_family_of_vip(pokemon['pokemon_id']):
                return True
        # If we need the Pokemon for an evolution, catch it.
        if any(not inventory.pokedex().seen(fid) for fid in self.get_family_ids(pokemon['pokemon_id'])):
            # self.logger.info('Found a Pokemon whoes family is not yet complete in Pokedex!')
            return True

        return False
示例#3
0
    def _is_vip_pokemon(self, pokemon):
        if 'pokemon_id' not in pokemon:
            if not 'name' in pokemon:
                return False
            pokemon['pokemon_id'] = Pokemons.id_for(pokemon['name'])
        # having just a name present in the list makes them vip
        # Not seen pokemons also will become vip if it's not disabled in config
        if self.bot.config.vips.get(Pokemons.name_for(pokemon['pokemon_id'])) == {}:
            return True
        if (not inventory.pokedex().seen(pokemon['pokemon_id'])):
            return True
        # If we must treat family of VIP as VIP
        if self.config.get('treat_family_of_vip_as_vip', False):
            if self._is_family_of_vip(pokemon['pokemon_id']):
                return True
        # If we need the Pokemon for an evolution, catch it.
        if any(not inventory.pokedex().seen(fid) for fid in self.get_family_ids(pokemon['pokemon_id'])):
            # self.logger.info('Found a Pokemon whoes family is not yet complete in Pokedex!')
            return True

        return False
示例#4
0
    def request_snipe(self, update, pkm, lat, lng):
        snipeSuccess = False
        try:
            id = Pokemons.id_for(pkm)
        except:
            self.sendMessage(chat_id=update.message.chat_id,
                             parse_mode='Markdown',
                             text="Invaild Pokemon")
            return

        #Set Telegram Snipe to true and let sniper do its work
        TelegramSnipe.ENABLED = True
        TelegramSnipe.ID = int(id)
        TelegramSnipe.POKEMON_NAME = str(pkm)
        TelegramSnipe.LATITUDE = float(lat)
        TelegramSnipe.LONGITUDE = float(lng)

        outMsg = 'Catching pokemon: ' + TelegramSnipe.POKEMON_NAME + ' at Latitude: ' + str(
            TelegramSnipe.LATITUDE) + ' Longitude: ' + str(
                TelegramSnipe.LONGITUDE) + '\n'
        self.sendMessage(chat_id=update.message.chat_id,
                         parse_mode='Markdown',
                         text="".join(outMsg))
示例#5
0
    def fetch(self):
        pokemons = []

        try:
            results = self.fetch_raw()

            # Parse results
            for result in results:
                iv = result.get(self.mappings.iv.param)
                id = result.get(self.mappings.id.param)
                name = self._get_closest_name(self._fixname(result.get(self.mappings.name.param)))
                latitude = result.get(self.mappings.latitude.param)
                longitude = result.get(self.mappings.longitude.param)
                expiration = result.get(self.mappings.expiration.param)
                encounter = result.get(self.mappings.encounter.param)
                spawnpoint = result.get(self.mappings.spawnpoint.param)

                # If this is a composite param, split it ("coords": "-31.415553, -64.190480")
                if self.mappings.latitude.param == self.mappings.longitude.param:
                    position = result.get(self.mappings.latitude.param).replace(" ", "").split(",")
                    latitude = position[0]
                    longitude = position[1]

                # Some sources block access to all pokemon, need to skip those!
                try:
                    float(latitude)
                    float(longitude)
                except ValueError:
                    # Seems to be blacked out, do next.
                    continue

                # Format the time accordingly. Pokemon times are in milliseconds!
                if self.mappings.expiration.exists and expiration:
                    if self.mappings.expiration.format == SniperSourceMappingTimeFormat.SECONDS:
                        expiration = expiration * 1000
                    elif self.mappings.expiration.format == SniperSourceMappingTimeFormat.UTC:
                        utc_date = datetime.strptime(expiration.replace("T", " ")[:19], self.time_mask)
                        unix_timestamp = calendar.timegm(utc_date.timetuple())
                        local_date = datetime.fromtimestamp(unix_timestamp)
                        local_date = local_date.replace(microsecond=utc_date.microsecond)
                        expiration = time.mktime(local_date.timetuple()) * 1000
                else:
                    minutes_to_expire = 3
                    seconds_per_minute = 60
                    expiration = (time.time() + minutes_to_expire * seconds_per_minute) * 1000

                # If either name or ID are invalid, fix it using each other
                if not name or not id:
                    if not name and id:
                        name = Pokemons.name_for(id)
                    if not id and name:
                        id = Pokemons.id_for(name)

                # Some type castings were specified for a better readability
                pokemons.append({
                    'iv': float(iv or 0),
                    'pokemon_id': int(id or 0),
                    'pokemon_name': str(name or ''),
                    'latitude': float(latitude or .0),
                    'longitude': float(longitude or .0),
                    'expiration_timestamp_ms': long(expiration or 0),
                    'last_modified_timestamp_ms': long(expiration or 0),
                    'encounter_id': long(encounter or 0),
                    'spawn_point_id': str(spawnpoint or '')
                })
        except requests.exceptions.Timeout:
            raise Exception("Fetching has timed out")
        except requests.exceptions.ConnectionError:
            raise Exception("Source not available")
        except:
            raise

        return pokemons