def add_server(server_id, server_name):
    """
    Adds a server to the database
    :param server_id: Server id
    :param server_name: The server name
    """
    if not server_in_db(server_id):
        session = Session()
        new_server = Server(server_id=server_id, server_name=server_name)
        session.add(new_server)
        session.commit()
        session.close()
Beispiel #2
0
def create_user(discord_id, discord_name, server_id, reaction_count=0):
    """
    Create an user and post it to the database
    :param discord_id: Discord id
    :param discord_name: Discord name (not nickname)
    :param server_id: From which server the user comes
    :param reaction_count: Amount of reactions that user triggered
    """
    session = Session()
    user = User(uid=discord_id,
                username=discord_name,
                from_server=server_id,
                reaction_count=reaction_count)
    session.add(user)
    session.commit()
    session.close()
    logger.info(
        f"Posted user to DB | {discord_id}: {discord_name} [{server_id}]")
def add_reaction(answer, keyword, react_type, server_id):
    """
    Add a reaction to the database
    :param answer: What to send back as response
    :param keyword: On what keyword to match
    :param react_type: Whether the reaction to be sent is a gif or a normal message
    :param server_id: From which server the reaction belongs to
    """
    try:
        session = Session()
        reaction = Reaction(answer=answer,
                            keyword=keyword,
                            react_type=react_type,
                            from_server=server_id)
        session.add(reaction)
        session.commit()
        session.close()
    except:
        logger.error('Error when commiting reaction to database',
                     exc_info=True)