Organization and better creating and posting message support for unauth users

This commit is contained in:
Jeremy Zhang
2017-02-09 21:10:44 -08:00
parent 24e69f9fea
commit 030d492af1
17 changed files with 359 additions and 54 deletions

View 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

View 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

View 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

View 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)

View 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