def apply_evolution(username, position):
    con = get_connection()
    evolution_result = check_evolution_eligibility(username, position)
    trade_evolution_result = check_trade_evolution_eligibility(
        username, position)
    if evolution_result is not None:
        nickname = evolution_result[0]
        id = evolution_result[3]
        if nickname == evolution_result[1]:
            nickname = evolution_result[2]
        with con:
            cur = con.cursor()
            cur.execute("""
                UPDATE userpokemon SET pokemon_id = %s, nickname = %s
                    WHERE username = %s AND position = %s
                """, [id, nickname, username, position])
            cur.close()
            return nickname + " has evolved! Raise your Kappa s!!!"
    elif trade_evolution_result is not None:
        con = get_connection()
        nickname = trade_evolution_result[0]
        id = trade_evolution_result[3]
        if nickname == trade_evolution_result[1]:
            nickname = trade_evolution_result[2]
        with con:
            cur = con.cursor()
            cur.execute("""
                UPDATE userpokemon SET pokemon_id = %s, nickname = %s
                    WHERE username = %s AND position = %s
                """, [id, nickname, username, position])
            cur.close()
            return nickname + " has evolved! Raise your Kappa s!!!"
    else:
        return "No Pokemon eligible for evolution."
def apply_evolution(username, position):
    con = get_connection()
    evolution_result = check_evolution_eligibility(username, position)
    trade_evolution_result = check_trade_evolution_eligibility(
        username, position)
    if evolution_result is not None:
        nickname = evolution_result[0]
        id = evolution_result[3]
        if nickname == evolution_result[1]:
            nickname = evolution_result[2]
        with con:
            cur = con.cursor()
            cur.execute("""
                UPDATE userpokemon SET pokemon_id = %s, nickname = %s
                    WHERE username = %s AND position = %s
                """, [id, nickname, username, position])
            cur.close()
            return nickname + " has evolved! Raise your Kappa s!!!"
    elif trade_evolution_result is not None:
        con = get_connection()
        nickname = trade_evolution_result[0]
        id = trade_evolution_result[3]
        if nickname == trade_evolution_result[1]:
            nickname = trade_evolution_result[2]
        with con:
            cur = con.cursor()
            cur.execute("""
                UPDATE userpokemon SET pokemon_id = %s, nickname = %s
                    WHERE username = %s AND position = %s
                """, [id, nickname, username, position])
            cur.close()
            return nickname + " has evolved! Raise your Kappa s!!!"
    else:
        return "No Pokemon eligible for evolution."
