2022-07-21 21:27:47 +02:00
|
|
|
import datetime
|
2022-07-25 02:32:07 +02:00
|
|
|
import os
|
2022-07-21 21:27:47 +02:00
|
|
|
|
2022-07-25 02:32:07 +02:00
|
|
|
from dotenv import load_dotenv
|
2022-07-21 20:50:23 +02:00
|
|
|
from peewee import (
|
|
|
|
SqliteDatabase,
|
2022-07-25 02:32:07 +02:00
|
|
|
PostgresqlDatabase,
|
2022-07-21 20:50:23 +02:00
|
|
|
Model,
|
|
|
|
BigIntegerField,
|
|
|
|
CharField,
|
|
|
|
TextField,
|
|
|
|
DateTimeField,
|
|
|
|
AutoField,
|
|
|
|
FloatField,
|
|
|
|
BooleanField,
|
|
|
|
CompositeKey,
|
|
|
|
ForeignKeyField,
|
2022-08-05 13:19:08 +02:00
|
|
|
IntegerField,
|
2022-07-21 20:50:23 +02:00
|
|
|
)
|
|
|
|
|
2022-07-25 02:32:07 +02:00
|
|
|
|
|
|
|
db = None
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The database connection."""
|
|
|
|
|
|
|
|
load_dotenv()
|
2022-07-25 02:32:07 +02:00
|
|
|
if (postgres_url := os.getenv("HEIMDALLR_POSTGRES_URL")) is not None:
|
|
|
|
db = PostgresqlDatabase(postgres_url)
|
|
|
|
else:
|
|
|
|
db = SqliteDatabase("heimdallr.db")
|
2022-07-21 20:50:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Infractions(Model):
|
2022-08-03 19:48:01 +02:00
|
|
|
"""A model for infractions."""
|
|
|
|
|
2022-07-21 20:50:23 +02:00
|
|
|
id = AutoField()
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The ID of the infraction."""
|
2022-07-21 20:50:23 +02:00
|
|
|
guild_id = BigIntegerField()
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The guild ID of the infraction."""
|
2022-07-21 20:50:23 +02:00
|
|
|
user_id = BigIntegerField()
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The user ID of the user receiving the infraction."""
|
2022-07-21 20:50:23 +02:00
|
|
|
at_time = DateTimeField(default=datetime.datetime.now)
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The time at which the infraction was received."""
|
2022-07-21 20:50:23 +02:00
|
|
|
weight = FloatField(default=1.0)
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The weight/severity of the infraction."""
|
2022-07-21 20:50:23 +02:00
|
|
|
reason = TextField(null=True)
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The reason for the infraction."""
|
2022-07-21 20:50:23 +02:00
|
|
|
given_by = BigIntegerField()
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The user ID of the user giving the infraction."""
|
2022-07-21 20:50:23 +02:00
|
|
|
silent = BooleanField(default=False)
|
2022-08-03 19:48:01 +02:00
|
|
|
"""Whether the infraction should be silent."""
|
2022-07-21 20:50:23 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
table_name = "Infractions"
|
|
|
|
database = db
|
|
|
|
|
|
|
|
|
|
|
|
class GuildSettings(Model):
|
2022-08-03 19:48:01 +02:00
|
|
|
"""A model for guild settings."""
|
|
|
|
|
2022-07-21 20:50:23 +02:00
|
|
|
guild_id = BigIntegerField(primary_key=True)
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The guild ID of the guild settings."""
|
2022-07-21 20:50:23 +02:00
|
|
|
admin_channel = BigIntegerField(null=True)
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The channel ID of the admin channel."""
|
2022-07-21 20:50:23 +02:00
|
|
|
use_name_filter = BooleanField(default=False)
|
2022-08-03 19:48:01 +02:00
|
|
|
"""Whether the bot should use a name filter."""
|
2022-07-21 20:50:23 +02:00
|
|
|
use_gatekeep = BooleanField(default=False)
|
2022-08-03 19:48:01 +02:00
|
|
|
"""Whether the bot should use gatekeep."""
|
2022-07-21 20:50:23 +02:00
|
|
|
use_logging = BooleanField(default=False)
|
2022-08-03 19:48:01 +02:00
|
|
|
"""Whether the bot should use logging."""
|
2022-07-21 20:50:23 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
table_name = "GuildSettings"
|
|
|
|
database = db
|
|
|
|
|
|
|
|
|
|
|
|
class JoinLeave(Model):
|
2022-08-03 19:48:01 +02:00
|
|
|
"""A model for join/leave messages."""
|
|
|
|
|
2022-07-21 20:50:23 +02:00
|
|
|
guild_id = BigIntegerField(primary_key=True)
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The guild ID of the guild settings."""
|
2022-07-21 20:50:23 +02:00
|
|
|
join_message = TextField(null=True)
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The join message."""
|
2022-07-21 20:50:23 +02:00
|
|
|
leave_message = TextField(null=True)
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The leave message."""
|
2022-07-21 20:50:23 +02:00
|
|
|
message_channel = BigIntegerField(null=True)
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The channel ID of the channel to send the message in."""
|
2022-07-21 20:50:23 +02:00
|
|
|
join_message_enabled = BooleanField(default=True)
|
2022-08-03 19:48:01 +02:00
|
|
|
"""Whether the join message is enabled."""
|
2022-07-21 20:50:23 +02:00
|
|
|
leave_message_enabled = BooleanField(default=False)
|
2022-08-03 19:48:01 +02:00
|
|
|
"""Whether the leave message is enabled."""
|
2022-07-21 20:50:23 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
table_name = "JoinLeave"
|
|
|
|
database = db
|
|
|
|
|
|
|
|
|
|
|
|
class SelfRoles(Model):
|
2022-08-03 19:48:01 +02:00
|
|
|
"""A model for self-assignable roles."""
|
|
|
|
|
2022-07-21 20:50:23 +02:00
|
|
|
guild_id = BigIntegerField()
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The guild ID of the guild for the self-role."""
|
2022-07-21 20:50:23 +02:00
|
|
|
role_id = BigIntegerField()
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The role ID of the self-role."""
|
2022-07-21 20:50:23 +02:00
|
|
|
role_name = TextField()
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The name of the self-role."""
|
2022-07-22 02:27:17 +02:00
|
|
|
role_description = TextField(null=True)
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The description of the self-role."""
|
2022-07-22 02:27:17 +02:00
|
|
|
requires = BigIntegerField(null=True)
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The role ID of the role required to assign the self-role, if any."""
|
2022-07-21 20:50:23 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
primary_key = CompositeKey("guild_id", "role_id")
|
|
|
|
table_name = "SelfRoles"
|
|
|
|
database = db
|
|
|
|
|
|
|
|
|
2022-08-03 19:48:01 +02:00
|
|
|
class SelfRoleGroups(Model):
|
|
|
|
"""A model for self-role groups."""
|
|
|
|
|
|
|
|
guild_id = BigIntegerField()
|
|
|
|
"""The guild ID of the guild for the self-role group."""
|
|
|
|
group_name = TextField()
|
|
|
|
"""The name of the self-role group."""
|
|
|
|
group_description = TextField(null=True)
|
|
|
|
"""The description of the self-role group."""
|
2022-08-04 00:56:46 +02:00
|
|
|
exclusive = BooleanField(default=False)
|
|
|
|
"""Whether the self-role group is exclusive."""
|
2022-08-03 19:48:01 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
primary_key = CompositeKey("guild_id", "group_name")
|
|
|
|
table_name = "SelfRoleGroups"
|
|
|
|
database = db
|
|
|
|
|
|
|
|
|
|
|
|
class SelfRoleGroupRelations(Model):
|
|
|
|
"""A model for self-role group relations."""
|
|
|
|
|
|
|
|
guild_id = ForeignKeyField(SelfRoleGroups, field="guild_id", backref="GuildRelation")
|
|
|
|
"""The guild ID of the guild for the self-role group."""
|
|
|
|
group_name = ForeignKeyField(SelfRoleGroups, field="group_name", backref="GroupRelation")
|
|
|
|
"""The name of the self-role group."""
|
|
|
|
role_id = BigIntegerField()
|
|
|
|
"""The role ID of the self-role."""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
primary_key = CompositeKey("guild_id", "group_name", "role_id")
|
|
|
|
table_name = "SelfRoleGroupRelations"
|
|
|
|
database = db
|
|
|
|
|
2022-07-21 20:50:23 +02:00
|
|
|
class ConditionalRoles(Model):
|
2022-08-03 19:48:01 +02:00
|
|
|
"""A model for conditional roles."""
|
|
|
|
|
2022-07-21 20:50:23 +02:00
|
|
|
guild_id = BigIntegerField()
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The guild ID of the guild for the conditional role."""
|
2022-07-21 20:50:23 +02:00
|
|
|
role_id = BigIntegerField()
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The role ID of the conditional role."""
|
2022-07-21 20:50:23 +02:00
|
|
|
condition = CharField(max_length=16)
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The condition for the conditional role."""
|
2022-07-21 20:50:23 +02:00
|
|
|
condition_data = TextField()
|
2022-08-03 19:48:01 +02:00
|
|
|
"""The data for the condition."""
|
2022-07-21 20:50:23 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
primary_key = CompositeKey("guild_id", "role_id")
|
|
|
|
table_name = "ConditionalRoles"
|
|
|
|
database = db
|
|
|
|
|
|
|
|
|
|
|
|
class BotMessages(Model):
|
|
|
|
guild_id = BigIntegerField()
|
|
|
|
channel_id = BigIntegerField()
|
|
|
|
message_id = BigIntegerField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
primary_key = CompositeKey("guild_id", "channel_id", "message_id")
|
|
|
|
table_name = "BotMessages"
|
|
|
|
database = db
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BadNames(Model):
|
|
|
|
id = AutoField()
|
|
|
|
guild_id = BigIntegerField()
|
|
|
|
regex = TextField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
table_name = "BadNames"
|
|
|
|
database = db
|
2022-08-04 03:52:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Gatekeep(Model):
|
|
|
|
guild_id = BigIntegerField(primary_key=True)
|
|
|
|
gatekeep_method = TextField(null=True)
|
|
|
|
gatekeep_approve_role = BigIntegerField(null=True)
|
|
|
|
gatekeep_approve_message = TextField(null=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
table_name = "Gatekeep"
|
|
|
|
database = db
|
|
|
|
|
|
|
|
class GatekeepCaptchas(Model):
|
|
|
|
guild_id = BigIntegerField()
|
|
|
|
user_id = BigIntegerField()
|
|
|
|
captcha = TextField(null=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
primary_key = CompositeKey("guild_id", "user_id")
|
|
|
|
table_name = "GatekeepCaptchas"
|
2022-08-05 13:19:08 +02:00
|
|
|
database = db
|
|
|
|
|
|
|
|
class Polls(Model):
|
|
|
|
id = AutoField()
|
|
|
|
guild_id = BigIntegerField()
|
|
|
|
channel_id = BigIntegerField(null=True)
|
|
|
|
message_id = BigIntegerField(null=True)
|
|
|
|
author_id = BigIntegerField()
|
|
|
|
title = TextField()
|
|
|
|
options = TextField()
|
|
|
|
no_options = IntegerField()
|
|
|
|
multiple_choice = BooleanField()
|
|
|
|
expires = DateTimeField(null=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
table_name = "Polls"
|
|
|
|
database = db
|
|
|
|
|
|
|
|
class PollVotes(Model):
|
|
|
|
id = AutoField()
|
|
|
|
poll_id = ForeignKeyField(Polls, to_field="id")
|
|
|
|
user_id = BigIntegerField()
|
|
|
|
option = IntegerField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
table_name = "PollVotes"
|
2022-08-04 03:52:53 +02:00
|
|
|
database = db
|