mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2025-06-16 19:35:24 +02:00
Organization and better creating and posting message support for unauth users
This commit is contained in:
6
titanembeds/database/__init__.py
Normal file
6
titanembeds/database/__init__.py
Normal file
@ -0,0 +1,6 @@
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
db = SQLAlchemy()
|
||||
|
||||
from guilds import Guilds
|
||||
from unauthenticated_users import UnauthenticatedUsers
|
||||
from unauthenticated_bans import UnauthenticatedBans
|
19
titanembeds/database/authenticated_users.py
Normal file
19
titanembeds/database/authenticated_users.py
Normal file
@ -0,0 +1,19 @@
|
||||
from titanembeds.database import db
|
||||
import datetime
|
||||
|
||||
class AuthenticatedUsers(db.Model):
|
||||
__tablename__ = "authenticated_users"
|
||||
id = db.Column(db.Integer, primary_key=True) # Auto increment id
|
||||
guild_id = db.Column(db.String(255)) # Guild pretaining to the authenticated user
|
||||
client_id = db.Column(db.String(255)) # Client ID of the authenticated user
|
||||
last_timestamp = db.Column(db.TIMESTAMP) # The timestamp of when the user has last sent the heartbeat
|
||||
|
||||
def __init__(self, guild_id, client_id):
|
||||
self.guild_id = guild_id
|
||||
self.client_id = client_id
|
||||
self.last_timestamp = datetime.datetime.now
|
||||
|
||||
def bumpTimestamp(self):
|
||||
self.last_timestamp = datetime.datetime.now
|
||||
db.session.commit()
|
||||
return self.last_timestamp
|
19
titanembeds/database/guilds.py
Normal file
19
titanembeds/database/guilds.py
Normal file
@ -0,0 +1,19 @@
|
||||
from titanembeds.database import db
|
||||
|
||||
class Guilds(db.Model):
|
||||
__tablename__ = "guilds"
|
||||
id = db.Column(db.Integer, primary_key=True) # Auto incremented id
|
||||
guild_id = db.Column(db.String(255)) # Discord guild id
|
||||
unauth_users = db.Column(db.Boolean()) # If allowed unauth users
|
||||
|
||||
def __init__(self, guild_id):
|
||||
self.guild_id = guild_id
|
||||
self.unauth_users = true # defaults to true
|
||||
|
||||
def __repr__(self):
|
||||
return '<Guilds {0} {1}>'.format(self.id, self.guild_id)
|
||||
|
||||
def set_unauthUsersBool(self, value):
|
||||
self.unauth_users = value
|
||||
db.session.commit()
|
||||
return self.unauth_users
|
32
titanembeds/database/unauthenticated_bans.py
Normal file
32
titanembeds/database/unauthenticated_bans.py
Normal file
@ -0,0 +1,32 @@
|
||||
from titanembeds.database import db
|
||||
import datetime
|
||||
|
||||
class UnauthenticatedBans(db.Model):
|
||||
__tablename__ = "unauthenticated_bans"
|
||||
id = db.Column(db.Integer, primary_key=True) # Auto increment id
|
||||
guild_id = db.Column(db.String(255)) # Guild pretaining to the unauthenticated user
|
||||
ip_address = db.Column(db.String(255)) # The IP Address of the user
|
||||
last_username = db.Column(db.String(255)) # The username when they got banned
|
||||
last_discriminator = db.Column(db.Integer) # The discrim when they got banned
|
||||
timestamp = db.Column(db.TIMESTAMP) # The timestamp of when the user got banned
|
||||
reason = db.Column(db.Text()) # The reason of the ban set by the guild moderators
|
||||
lifter_id = db.Column(db.String(255)) # Discord Client ID of the user who lifted the ban
|
||||
placer_id = db.Column(db.String(255)) # The id of who placed the ban
|
||||
|
||||
def __init__(self, guild_id, ip_address, last_username, last_discriminator, reason, placer_id):
|
||||
self.guild_id = guild_id
|
||||
self.ip_address = ip_address
|
||||
self.last_username = last_username
|
||||
self.last_discriminator = last_discriminator
|
||||
self.timestamp = datetime.datetime.now
|
||||
self.reason = reason
|
||||
self.lifter_id = null
|
||||
self.placer_id = placer_id
|
||||
|
||||
def liftBan(self, lifter_id):
|
||||
self.lifter_id = lifter_id
|
||||
db.session.commit()
|
||||
return self.lifter_id
|
||||
|
||||
def __repr__(self):
|
||||
return '<UnauthenticatedBans {0} {1} {2} {3} {4} {5}'.format(self.id, self.guild_id, self.ip_address, self.last_username, self.last_discriminator, self.timestamp)
|
45
titanembeds/database/unauthenticated_users.py
Normal file
45
titanembeds/database/unauthenticated_users.py
Normal file
@ -0,0 +1,45 @@
|
||||
from titanembeds.database import db
|
||||
import datetime
|
||||
import random
|
||||
import string
|
||||
|
||||
class UnauthenticatedUsers(db.Model):
|
||||
__tablename__ = "unauthenticated_users"
|
||||
id = db.Column(db.Integer, primary_key=True) # Auto increment id
|
||||
guild_id = db.Column(db.String(255)) # Guild pretaining to the unauthenticated user
|
||||
username = db.Column(db.String(255)) # The username of the user
|
||||
discriminator = db.Column(db.Integer) # The discriminator to distinguish unauth users with each other
|
||||
user_key = db.Column(db.Text()) # The secret key used to identify the user holder
|
||||
ip_address = db.Column(db.String(255)) # The IP Address of the user
|
||||
last_timestamp = db.Column(db.TIMESTAMP) # The timestamp of when the user has last sent the heartbeat
|
||||
revoked = db.Column(db.Boolean()) # If the user's key has been revoked and a new one is required to be generated
|
||||
|
||||
def __init__(self, guild_id, username, discriminator, ip_address):
|
||||
self.guild_id = guild_id
|
||||
self.username = username
|
||||
self.discriminator = discriminator
|
||||
self.user_key = "".join(random.choice(string.ascii_letters) for _ in range(0, 32))
|
||||
self.ip_address = ip_address
|
||||
self.last_timestamp = datetime.datetime.now
|
||||
self.revoked = False
|
||||
|
||||
def __repr__(self):
|
||||
return '<UnauthenticatedUsers {0} {1} {2} {3} {4} {5} {6} {7}>'.format(self.id, self.guild_id, self.username, self.discriminator, self.user_key, self.ip_address, self.last_timestamp, self.revoked)
|
||||
|
||||
def isRevoked(self):
|
||||
return self.revoked
|
||||
|
||||
def changeUsername(self, username):
|
||||
self.username = username
|
||||
db.session.commit()
|
||||
return self.username
|
||||
|
||||
def revokeUser(self):
|
||||
self.revoked = True
|
||||
db.session.commit()
|
||||
return self.revoked
|
||||
|
||||
def bumpTimestamp(self):
|
||||
self.last_timestamp = datetime.datetime.now
|
||||
db.session.commit()
|
||||
return self.last_timestamp
|
Reference in New Issue
Block a user