def set_battle_timestamp(username, datetime):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""UPDATE users SET lastbattle = %s WHERE username = %s""",
                    [datetime, username])
        cur.close()
def pokemon_market_set():
    con = get_connection()
    with con:
        base_price = 500
        cur = con.cursor()
        cur.execute("""DELETE FROM market""")
        cur.execute("""ALTER TABLE market AUTO_INCREMENT=1""")
        cur.close()
        cur = con.cursor()
        cur.execute("""SELECT id, rarity FROM pokemon""")
        pokemon = cur.fetchall()[0:151]
        cur.close()
        selected_pokemon = []
        rarity_index = {"0": 4, "1": 3, "2": 2, "3": 1}

        def get_random_pokemon():
            random_pokemon = random.choice(pokemon)
            if random_pokemon[0] in selected_pokemon:
                get_random_pokemon()
            else:
                selected_pokemon.append(random_pokemon[0])
                return random_pokemon
        for i in range(6):
            random_pokemon = get_random_pokemon()
            cur = con.cursor()
            cur.execute("""
                INSERT INTO market(pokemon_id, price, time) VALUES(%s, %s, %s)
            """, [
                random_pokemon[0], rarity_index[str(random_pokemon[1])] * base_price,
                datetime.now()
            ])
            cur.close()
Esempio n. 5
0
def modify_user_points(username, delta):
    donation_points = get_user_points(username)
    if isinstance(donation_points, str):
        donation_points = 0
    time_points = get_user_time_points(username)
    if isinstance(time_points, str):
        time_points = 0
    con = get_connection()
    with con:
        cur = con.cursor()
        if abs(delta) > donation_points and delta <= 0:
            time_points_to_remove = abs(donation_points - abs(delta))
            cur.execute(
                """INSERT INTO users (username, donation_points)
                    VALUES (%s, %s) ON DUPLICATE KEY
                    UPDATE donation_points = %s,
                    time_points = time_points - %s""", [
                    username, 0, 0, time_points_to_remove])
        else:  # standard for removal
            cur.execute(
                """INSERT INTO users (username, donation_points)
                    VALUES (%s, %s) ON DUPLICATE KEY
                    UPDATE donation_points = donation_points + %s""", [
                    username, delta, delta])
        cur.close()
def check_trade_evolution_eligibility(username, position):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute(
            """SELECT userpokemon.nickname, pokemon.name, pokeset.name, pokeset.id,
        pokeset.evolution_set, pokeset.evolution_index, pokeset.evolution_trigger, userpokemon.for_trade
        FROM userpokemon JOIN pokemon on userpokemon.pokemon_id = pokemon.id
        JOIN pokemon as pokeset on pokemon.evolution_set = pokeset.evolution_set
        WHERE userpokemon.username = %s AND userpokemon.position = %s
        AND pokeset.evolution_index = pokemon.evolution_index + 1
        AND pokeset.evolution_trigger = 20 and for_trade = 2;
        """,
            [username, position],
        )

        # +----------+---------+--------+----+---------------+-----------------+-------------------+
        # | nickname | name    | name   | id | evolution_set | evolution_index + evolution_trigger |
        # +----------+---------+--------+----+---------------+-----------------+-------------------+
        # | Haunter  | Haunter | Gengar | 94 |            39 |               3 +                20 |
        # +----------+---------+--------+----+---------------+-----------------+-------------------+

        eligible_evolution = cur.fetchone()
        cur.close()
        return eligible_evolution
def trade_transaction(giver, giver_position, receiver, receiver_position):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute(
            """
            UPDATE userpokemon SET username = %s, for_trade = 2, position = 0
                WHERE username = %s
                    AND position = %s""",
            [receiver, giver, giver_position],
        )
        cur.execute(
            """
            UPDATE userpokemon SET username = %s, for_trade = 2, position = %s
                WHERE username = %s
                    AND position = %s""",
            [giver, giver_position, receiver, receiver_position],
        )
        cur.execute(
            """
            UPDATE userpokemon SET position = %s, for_trade = 2
                WHERE position = 0""",
            [receiver_position],
        )
        cur.execute(
            """
            UPDATE userpokemon SET time_trade_set = NULL
                WHERE username = %s AND position = %s
        """,
            [receiver, receiver_position],
        )
        cur.close()
def trade_transaction(giver, giver_position, receiver, receiver_position):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute(
            """
            UPDATE userpokemon SET username = %s, for_trade = 2, position = 0
                WHERE username = %s
                    AND position = %s""", [receiver, giver, giver_position])
        cur.execute(
            """
            UPDATE userpokemon SET username = %s, for_trade = 2, position = %s
                WHERE username = %s
                    AND position = %s""",
            [giver, giver_position, receiver, receiver_position])
        cur.execute(
            """
            UPDATE userpokemon SET position = %s, for_trade = 2
                WHERE position = 0""", [receiver_position])
        cur.execute(
            """
            UPDATE userpokemon SET time_trade_set = NULL
                WHERE username = %s AND position = %s
        """, [receiver, receiver_position])
        cur.close()
def user_pokemon_types_summary(username, position):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""SELECT userpokemon.nickname AS 'Nickname',
        type_primary.id as 'ID 1', type_secondary.id AS 'ID 2',
        pokemon.name AS 'Name', type_primary.identifier AS 'Type 1',
        type_secondary.identifier AS 'Type 2'
        FROM userpokemon INNER JOIN pokemon
            ON pokemon.id = userpokemon.pokemon_id inner
        JOIN types AS type_primary
            ON (type_primary.id = pokemon.type_primary)
        LEFT OUTER JOIN types AS type_secondary
            ON (type_secondary.id = pokemon.type_secondary)
        WHERE username = %s AND userpokemon.position = %s""", [
            username, position])
        types_summary = cur.fetchone()
        nickname = types_summary[0]
        pokemon_type1_id = types_summary[1]
        pokemon_type2_id = types_summary[2]
        pokemon_name = types_summary[3]
        pokemon_type1 = types_summary[4]
        cur.close()
        if types_summary[2] and types_summary[5] is not None:
            pokemon_type2 = types_summary[5]
            return nickname, pokemon_type1_id, pokemon_type2_id, pokemon_name, pokemon_type1, pokemon_type2
        else:
            pokemon_type2 = "No secondary type."
            return nickname, pokemon_type1_id, 'none', pokemon_name, pokemon_type1, 'none'
