Inital postgresql implementation (#46)

This commit is contained in:
Jeremy "EndenDragon" Zhang
2017-09-04 23:54:54 -07:00
committed by GitHub
parent 3a503c9bcb
commit aa9075f484
11 changed files with 54 additions and 54 deletions

View File

@ -21,7 +21,7 @@ except:
os.chdir(config['app-location'])
app = Flask(__name__, static_folder="static")
app.config['SQLALCHEMY_DATABASE_URI'] = config['database-uri'] + "?charset=utf8mb4"
app.config['SQLALCHEMY_DATABASE_URI'] = config['database-uri']
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # Suppress the warning/no need this on for now.
app.config['RATELIMIT_HEADERS_ENABLED'] = True
app.config['SQLALCHEMY_POOL_RECYCLE'] = 250

View File

@ -231,7 +231,7 @@ def add_bot(guild_id):
def prepare_guild_members_list(members, bans):
all_users = []
ip_pool = []
members = sorted(members, key=lambda k: datetime.datetime.strptime(str(k.last_timestamp), "%Y-%m-%d %H:%M:%S"), reverse=True)
members = sorted(members, key=lambda k: datetime.datetime.strptime(str(k.last_timestamp.replace(tzinfo=None)), "%Y-%m-%d %H:%M:%S"), reverse=True)
for member in members:
user = {
"id": member.id,

View File

@ -11,10 +11,10 @@ class Guilds(db.Model):
chat_links = db.Column(db.Boolean(), nullable=False, default=1) # If users can post links
bracket_links = db.Column(db.Boolean(), nullable=False, default=1) # If appending brackets to links to prevent embed
mentions_limit = db.Column(db.Integer, nullable=False, default=11) # If there is a limit on the number of mentions in a msg
roles = db.Column(db.Text(4294967295), nullable=False) # Guild Roles
channels = db.Column(db.Text(4294967295), nullable=False) # Guild channels
webhooks = db.Column(db.Text(4294967295), nullable=False) # Guild webhooks
emojis = db.Column(db.Text(4294967295), nullable=False) # Guild Emojis
roles = db.Column(db.Text().with_variant(db.Text(4294967295), 'mysql'), nullable=False) # Guild Roles
channels = db.Column(db.Text().with_variant(db.Text(4294967295), 'mysql'), nullable=False) # Guild channels
webhooks = db.Column(db.Text().with_variant(db.Text(4294967295), 'mysql'), nullable=False) # Guild webhooks
emojis = db.Column(db.Text().with_variant(db.Text(4294967295), 'mysql'), nullable=False) # Guild Emojis
owner_id = db.Column(db.String(255), nullable=False) # Snowflake of the owner
icon = db.Column(db.String(255)) # The icon string, null if none
discordio = db.Column(db.String(255)) # Custom Discord.io Invite Link

View File

@ -20,14 +20,14 @@ def set_keyvalproperty(key, value, expiration=None):
def get_keyvalproperty(key):
q = db.session.query(KeyValueProperties).filter(KeyValueProperties.key == key)
now = datetime.now()
if q.count() > 0 and (q.first().expiration is None or q.first().expiration > now):
if q.count() > 0 and (q.first().expiration is None or q.first().expiration.replace(tzinfo=None) > now):
return q.first().value
return None
def getexpir_keyvalproperty(key):
q = db.session.query(KeyValueProperties).filter(KeyValueProperties.key == key)
now = datetime.now()
if q.count() > 0 and (q.first().expiration is not None and q.first().expiration > now):
if q.count() > 0 and (q.first().expiration is not None and q.first().expiration.replace(tzinfo=None) > now):
return int(q.first().expiration.strftime('%s'))
return 0

View File

@ -5,7 +5,7 @@ class UserCSS(db.Model):
id = db.Column(db.Integer, primary_key=True) # Auto increment id
name = db.Column(db.String(255), nullable=False) # CSS Name
user_id = db.Column(db.String(255), nullable=False) # Discord client ID of the owner of the css (can edit)
css = db.Column(db.Text(4294967295)) # CSS contents
css = db.Column(db.Text().with_variant(db.Text(4294967295), 'mysql')) # CSS contents
def __init__(self, name, user_id, css=None):
self.name = name