Passed
Push — main ( 14d315...db93df )
by Bartosz
01:56
created

cogs.cogbase   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 83.67 %

Importance

Changes 0
Metric Value
eloc 30
dl 41
loc 49
rs 10
c 0
b 0
f 0
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
B BaseCog.get_monster() 35 35 7
A BaseCog.__init__() 3 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
import json
2
3
import discord
4
from discord.ext import commands
5
from discord_slash import SlashContext
6
7
8 View Code Duplication
class BaseCog(commands.Cog):
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9
    def __init__(self, bot):
10
        self.bot = bot
11
        print(f"[INFO]: Init {self.__class__.__name__}")
12
13
    # Find monster in config
14
    async def get_monster(self, ctx: SlashContext, name: str):
15
        """
16
17
        :param ctx:
18
        :type ctx:
19
        :param name:
20
        :type name:
21
        :return:
22
        :rtype:
23
        """
24
        monster = []
25
        name = name.lower()
26
27
        for monsters in self.bot.config["commands"]:
28
            if monsters["name"].lower() == name:
29
                monster = monsters
30
                break
31
            for monster_triggers in monsters["triggers"]:
32
                if monster_triggers == name:
33
                    monster = monsters
34
35
        if not monster:
36
            print("Monster not found")
37
            await ctx.send("Monster not found", hidden=True)
38
            return
39
40
        monster["role"] = discord.utils.get(ctx.guild.roles, name=monster["name"])
41
        if not monster["role"]:
42
            print(f"Failed to fetch roleID for monster {monster['name']}")
43
            await ctx.send("Role not found", hidden=True)
44
            return
45
46
        else:
47
            monster["role"] = monster["role"].id
48
        return monster
49