def buy_items(id, username):
    con = get_connection()
    with con:
        try:
            if int(id) in (1, 2, 3, 4, 5, 11):
                points = int(get_user_points(username))
                value = int(get_item_value(id))
                if points >= value:
                    cur = con.cursor()
                    cur.execute("""
                        INSERT INTO useritems (username, item_id, quantity)
                                VALUES (%s, %s, 1) ON DUPLICATE KEY
                                UPDATE quantity = quantity + 1""", [
                        username, id])
                    cur.execute("""
                        UPDATE users SET points = points - %s
                            WHERE username = %s""", [value, username])
                    cur.close()
                    return "Transaction successful."
                else:
                    return "You need more points for that!"
            else:
                return "That is not a valid item position."
        except Exception as error:
            print error
            return "item ID must be a number"
Esempio n. 11
0
def modify_points_all_users_timer(all_users, points_to_increment=1):
    con = get_connection()
    user_list_for_query = [(x, str(points_to_increment)) for x in all_users]
    try:
        with con:
            cur = con.cursor()
            dData = user_list_for_query  # exact input you gave
            sql = """
                INSERT INTO users (username, points)
                        VALUES (%s, %s)
                    ON DUPLICATE KEY UPDATE points = points +
                """ + str(points_to_increment)
            cur.executemany(sql, ((user, points) for user, points in dData))
            sql = """
                INSERT INTO users (username, time_in_chat)
                    VALUES (%s, %s)
                    ON DUPLICATE KEY UPDATE time_in_chat = time_in_chat +
                        """ + str(5)
            cur.executemany(sql, ((user, points) for user, points in dData))
            cur.close()
            return "success"
    except Exception as error:
        cur.close()
        print "ERROR", error
        return "Error incrementing points:" + str(error)
def sell_transaction(username):
    con = get_connection()
    seller = 'lorenzotherobot'
    buyer = username
    open_position = 5
    with con:
        cur = con.cursor()
        cur.execute("""SET @seller = %s""", [seller])
        cur.execute("""@position = %s""", [party_position])
        cur.execute("""SET @buyer = %s""", [buyer])
        cur.execute("""SET @position_free = %s""", [open_position])
        cur.execute("""
            SET @price = (
                SELECT asking_price FROM userpokemon WHERE username = @owner
                    AND position = @position)""")
        cur.execute("""
            UPDATE userpokemon SET username = @buyer, for_sale = 0,
                position = @position_free WHERE username = @seller
                    AND position = @position""")
        cur.execute("""
            UPDATE users SET points = points + @price
                WHERE username = @seller""")
        cur.execute("""
            UPDATE users SET points = points - @price
                WHERE username = @buyer""")
        cur.execute("""COMMIT""")
        cur.close()
def modify_points_all_users_timer(all_users, points_to_increment=1):
    con = get_connection()
    user_list_for_query = [(x, str(points_to_increment)) for x in all_users]
    try:
        with con:
            cur = con.cursor()
            dData = user_list_for_query  # exact input you gave
            sql = """
                INSERT INTO users (username, points)
                        VALUES (%s, %s)
                    ON DUPLICATE KEY UPDATE points = points +
                """ + str(points_to_increment)
            cur.executemany(sql, ((user, points) for user, points in dData))
            sql = """
                INSERT INTO users (username, time_in_chat)
                    VALUES (%s, %s)
                    ON DUPLICATE KEY UPDATE time_in_chat = time_in_chat +
                        """ + str(5)
            cur.executemany(sql, ((user, points) for user, points in dData))
            cur.close()
            return "success"
    except Exception as error:
        cur.close()
        print "ERROR", error
        return "Error incrementing points:" + str(error)
Esempio n. 14
0
def sell_transaction(username):
    con = get_connection()
    seller = 'lorenzotherobot'
    buyer = username
    open_position = 5
    with con:
        cur = con.cursor()
        cur.execute("""SET @seller = %s""", [seller])
        cur.execute("""@position = %s""", [party_position])
        cur.execute("""SET @buyer = %s""", [buyer])
        cur.execute("""SET @position_free = %s""", [open_position])
        cur.execute("""
            SET @price = (
                SELECT asking_price FROM userpokemon WHERE username = @owner
                    AND position = @position)""")
        cur.execute("""
            UPDATE userpokemon SET username = @buyer, for_sale = 0,
                position = @position_free WHERE username = @seller
                    AND position = @position""")
        cur.execute("""
            UPDATE users SET donation_points = donation_points + @price
                WHERE username = @seller""")
        cur.execute("""
            UPDATE users SET donation_points = donation_points - @price
                WHERE username = @buyer""")
        cur.execute("""COMMIT""")
        cur.close()
