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
|
|
|
|
7
|
|
|
from modules.get_settings import get_settings |
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.ROLE, True) |
20
|
|
|
] |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
# noinspection PyTypeChecker |
25
|
|
|
class BaseCog(commands.Cog): |
26
|
|
|
def __init__(self, bot): |
27
|
|
|
self.bot = bot |
28
|
|
|
self.create_log_msg("Init") |
29
|
|
|
self.legend_multiplier = 5 |
30
|
|
|
|
31
|
|
|
def get_bot(self): |
32
|
|
|
return self.bot |
33
|
|
|
|
34
|
|
|
# Find monster in config |
35
|
|
|
def get_monster(self, ctx, name: str): |
36
|
|
|
name = name.lower() |
37
|
|
|
monster_found = None |
38
|
|
|
|
39
|
|
|
for monster in self.bot.config["commands"]: |
40
|
|
|
if monster["name"].lower() == name or name in monster["triggers"]: |
41
|
|
|
monster_found = monster |
42
|
|
|
break |
43
|
|
|
|
44
|
|
|
if not monster_found: |
45
|
|
|
self.create_log_msg(f"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
|
|
|
self.create_log_msg(f"Failed to fetch roleID for monster {monster_found['name']}") |
51
|
|
|
return |
52
|
|
|
|
53
|
|
|
monster_found["role"] = monster_found["role"].id |
54
|
|
|
return monster_found |
55
|
|
|
|
56
|
|
|
def create_log_msg(self, message: str) -> None: |
57
|
|
|
dt_string = self.bot.get_current_time() |
58
|
|
|
# That's just my pedantic way to approach string aligning as .format did not work here as if I wanted to |
59
|
|
|
log: str = f"({dt_string}) [{self.__class__.__name__}]:" |
60
|
|
|
log = f"{log}\t{message}" if len(log) >= 40 else f"{log}\t\t{message}" |
61
|
|
|
print(log) |
62
|
|
|
logs_txt_dir: str = "logs/logs.txt" |
63
|
|
|
with open(logs_txt_dir, "a+") as file_object: |
64
|
|
|
file_object.write(f"{log}\n") |
65
|
|
|
|
66
|
|
|
# Create role if not on server |
67
|
|
|
async def create_new_role(self, guild, role) -> None: |
68
|
|
|
if get(guild.roles, name=role): |
69
|
|
|
return |
70
|
|
|
await guild.create_role(name=role) |
71
|
|
|
self.create_log_msg(f"{role} role created") |
72
|
|
|
|