|
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
|
|
|
from datetime import datetime |
|
8
|
|
|
|
|
9
|
|
|
GUILD_IDS = get_settings("guild") |
|
10
|
|
|
MODERATION_IDS = get_settings("MOD_ROLES") |
|
11
|
|
|
PERMISSION_MODS = { |
|
12
|
|
|
GUILD_IDS[0]: [ |
|
13
|
|
|
create_permission(MODERATION_IDS[0], SlashCommandPermissionType.ROLE, True), |
|
14
|
|
|
create_permission(MODERATION_IDS[1], SlashCommandPermissionType.ROLE, True) |
|
15
|
|
|
] |
|
16
|
|
|
} |
|
17
|
|
|
PERMISSION_ADMINS = { |
|
18
|
|
|
GUILD_IDS[0]: [ |
|
19
|
|
|
create_permission(get_settings("ADMIN"), SlashCommandPermissionType.USER, True) |
|
20
|
|
|
] |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
# noinspection PyTypeChecker |
|
25
|
|
|
class BaseCog(commands.Cog): |
|
26
|
|
|
def __init__(self, bot): |
|
27
|
|
|
self.bot = bot |
|
28
|
|
|
now = datetime.now() |
|
29
|
|
|
dt_string = now.strftime("%d/%m/%Y %H:%M:%S") |
|
30
|
|
|
print(f"({dt_string})\t[{self.__class__.__name__}]: Init") |
|
31
|
|
|
|
|
32
|
|
|
def get_bot(self): |
|
33
|
|
|
return self.bot |
|
34
|
|
|
|
|
35
|
|
|
# Find monster in config |
|
36
|
|
|
def get_monster(self, ctx, name: str): |
|
37
|
|
|
name = name.lower() |
|
38
|
|
|
monster_found = [] |
|
39
|
|
|
|
|
40
|
|
|
for monster in self.bot.config["commands"]: |
|
41
|
|
|
if monster["name"].lower() == name or name in monster["triggers"]: |
|
42
|
|
|
monster_found = monster |
|
43
|
|
|
|
|
44
|
|
|
if not monster_found: |
|
45
|
|
|
print(f"[{self.__class__.__name__}]: Monster not found ({ctx.author}: {name})") |
|
46
|
|
|
return |
|
47
|
|
|
|
|
48
|
|
|
monster_found["role"] = discord.utils.get(ctx.guild.roles, name=monster_found["name"]) |
|
49
|
|
|
if not monster_found["role"]: |
|
50
|
|
|
print(f"[{self.__class__.__name__}]: Failed to fetch roleID for monster {monster_found['name']}") |
|
51
|
|
|
return |
|
52
|
|
|
|
|
53
|
|
|
else: |
|
54
|
|
|
monster_found["role"] = monster_found["role"].id |
|
55
|
|
|
return monster_found |
|
56
|
|
|
|
|
57
|
|
|
# Create role if not on server |
|
58
|
|
|
async def create_role(self, guild, role): |
|
59
|
|
|
if get(guild.roles, name=role): |
|
60
|
|
|
return |
|
61
|
|
|
else: |
|
62
|
|
|
await guild.create_role(name=role) |
|
63
|
|
|
print(f"[{self.__class__.__name__}]: {role} role created") |
|
64
|
|
|
|
|
65
|
|
|
@staticmethod |
|
66
|
|
|
def get_current_time(): |
|
67
|
|
|
now = datetime.now() |
|
68
|
|
|
dt_string = now.strftime("%d/%m/%Y %H:%M:%S") |
|
69
|
|
|
return dt_string |
|
70
|
|
|
|