Esempio n. 15
0
def buy_items(id, username):
    con = get_connection()
    with con:
        try:
            if int(id) in (1, 2, 3, 4, 5, 11):
                points = int(get_user_points(username))
                value = int(get_item_value(id))
                if points >= value:
                    cur = con.cursor()
                    cur.execute("""
                        INSERT INTO useritems (username, item_id, quantity)
                                VALUES (%s, %s, 1) ON DUPLICATE KEY
                                UPDATE quantity = quantity + 1""", [
                        username, id])
                    cur.execute("""
                        UPDATE users SET donation_points = donation_points - %s
                            WHERE username = %s""", [value, username])
                    cur.close()
                    return "Transaction successful."
                else:
                    return "You need more points for that!"
            else:
                return "That is not a valid item position."
        except Exception as error:
            print error
            return "item ID must be a number"
def get_user_stats(username):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            SELECT wins, losses FROM users WHERE username = %s
            """, [username])
        user_data = cur.fetchone()
        print "USER DATA", user_data
        if len(user_data) > 0:
            y = user_data[0]
            z = user_data[1]
            try:
                ratio = int((float(y) / ((float(y) + float(z)))) * 100)
            except:
                if y > 0:
                    ratio = 100
                else:
                    ratio = 0
            response = "W{0}, L{1}, {2}%".format(
                y, z, ratio)
        else:
            response = "You've got to actually battle first!"
        cur.close()
        return response
def user_pokemon_types_summary(username, position):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""SELECT userpokemon.nickname AS 'Nickname',
        type_primary.id as 'ID 1', type_secondary.id AS 'ID 2',
        pokemon.name AS 'Name', type_primary.identifier AS 'Type 1',
        type_secondary.identifier AS 'Type 2'
        FROM userpokemon INNER JOIN pokemon
            ON pokemon.id = userpokemon.pokemon_id inner
        JOIN types AS type_primary
            ON (type_primary.id = pokemon.type_primary)
        LEFT OUTER JOIN types AS type_secondary
            ON (type_secondary.id = pokemon.type_secondary)
        WHERE username = %s AND userpokemon.position = %s""", [
            username, position])
        types_summary = cur.fetchone()
        nickname = types_summary[0]
        pokemon_type1_id = types_summary[1]
        pokemon_type2_id = types_summary[2]
        pokemon_name = types_summary[3]
        pokemon_type1 = types_summary[4]
        cur.close()
        if types_summary[2] and types_summary[5] is not None:
            pokemon_type2 = types_summary[5]
            return nickname, pokemon_type1_id, pokemon_type2_id, pokemon_name, pokemon_type1, pokemon_type2
        else:
            pokemon_type2 = "No secondary type."
            return nickname, pokemon_type1_id, 'none', pokemon_name, pokemon_type1, 'none'
Esempio n. 18
0
def get_item_value(id):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""SELECT value FROM items WHERE id = %s""", [id])
        value = cur.fetchone()
        cur.close()
        return value[0]
def level_up_user_pokemon(username, position):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""update userpokemon set level = level + 1
        where username = %s and position = %s
        """, [username, position])
        cur.close()
Esempio n. 20
0
def add_loss(username):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            UPDATE users SET losses = losses + 1 WHERE username = %s
        """, [username])
        cur.close()
def add_loss(username):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            UPDATE users SET losses = losses + 1 WHERE username = %s
        """, [username])
        cur.close()
Esempio n. 22
0
def set_battle_timestamp(username, datetime):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute(
            """UPDATE users SET lastbattle = %s WHERE username = %s""", [
                datetime, username])
        cur.close()
Esempio n. 23
0
def level_up_user_pokemon(username, position):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""update userpokemon set level = level + 1
        where username = %s and position = %s
        """, [username, position])
        cur.close()
Esempio n. 24
0
def get_last_battle(username):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""SELECT lastbattle from users WHERE username = %s""", [username])
        last_battle = cur.fetchone()
        cur.close()
        return last_battle[0]
