Passed
Push — main ( 530a31...c507f0 )
by Bartosz
02:42 queued 01:19
created

build.cogs.cogbase.BaseCog.create_log_msg()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nop 2
1
import discord
2
from discord.ext import commands
3
from discord.utils import get
4
from discord_slash.model import SlashCommandPermissionType
5
from discord_slash.utils.manage_commands import create_permission
6
from modules.get_settings import get_settings
7
8
GUILD_IDS = get_settings("guild")
9
MODERATION_IDS = get_settings("MOD_ROLES")
10
PERMISSION_MODS = {
11
    GUILD_IDS[0]: [
12
        create_permission(MODERATION_IDS[0], SlashCommandPermissionType.ROLE, True),
13
        create_permission(MODERATION_IDS[1], SlashCommandPermissionType.ROLE, True)
14
    ]
15
}
16
PERMISSION_ADMINS = {
17
    GUILD_IDS[0]: [
18
        create_permission(get_settings("ADMIN"), SlashCommandPermissionType.USER, True)
19
    ]
20
}
21
22
23
# noinspection PyTypeChecker
24
class BaseCog(commands.Cog):
25
    def __init__(self, bot):
26
        self.bot = bot
27
        self.create_log_msg("Init")
28
        self.legend_multiplier = 5
29
30
    def get_bot(self):
31
        return self.bot
32
33
    # Find monster in config
34
    def get_monster(self, ctx, name: str):
35
        name = name.lower()
36
        monster_found = None
37
38
        for monster in self.bot.config["commands"]:
39
            if monster["name"].lower() == name or name in monster["triggers"]:
40
                monster_found = monster
41
                break
42
43
        if not monster_found:
44
            self.create_log_msg(f"Monster not found ({ctx.author}: {name})")
45
            return
46
47
        monster_found["role"] = discord.utils.get(ctx.guild.roles, name=monster_found["name"])
48
        if not monster_found["role"]:
49
            self.create_log_msg(f"Failed to fetch roleID for monster {monster_found['name']}")
50
            return
51
52
        monster_found["role"] = monster_found["role"].id
53
        return monster_found
54
55
    # Create role if not on server
56
    async def create_role(self, guild, role):
57
        if get(guild.roles, name=role):
58
            return
59
        else:
60
            await guild.create_role(name=role)
61
            self.create_log_msg(f"{role} role created")
62
63
    # Print message from cog
64
    def create_log_msg(self, message: str):
65
        dt_string = self.bot.get_current_time()
66
        print(f"({dt_string})\t[{self.__class__.__name__}]: {message}")
67