2017-02-10 06:10:44 +01:00
|
|
|
from flask_sqlalchemy import SQLAlchemy
|
2017-04-24 08:02:03 +02:00
|
|
|
|
2017-02-10 06:10:44 +01:00
|
|
|
db = SQLAlchemy()
|
|
|
|
|
2017-08-19 02:33:50 +02:00
|
|
|
from .guilds import Guilds
|
|
|
|
from .unauthenticated_users import UnauthenticatedUsers
|
|
|
|
from .unauthenticated_bans import UnauthenticatedBans
|
|
|
|
from .authenticated_users import AuthenticatedUsers
|
|
|
|
from .guild_members import GuildMembers, list_all_guild_members, get_guild_member
|
|
|
|
from .messages import Messages, get_channel_messages
|
2017-12-07 07:49:32 +01:00
|
|
|
from .cosmetics import Cosmetics, set_badges, get_badges, add_badge, remove_badge
|
2017-08-19 02:33:50 +02:00
|
|
|
from .user_css import UserCSS
|
|
|
|
from .administrators import Administrators, get_administrators_list
|
|
|
|
from .titan_tokens import TitanTokens, get_titan_token
|
|
|
|
from .token_transactions import TokenTransactions
|
2017-11-22 03:41:43 +01:00
|
|
|
from .patreon import Patreon
|
2017-08-14 03:10:03 +02:00
|
|
|
|
|
|
|
def set_titan_token(user_id, amt_change, action):
|
|
|
|
token_count = get_titan_token(user_id)
|
|
|
|
if token_count >= 0:
|
|
|
|
token_usr = db.session.query(TitanTokens).filter(TitanTokens.user_id == user_id).first()
|
|
|
|
else:
|
|
|
|
token_count = 0
|
|
|
|
token_usr = TitanTokens(user_id, 0)
|
|
|
|
new_token_count = token_count + amt_change
|
|
|
|
if new_token_count < 0:
|
|
|
|
return False
|
|
|
|
transact = TokenTransactions(user_id, action, amt_change, token_count, new_token_count)
|
|
|
|
db.session.add(transact)
|
|
|
|
token_usr.tokens = new_token_count
|
|
|
|
db.session.add(token_usr)
|
|
|
|
db.session.commit()
|
|
|
|
return True
|