-
Notifications
You must be signed in to change notification settings - Fork 3
/
models.py
118 lines (99 loc) · 4.01 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
from discord import Guild
from discord.ext.commands import Context
from tortoise import Model, fields
from config.bot import bot_config
class GuildModel(Model):
id = fields.BigIntField(pk=True, description="Discord ID of the guild")
prefix = fields.CharField(
max_length=10,
default=bot_config.prefix,
description="Custom prefix of the guild",
)
users = fields.ManyToManyField("main.UserModel", related_name="Guild")
image_banner = fields.TextField(
description="BackGround image banner for the `rank` command", null=True
)
leveling_enabled = fields.BooleanField(
defualt=False,
description="Leveling Enabled or Disabled for the guild!",
null=True,
)
xp_multiplier = fields.IntField(description="Xp Multipication Value", default=1)
xp_role_rewards = fields.JSONField(
description="Role Rewards Level -> Role Mapping", null=True
)
@classmethod
async def from_id(cls, guild_id: int):
return (await cls.get_or_create(id=guild_id))[0]
@classmethod
async def from_guild_object(cls, guild: Guild):
return await cls.from_id(guild.id)
@classmethod
async def from_context(cls, ctx: Context):
return await cls.from_id(ctx.guild.id)
class Meta:
table = "guilds"
table_description = "Represents a discord guild's settings"
class UserModel(Model):
id = fields.BigIntField(pk=True, description="Discord ID of the user")
class Meta:
table = "users"
table_description = "Represents all users"
class AutoResponseModel(Model):
id = fields.UUIDField(pk=True)
trigger = fields.TextField(description="Trigger for the autoresponse")
response = fields.TextField(
default=None,
null=True,
description="Response to be sent after being triggered from the trigger",
)
enabled = fields.BooleanField(
default=False, description="Boolean to show of the trigger is enabled"
)
extra_arguements = fields.BooleanField(
default=False,
description="If the autoresponse should be run even when extra arguements are passed",
)
has_variables = fields.BooleanField(
default=False, description="If the autoresponse output has variables"
)
guild = fields.ForeignKeyField("main.GuildModel", related_name="Autoresponses")
created_by = fields.ForeignKeyField(
"main.UserModel", related_name="Autoresponses", null=True
)
class Meta:
table = "autoresponses"
table_description = "Represents the autoresponses for each GuildModel"
class CommandModel(Model):
id = fields.UUIDField(pk=True)
name = fields.TextField(description="Name of the cog or command!")
enabled = fields.BooleanField(
default=True, description="If the command/cog is enabled/disabled"
)
is_cog = fields.BooleanField(
default=False, description="If the command/cog is a command"
)
guild = fields.ForeignKeyField("main.GuildModel", related_name="Commands")
channel = fields.BigIntField(description="Channel of that disabled/enable command")
class Meta:
table = "commands"
table_description = (
"Represets all the enabled and disabled commands for each Guild"
)
class LevelingUserModel(Model):
id = fields.UUIDField(pk=True)
user = fields.ForeignKeyField("main.UserModel", related_name="LevelingUser")
guild = fields.ForeignKeyField("main.GuildModel", related_name="LevelingUser")
xp = fields.BigIntField(
description="XP of the user in that guild!", default=0, null=True
)
level = fields.IntField(description="Level of the user!", default=0, null=True)
image_banner = fields.TextField(
description="BackGround image banner for the `rank` command", null=True
)
messages = fields.IntField(
description="No. of messages sent by the user!", default=0
)
class Meta:
table = "UserLeveling"
table_description = "Represents the Leveling data for each user in a guild!"