def get_item_value(id):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""SELECT value FROM items WHERE id = %s""", [id])
        value = cur.fetchone()
        cur.close()
        return value[0]
Esempio n. 26
0
def set_user_points(delta_user, delta):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            UPDATE users SET points = %s
                WHERE username = %s
            """, [delta, delta_user])
        cur.close()
Esempio n. 27
0
def reset_trade_timestamp(time):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            UPDATE userpokemon SET for_trade = 0, time_trade_set = NULL
                WHERE time_trade_set < %s
            """, [time])
        cur.close()
Esempio n. 28
0
def set_user_points(delta_user, delta):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            UPDATE users SET donation_points = %s, time_points = 0
                WHERE username = %s
            """, [delta, delta_user])
        cur.close()
Esempio n. 29
0
def update_nickname(nickname, username, position):
    con = get_connection()
    # TODO - error message on no entry
    with con:
        cur = con.cursor()
        cur.execute("""
            UPDATE userpokemon SET nickname = %s WHERE username = %s
                AND position = %s""", [nickname, username, position])
        cur.close()
def reset_trade_timestamp(time):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            UPDATE userpokemon SET for_trade = 0, time_trade_set = NULL
                WHERE time_trade_set < %s
            """, [time])
        cur.close()
def update_nickname(nickname, username, position):
    con = get_connection()
    # TODO - error message on no entry
    with con:
        cur = con.cursor()
        cur.execute("""
            UPDATE userpokemon SET nickname = %s WHERE username = %s
                AND position = %s""", [nickname, username, position])
        cur.close()
def modify_user_points(username, delta):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute(
            """INSERT INTO users (username, points)
                VALUES (%s, %s) ON DUPLICATE KEY
                UPDATE points = points + %s""", [username, delta, delta])
        cur.close()
def get_last_battle(username):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute(
            """SELECT lastbattle from users WHERE username = %s""", [username])
        last_battle = cur.fetchone()
        cur.close()
        return last_battle[0]
Esempio n. 34
0
def check_for_pokemon_for_sale():
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            SELECT userpokemon.username, pokemon.name, userpokemon.asking_price
                FROM pokemon
                LEFT JOIN userpokemon on userpokemon.pokemon_id = pokemon.id
                WHERE for_sale = 1 and pokemon.name = %s""", [pokemon_query])
        cur.close()
Esempio n. 35
0
def get_oauth(channel):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            SELECT twitch_oauth FROM auth WHERE channel = %s
        """, [channel])
        oauth = cur.fetchone()
        cur.close()
        return oauth
Esempio n. 36
0
def check_items():
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            SELECT id, name, value FROM items WHERE id IN (1,2,3,4,5,11)
            """)
        for_sale = cur.fetchall()
        cur.close()
        return for_sale
def get_pokemon_id(username, position):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            SELECT userpokemon.pokemon_id WHERE username = %s and position = %s
        """, [username, position])
        pokemon_id = cur.fetchone()
        cur.close()
        return pokemon_id
def check_for_pokemon_for_sale():
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            SELECT userpokemon.username, pokemon.name, userpokemon.asking_price
                FROM pokemon
                LEFT JOIN userpokemon on userpokemon.pokemon_id = pokemon.id
                WHERE for_sale = 1 and pokemon.name = %s""", [pokemon_query])
        cur.close()
Esempio n. 39
0
def modify_user_points(username, delta):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute(
            """INSERT INTO users (username, points)
                VALUES (%s, %s) ON DUPLICATE KEY
                UPDATE points = points + %s""", [
                username, delta, delta])
        cur.close()
Esempio n. 40
0
def get_pokemon_id(username, position):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            SELECT userpokemon.pokemon_id WHERE username = %s and position = %s
        """, [username, position])
        pokemon_id = cur.fetchone()
        cur.close()
        return pokemon_id
def get_defender_multiplier(attacker_type, defender_type):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""SELECT * from types WHERE id = %s""", [defender_type])
        defender_multipliers = cur.fetchone()
        row_correction = attacker_type + 1
        defender_effect = defender_multipliers[row_correction]
        cur.close()
        return defender_effect
def check_items():
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            SELECT id, name, value FROM items WHERE id IN (1,2,3,4,5,11)
            """)
        for_sale = cur.fetchall()
        cur.close()
        return for_sale
Esempio n. 43
0
def get_defender_multiplier(attacker_type, defender_type):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""SELECT * from types WHERE id = %s""", [defender_type])
        defender_multipliers = cur.fetchone()
        row_correction = attacker_type + 1
        defender_effect = defender_multipliers[row_correction]
        cur.close()
        return defender_effect
