prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Crash on Level Up
  I'm gonna guess an issue with:
  https://github.com/PokemonGoF/PokemonGo-Bot/pull/5016
  
  which is also the version im on
  
  ```
  Traceback (most recent call last):
    File "pokecli.py", line 781, in <module>
      main()
    File "pokecli.py", line 139, in main
      bot.tick()
    File "C:\Users\Steve\Downloads\PokemonGo-Bot\pokemongo_bot\__init__.py", line 658, in tick
      if worker.work() == WorkerResult.RUNNING:
    File "C:\Users\Steve\Downloads\PokemonGo-Bot\pokemongo_bot\cell_workers\collect_level_up_reward.py", line 37, in work
      self._collect_level_reward()
    File "C:\Users\Steve\Downloads\PokemonGo-Bot\pokemongo_bot\cell_workers\collect_level_up_reward.py", line 70, in _collect_level_reward
      'items': ', '.join(["{}x {}".format(data[x], x) for x in data])
  TypeError: list indices must be integers, not dict
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pokemongo_bot/cell_workers/collect_level_up_reward.py`
  Content:
  ```
  1 import sys
  2 
  3 from pokemongo_bot.base_task import BaseTask
  4 from pokemongo_bot import inventory
  5 
  6 
  7 class CollectLevelUpReward(BaseTask):
  8     SUPPORTED_TASK_API_VERSION = 1
  9 
  10     current_level = 0
  11     previous_level = 0
  12 
  13     def initialize(self):
  14         self._process_config()
  15         self.current_level = inventory.player().level
  16         self.previous_level = 0
  17 
  18     def work(self):
  19         if self._should_run():
  20             self.current_level = inventory.player().level
  21 
  22             if self.collect_reward:
  23                 # let's check level reward on bot initialization
  24                 # to be able get rewards for old bots
  25                 if self.previous_level == 0:
  26                     self._collect_level_reward()
  27                 # level up situation
  28                 elif self.current_level > self.previous_level:
  29                     self.emit_event(
  30                         'level_up',
  31                         formatted='Level up from {previous_level} to {current_level}',
  32                         data={
  33                             'previous_level': self.previous_level,
  34                             'current_level': self.current_level
  35                         }
  36                     )
  37                     self._collect_level_reward()
  38 
  39             if self.level_limit != -1 and self.current_level >= self.level_limit:
  40                 sys.exit("You have reached your target level! Exiting now.")
  41 
  42             self.previous_level = self.current_level
  43 
  44     def _process_config(self):
  45         self.level_limit = self.config.get('level_limit', -1)
  46         self.collect_reward = self.config.get('collect_reward', True)
  47 
  48     def _should_run(self):
  49         return self.level_limit != -1 or self.collect_reward
  50 
  51     def _collect_level_reward(self):
  52         response_dict = self.bot.api.level_up_rewards(level=self.current_level)
  53         if 'status_code' in response_dict and response_dict['status_code'] == 1:
  54             data = (response_dict
  55                     .get('responses', {})
  56                     .get('LEVEL_UP_REWARDS', {})
  57                     .get('items_awarded', []))
  58 
  59             for item in data:
  60                 if 'item_id' in item and str(item['item_id']) in self.bot.item_list:
  61                     got_item = self.bot.item_list[str(item['item_id'])]
  62                     item['name'] = got_item
  63                     count = 'item_count' in item and item['item_count'] or 0
  64                     inventory.items().get(item['item_id']).add(count)
  65             try:
  66                 self.emit_event(
  67                     'level_up_reward',
  68                     formatted='Received level up reward: {items}',
  69                     data={
  70                         'items': ', '.join(["{}x {}".format(data[x], x) for x in data])
  71                     }
  72                 )
  73             except TypeError:
  74                 pass
  75
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/pokemongo_bot/cell_workers/collect_level_up_reward.py b/pokemongo_bot/cell_workers/collect_level_up_reward.py
  --- a/pokemongo_bot/cell_workers/collect_level_up_reward.py
  +++ b/pokemongo_bot/cell_workers/collect_level_up_reward.py
  @@ -62,13 +62,11 @@
                       item['name'] = got_item
                       count = 'item_count' in item and item['item_count'] or 0
                       inventory.items().get(item['item_id']).add(count)
  -            try:
  -                self.emit_event(
  -                    'level_up_reward',
  -                    formatted='Received level up reward: {items}',
  -                    data={
  -                        'items': ', '.join(["{}x {}".format(data[x], x) for x in data])
  -                    }
  -                )
  -            except TypeError:
  -                pass
  +            self.emit_event(
  +                'level_up_reward',
  +                formatted='Received level up reward: {items}',
  +                data={
  +                    # [{'item_id': 3, 'name': u'Ultraball', 'item_count': 10}, {'item_id': 103, 'name': u'Hyper Potion', 'item_count': 10}]
  +                    'items': ', '.join(["{}x {}".format(x['item_count'], x['name']) for x in data])
  +                }
  +            )
  
verification_info: {"golden_diff": "diff --git a/pokemongo_bot/cell_workers/collect_level_up_reward.py b/pokemongo_bot/cell_workers/collect_level_up_reward.py\n--- a/pokemongo_bot/cell_workers/collect_level_up_reward.py\n+++ b/pokemongo_bot/cell_workers/collect_level_up_reward.py\n@@ -62,13 +62,11 @@\n                     item['name'] = got_item\n                     count = 'item_count' in item and item['item_count'] or 0\n                     inventory.items().get(item['item_id']).add(count)\n-            try:\n-                self.emit_event(\n-                    'level_up_reward',\n-                    formatted='Received level up reward: {items}',\n-                    data={\n-                        'items': ', '.join([\"{}x {}\".format(data[x], x) for x in data])\n-                    }\n-                )\n-            except TypeError:\n-                pass\n+            self.emit_event(\n+                'level_up_reward',\n+                formatted='Received level up reward: {items}',\n+                data={\n+                    # [{'item_id': 3, 'name': u'Ultraball', 'item_count': 10}, {'item_id': 103, 'name': u'Hyper Potion', 'item_count': 10}]\n+                    'items': ', '.join([\"{}x {}\".format(x['item_count'], x['name']) for x in data])\n+                }\n+            )\n", "issue": "Crash on Level Up\nI'm gonna guess an issue with:\nhttps://github.com/PokemonGoF/PokemonGo-Bot/pull/5016\n\nwhich is also the version im on\n\n```\nTraceback (most recent call last):\n  File \"pokecli.py\", line 781, in <module>\n    main()\n  File \"pokecli.py\", line 139, in main\n    bot.tick()\n  File \"C:\\Users\\Steve\\Downloads\\PokemonGo-Bot\\pokemongo_bot\\__init__.py\", line 658, in tick\n    if worker.work() == WorkerResult.RUNNING:\n  File \"C:\\Users\\Steve\\Downloads\\PokemonGo-Bot\\pokemongo_bot\\cell_workers\\collect_level_up_reward.py\", line 37, in work\n    self._collect_level_reward()\n  File \"C:\\Users\\Steve\\Downloads\\PokemonGo-Bot\\pokemongo_bot\\cell_workers\\collect_level_up_reward.py\", line 70, in _collect_level_reward\n    'items': ', '.join([\"{}x {}\".format(data[x], x) for x in data])\nTypeError: list indices must be integers, not dict\n```\n\n", "before_files": [{"content": "import sys\n\nfrom pokemongo_bot.base_task import BaseTask\nfrom pokemongo_bot import inventory\n\n\nclass CollectLevelUpReward(BaseTask):\n    SUPPORTED_TASK_API_VERSION = 1\n\n    current_level = 0\n    previous_level = 0\n\n    def initialize(self):\n        self._process_config()\n        self.current_level = inventory.player().level\n        self.previous_level = 0\n\n    def work(self):\n        if self._should_run():\n            self.current_level = inventory.player().level\n\n            if self.collect_reward:\n                # let's check level reward on bot initialization\n                # to be able get rewards for old bots\n                if self.previous_level == 0:\n                    self._collect_level_reward()\n                # level up situation\n                elif self.current_level > self.previous_level:\n                    self.emit_event(\n                        'level_up',\n                        formatted='Level up from {previous_level} to {current_level}',\n                        data={\n                            'previous_level': self.previous_level,\n                            'current_level': self.current_level\n                        }\n                    )\n                    self._collect_level_reward()\n\n            if self.level_limit != -1 and self.current_level >= self.level_limit:\n                sys.exit(\"You have reached your target level! Exiting now.\")\n\n            self.previous_level = self.current_level\n\n    def _process_config(self):\n        self.level_limit = self.config.get('level_limit', -1)\n        self.collect_reward = self.config.get('collect_reward', True)\n\n    def _should_run(self):\n        return self.level_limit != -1 or self.collect_reward\n\n    def _collect_level_reward(self):\n        response_dict = self.bot.api.level_up_rewards(level=self.current_level)\n        if 'status_code' in response_dict and response_dict['status_code'] == 1:\n            data = (response_dict\n                    .get('responses', {})\n                    .get('LEVEL_UP_REWARDS', {})\n                    .get('items_awarded', []))\n\n            for item in data:\n                if 'item_id' in item and str(item['item_id']) in self.bot.item_list:\n                    got_item = self.bot.item_list[str(item['item_id'])]\n                    item['name'] = got_item\n                    count = 'item_count' in item and item['item_count'] or 0\n                    inventory.items().get(item['item_id']).add(count)\n            try:\n                self.emit_event(\n                    'level_up_reward',\n                    formatted='Received level up reward: {items}',\n                    data={\n                        'items': ', '.join([\"{}x {}\".format(data[x], x) for x in data])\n                    }\n                )\n            except TypeError:\n                pass\n", "path": "pokemongo_bot/cell_workers/collect_level_up_reward.py"}], "after_files": [{"content": "import sys\n\nfrom pokemongo_bot.base_task import BaseTask\nfrom pokemongo_bot import inventory\n\n\nclass CollectLevelUpReward(BaseTask):\n    SUPPORTED_TASK_API_VERSION = 1\n\n    current_level = 0\n    previous_level = 0\n\n    def initialize(self):\n        self._process_config()\n        self.current_level = inventory.player().level\n        self.previous_level = 0\n\n    def work(self):\n        if self._should_run():\n            self.current_level = inventory.player().level\n\n            if self.collect_reward:\n                # let's check level reward on bot initialization\n                # to be able get rewards for old bots\n                if self.previous_level == 0:\n                    self._collect_level_reward()\n                # level up situation\n                elif self.current_level > self.previous_level:\n                    self.emit_event(\n                        'level_up',\n                        formatted='Level up from {previous_level} to {current_level}',\n                        data={\n                            'previous_level': self.previous_level,\n                            'current_level': self.current_level\n                        }\n                    )\n                    self._collect_level_reward()\n\n            if self.level_limit != -1 and self.current_level >= self.level_limit:\n                sys.exit(\"You have reached your target level! Exiting now.\")\n\n            self.previous_level = self.current_level\n\n    def _process_config(self):\n        self.level_limit = self.config.get('level_limit', -1)\n        self.collect_reward = self.config.get('collect_reward', True)\n\n    def _should_run(self):\n        return self.level_limit != -1 or self.collect_reward\n\n    def _collect_level_reward(self):\n        response_dict = self.bot.api.level_up_rewards(level=self.current_level)\n        if 'status_code' in response_dict and response_dict['status_code'] == 1:\n            data = (response_dict\n                    .get('responses', {})\n                    .get('LEVEL_UP_REWARDS', {})\n                    .get('items_awarded', []))\n\n            for item in data:\n                if 'item_id' in item and str(item['item_id']) in self.bot.item_list:\n                    got_item = self.bot.item_list[str(item['item_id'])]\n                    item['name'] = got_item\n                    count = 'item_count' in item and item['item_count'] or 0\n                    inventory.items().get(item['item_id']).add(count)\n            self.emit_event(\n                'level_up_reward',\n                formatted='Received level up reward: {items}',\n                data={\n                    # [{'item_id': 3, 'name': u'Ultraball', 'item_count': 10}, {'item_id': 103, 'name': u'Hyper Potion', 'item_count': 10}]\n                    'items': ', '.join([\"{}x {}\".format(x['item_count'], x['name']) for x in data])\n                }\n            )\n", "path": "pokemongo_bot/cell_workers/collect_level_up_reward.py"}]}