Repository: PokemonGoF/PokemonGo-Bot

Issue:
check_awarded_badges being called but equip_badge is not
### Short Description

The client application is storing what badges it has shown to the user so that if they log into  new device they are not spammed all of the badges. This is very similar to level up api call.
### Possible solution

Have another task created like  CollectLevelUpReward which will peridoically check what badges are avialable and if they have been collected by the user. if not go and equip the badge.

https://github.com/tejado/pgoapi/wiki/check_awarded_badges
https://github.com/tejado/pgoapi/wiki/equip_badge
### How it would help others

This may reduce the glaring possibility that when an account is used solely by the bot and not logged into the native app once and a while, the number of badges for distance walked and pokemon captured might be flagging the account to be deleted even with slow walking and capturing enabled. This was also very similar to how CollectLevelUpReward which after logged in at level 15 it would collect all 15 levels of loot at once.



Discussion:
This is a feature request but i don't know how to add that label to this.

Also relates to #4114.

I'm not a python programmer (mostly java/php) but i'll give it a crack in the coming days if no one else picks this up.

This looks like what we need to do, this is the java version found in
https://github.com/Grover-c13/PokeGOAPI-Java/blob/Development/library/src/main/java/com/pokegoapi/api/player/PlayerProfile.java#L171

This code has no waits so it will show its a bot as it takes about 2-10seconds between badge collects to display to the user and i would take a guess that it equips badges when it displays the animation.

```
    /**
     * Check and equip badges.
     *
     * @throws LoginFailedException  when the auth is invalid
     * @throws RemoteServerException When a buffer exception is thrown
     */

    public void checkAndEquipBadges() throws LoginFailedException, RemoteServerException {
        CheckAwardedBadgesMessage msg = CheckAwardedBadgesMessage.newBuilder().build();
        ServerRequest serverRequest = new ServerRequest(RequestType.CHECK_AWARDED_BADGES, msg);
        api.getRequestHandler().sendServerRequests(serverRequest);
        CheckAwardedBadgesResponse response;
        try {
            response = CheckAwardedBadgesResponse.parseFrom(serverRequest.getData());
        } catch (InvalidProtocolBufferException e) {
            throw new RemoteServerException(e);
        }
        if (response.getSuccess()) {
            for (int i = 0; i < response.getAwardedBadgesCount(); i++) {
                EquipBadgeMessage msg1 = EquipBadgeMessage.newBuilder()
                        .setBadgeType(response.getAwardedBadges(i))
                        .setBadgeTypeValue(response.getAwardedBadgeLevels(i)).build();
                ServerRequest serverRequest1 = new ServerRequest(RequestType.EQUIP_BADGE, msg1);
                api.getRequestHandler().sendServerRequests(serverRequest1);
                EquipBadgeResponseOuterClass.EquipBadgeResponse response1;
                try {
                    response1 = EquipBadgeResponseOuterClass.EquipBadgeResponse.parseFrom(serverRequest1.getData());
                    badge = response1.getEquipped();
                } catch (InvalidProtocolBufferException e) {
                    throw new RemoteServerException(e);
                }
            }
        }
    }
```

it seem the check awarded badges is called after every pokemon capture, 1-5 seconds after capture (when you cancel out of the success screen maybe) and displays the badge you earned, e.g. you captured 10 water pokemon etc). it might be very easy for them to tell if its a bot if the distance walked badges are not being collected as well as rattata and a couple of others which is in the internal player data. It seems its also called after post login but we don't really want to replicate the behavour of having it collect all medals at once, as this may flag the account has being run incorrectly.


Resolving patch:
diff --git a/pokemongo_bot/__init__.py b/pokemongo_bot/__init__.py
--- a/pokemongo_bot/__init__.py
+++ b/pokemongo_bot/__init__.py
@@ -1215,21 +1215,8 @@ def heartbeat(self):
                         data={'badge': badgename,
                               'level' : badgelevel }
                     )
-
-                    #todo move equip badge into its own task once working
-                    #should work but gives errors :'(s
-                    #response = self.api.equip_badge(badge_type=badge)
-                    response = {'responses': "awaiting further testing on api call to equip_badge"}
-                    self.event_manager.emit(
-                        'badges',
-                        sender=self,
-                        level='info',
-                        formatted='equiped badge: {badge}',
-                        data={'badge': response['responses']}
-                    )
                     human_behaviour.action_delay(3,10)
 
-
         try:
             self.web_update_queue.put_nowait(True)  # do this outside of thread every tick
         except Queue.Full:


Test patch: