maduck/GoWDiscordTeamBot

View on GitHub
search.py

Summary

Maintainability
F
1 wk
Test Coverage

File search.py has 1480 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import calendar
import copy
import datetime
import importlib
import json
Severity: Major
Found in search.py - About 3 days to fix

    TeamExpander has 84 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class TeamExpander:
        my_emojis = {}
    
        def __init__(self):
            world = GameData()
    Severity: Major
    Found in search.py - About 1 day to fix

      Function search_item has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def search_item(search_term, lang, items, lookup_keys, translator, sort_by='name'):
              if search_term.startswith('#'):
                  search_term = search_term[1:]
              if search_term.isdigit():
                  if item := items.get(int(search_term)):
      Severity: Minor
      Found in search.py - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function get_event_rewards has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_event_rewards(self, event, lang):
              for stage, stage_reward in event['rewards'].items():
                  stage_reward['name'] = _('[REWARD_N]', lang).replace('%1', str(stage))
                  if EVENT_TYPES[event['type']] == '[RAIDBOSS]':
                      if stage <= 2:
      Severity: Minor
      Found in search.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function translate_spoiler has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def translate_spoiler(self, spoiler, lang):
              # this is transitional until all new models are in place.
              if spoiler['type'] in ['pet']:
                  if item := getattr(self, spoiler['type'] + 's').get(spoiler['id']):
                      entry = item[translations.LANGUAGE_CODE_MAPPING.get(lang, lang)].data.copy()
      Severity: Minor
      Found in search.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function get_current_event has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_current_event(self, lang, emojis):
              event = copy.deepcopy(self.weekly_event)
              kingdoms = self.search_kingdom(event['kingdom_id'], lang)
              if kingdoms:
                  event['kingdom'] = kingdoms[0]
      Severity: Minor
      Found in search.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function search_affix has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def search_affix(self, search_term, lang):
              real_search = extract_search_tag(search_term)
              results = {}
              for weapon in self.weapons.values():
                  my_weapon = weapon.copy()
      Severity: Minor
      Found in search.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function get_team_from_code has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_team_from_code(self, code, lang):
              result = {
                  'troops': [],
                  'banner': {},
                  'class': None,
      Severity: Minor
      Found in search.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function __init__ has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def __init__(self):
              world = GameData()
              world.populate_world_data()
              self.troops = world.troops
              self.troop_types = world.troop_types
      Severity: Minor
      Found in search.py - About 1 hr to fix

        Function guess_weekly_kingdom_from_troop_spoilers has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def guess_weekly_kingdom_from_troop_spoilers(self, lang):
                result = {}
                latest_date = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc)
                for spoiler in self.spoilers:
                    if spoiler['type'] == 'troop' \
        Severity: Minor
        Found in search.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function translate_kingdom has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def translate_kingdom(self, kingdom, lang):
                kingdom['name'] = _(kingdom['name'], lang)
                if self.is_untranslated(kingdom['name']):
                    kingdom['name'] = kingdom['reference_name']
                kingdom['description'] = _(kingdom['description'], lang)
        Severity: Minor
        Found in search.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function kingdom_percentage has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def kingdom_percentage(self, filter_name, filter_values, lang):
                result = {}
                now = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc)
                hidden_kingdoms = [3032, 3033, 3034, 3038]
        
        
        Severity: Minor
        Found in search.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function translate_kingdom has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def translate_kingdom(self, kingdom, lang):
                kingdom['name'] = _(kingdom['name'], lang)
                if self.is_untranslated(kingdom['name']):
                    kingdom['name'] = kingdom['reference_name']
                kingdom['description'] = _(kingdom['description'], lang)
        Severity: Minor
        Found in search.py - About 1 hr to fix

          Function search_trait has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def search_trait(self, search_term, lang):
                  possible_matches = []
                  for code, trait in self.traits.items():
                      translated_name = extract_search_tag(_(trait['name'], lang))
                      translated_description = extract_search_tag(_(trait['description'], lang))
          Severity: Minor
          Found in search.py - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function translate_spell has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def translate_spell(self, spell_id, lang):
                  spell = self.spells[spell_id]
                  magic = _('[MAGIC]', lang)
          
                  description = self.translate_spell_description(spell['description'], lang)
          Severity: Minor
          Found in search.py - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function get_map_data has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def get_map_data(self, lang, location):
                  if not location:
                      location = 'krystara'
                  base_folder = 'Worldmap'
                  map_data = {
          Severity: Minor
          Found in search.py - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function get_current_event has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def get_current_event(self, lang, emojis):
                  event = copy.deepcopy(self.weekly_event)
                  kingdoms = self.search_kingdom(event['kingdom_id'], lang)
                  if kingdoms:
                      event['kingdom'] = kingdoms[0]
          Severity: Minor
          Found in search.py - About 1 hr to fix

            Function translate_weapon has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def translate_weapon(self, weapon, lang):
                    weapon['name'] = _(weapon['name'], lang)
                    weapon['description'] = _(weapon['description'], lang)
                    weapon['color_code'] = "".join(sorted(weapon['colors']))
                    weapon['spell_title'] = _('[TROOPHELP_SPELL0]', lang)
            Severity: Minor
            Found in search.py - About 1 hr to fix

              Function translate_drop_chances has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def translate_drop_chances(self, data: dict, lang):
                      for key, item in data.copy().items():
                          if not self.is_untranslated(key):
                              continue
                          new_key = _(key, lang)
              Severity: Minor
              Found in search.py - About 55 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function get_weekly_summary has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def get_weekly_summary(self, lang, emojis):
                      world_event = self.get_current_event(lang, emojis)
              
                      def get_single_event(event_type, weekday):
                          if filtered_events := [e for e in self.events
              Severity: Minor
              Found in search.py - About 45 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Consider simplifying this complex logical expression.
              Open

                      if gacha_pool and gacha and gacha in gacha_pool:
                          item = gacha_pool[gacha]
                          return _(item['name'], lang, default=item.get('reference_name', item['name']))
                      elif event_type == '[PETRESCUE]' and gacha and gacha in self.pets:
                          return self.pets[gacha][lang].name
              Severity: Major
              Found in search.py - About 40 mins to fix

                Function search_item has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def search_item(search_term, lang, items, lookup_keys, translator, sort_by='name'):
                Severity: Minor
                Found in search.py - About 35 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return sorted(possible_matches, key=operator.itemgetter(sort_by))
                  Severity: Major
                  Found in search.py - About 30 mins to fix

                    Function translate_weapon has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def translate_weapon(self, weapon, lang):
                            weapon['name'] = _(weapon['name'], lang)
                            weapon['description'] = _(weapon['description'], lang)
                            weapon['color_code'] = "".join(sorted(weapon['colors']))
                            weapon['spell_title'] = _('[TROOPHELP_SPELL0]', lang)
                    Severity: Minor
                    Found in search.py - About 25 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Function get_shop_rewards has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def get_shop_rewards(event, lang, emojis):
                            event['shop_title'] = _('[SHOP]', lang)
                            event['shop'] = []
                            total_cost = 0
                            total = _('[TOTAL]', lang)
                    Severity: Minor
                    Found in search.py - About 25 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Function translate_categories has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def translate_categories(categories, lang):
                            def try_different_translated_versions_because_devs_are_stupid(cat):
                                lookup = f'[{cat.upper()}S]'
                                result = _(lookup, lang)
                                if result == lookup:
                    Severity: Minor
                    Found in search.py - About 25 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Function search_talent has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def search_talent(self, search_term, lang):
                            possible_matches = []
                            for tree in self.talent_trees.values():
                                translated_name = extract_search_tag(_(tree['name'], lang))
                                translated_talents = [_(talent['name'], lang) for talent in tree['talents']]
                    Severity: Minor
                    Found in search.py - About 25 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Function __task_name_replacements has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def __task_name_replacements(self, task, color, lang):
                            replacements = {
                                '{WeaponType}': '[WEAPONTYPE_{c:u}]',
                                '{Kingdom}': '[{d:u}_NAME]',
                                '{Banner}': '[{c:u}_BANNERNAME]',
                    Severity: Minor
                    Found in search.py - About 25 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Function translate_toplist has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def translate_toplist(self, toplist_id, lang):
                            toplist = self.toplists.get(toplist_id)
                            if not toplist:
                                return None
                            result = toplist.copy()
                    Severity: Minor
                    Found in search.py - About 25 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    invalid syntax (<unknown>, line 108)</unknown>
                    Open

                                if troop := self.troops.get(element):
                    Severity: Critical
                    Found in search.py by pylint

                    Used when a syntax error is raised for a module.

                    There are no issues that match your filters.

                    Category
                    Status