Esempio n. 44
0
def modify_points_all_users_hack(points_to_increment=1):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            INSERT INTO users (username, points) VALUES (%s, %s)
                ON DUPLICATE KEY UPDATE points = points + """ +
                    str(points_to_increment), user)
        cur.close()
        return "success"
def update_asking_price(username):
    con = get_connection()
    asking_price = 4000
    with con:
        cur = con.cursor()
        cur.execute("""
            UPDATE userpokemon SET asking_price = %s
                WHERE username = %s AND position = %s""", [
                    asking_price, username, party_position])
        cur.close()
Esempio n. 46
0
def update_asking_price(username):
    con = get_connection()
    asking_price = 4000
    with con:
        cur = con.cursor()
        cur.execute("""
            UPDATE userpokemon SET asking_price = %s
                WHERE username = %s AND position = %s""", [
                    asking_price, username, party_position])
        cur.close()
Esempio n. 47
0
def increment_command_counter(channel, command):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            UPDATE custom_commands SET times_used = times_used + 1
                WHERE command = %s AND channel = %s
            """, [command, channel])
        elements = cur.fetchone()
        cur.close()
        return elements
Esempio n. 48
0
def get_custom_command(channel, command):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            SELECT channel, command FROM custom_commands
                WHERE command = %s AND channel = %s
            """, [command, channel])
        commands = cur.fetchall()
        cur.close()
        return commands
def get_user_battle_info(username):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            SELECT userpokemon.position, userpokemon.level
                FROM userpokemon WHERE username = %s
                ORDER BY userpokemon.position""", [username])
        party_members = cur.fetchall()
        cur.close()
        return party_members
def show_all_pokemon_for_sale():
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            SELECT userpokemon.username
                    AS 'Owner', pokemon.name, userpokemon.asking_price
                FROM userpokemon
                INNER JOIN pokemon ON pokemon.id = userpokemon.pokemon_id
                WHERE for_sale = 1;""")
        cur.close()
Esempio n. 51
0
def get_giver_trade_status(position, giver):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            SELECT asking_trade, asking_level FROM userpokemon
                WHERE username = %s AND position = %s
        """, [giver, position])
        trader_party = cur.fetchall()
        cur.close()
        return trader_party
def get_giver_trade_status(position, giver):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            SELECT asking_trade, asking_level FROM userpokemon
                WHERE username = %s AND position = %s
        """, [giver, position])
        trader_party = cur.fetchall()
        cur.close()
        return trader_party
Esempio n. 53
0
def show_user_pokemon_for_sale(username):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            SELECT userpokemon.username, pokemon.name, userpokemon.position
                FROM userpokemon
                INNER JOIN pokemon ON pokemon.id = userpokemon.pokemon_id
                WHERE for_sale = 1 AND username = %s""", [
                    username])
        cur.close()
def show_user_pokemon_for_sale(username):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            SELECT userpokemon.username, pokemon.name, userpokemon.position
                FROM userpokemon
                INNER JOIN pokemon ON pokemon.id = userpokemon.pokemon_id
                WHERE for_sale = 1 AND username = %s""", [
                    username])
        cur.close()
Esempio n. 55
0
def get_user_battle_info(username):
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            SELECT userpokemon.position, userpokemon.level
                FROM userpokemon WHERE username = %s
                ORDER BY userpokemon.position""", [username])
        party_members = cur.fetchall()
        cur.close()
        return party_members
Esempio n. 56
0
def show_all_pokemon_for_sale():
    con = get_connection()
    with con:
        cur = con.cursor()
        cur.execute("""
            SELECT userpokemon.username
                    AS 'Owner', pokemon.name, userpokemon.asking_price
                FROM userpokemon
                INNER JOIN pokemon ON pokemon.id = userpokemon.pokemon_id
                WHERE for_sale = 1;""")
        cur.close()
def get_market_listings():
    con = get_connection()
    cur = con.cursor()
    cur.execute("""
        SELECT pokemon_id, price FROM market
    """)
    listings = cur.fetchall()
    resp = " | ".join(
        [str(x + 1) + ") " + ", ".join(
            [get_pokemon_name_from_id(listings[x][0]), str(
                listings[x][1])]) for x in range(len(listings))])
    return resp