예제 #1
0
def get_user(user_id: int):
    cursor = dbc.cursor()
    cursor.execute("select * from users where user_id = ? LIMIT 1",
                   (user_id, ))
    user = cursor.fetchone()

    if user:
        return row_to_dictionary(cursor, user)
예제 #2
0
def get_weeb_games():
    cursor = dbc.cursor()

    sql = """
        select message_id, weeb_status
        from joes_weeblist
    """

    cursor.execute(sql)
    games = cursor.fetchall()
    games = [row_to_dictionary(cursor, row) for row in games]
    return games
예제 #3
0
def get_game_platforms(id):
    cursor = dbc.cursor()

    sql = """
        select p.name
        from igdb_game_platforms as gp
        left join igdb_platforms as p on gp.platform_id = p.id
        where game_id = ?
    """

    cursor.execute(sql, (id, ))
    games = cursor.fetchall()
    games = [row_to_dictionary(cursor, row) for row in games]
    return games
예제 #4
0
def get_game_pitches(game_id):
    cursor = dbc.cursor()

    sql = """
        select gp.*, u.username, u.avatar_url
        from game_pitches as gp
        left join users as u on u.user_id = gp.user_id
        where gp.game_id = ?
        order by gp.pinned desc, gp.rowid
    """

    cursor.execute(sql, (game_id, ))
    pitches = cursor.fetchall()
    pitches = [row_to_dictionary(cursor, row) for row in pitches]
    return pitches
예제 #5
0
def can_vote_messages(user_id):
    cursor = dbc.cursor()

    sql = """
        select message_count
        from message_counts
        where user_id = ?
    """

    cursor.execute(sql, (user_id, ))

    count = cursor.fetchone()
    count = row_to_dictionary(cursor, count)
    if count:
        return count['message_count'] >= 100
예제 #6
0
def get_game(message_id, user_id=0):
    cursor = dbc.cursor()

    sql = """
        select gm.message_id as id, g.name, g.release_date, ifnull(g.summary,'') as summary , g.cover_url_big, u.can_vote
                ,case when gp.user_id is null then 1 else 0 end as can_pitch
        from discord_game_map as gm
        left join users as u on u.user_id = ?
        left join igdb_game as g on g.id = gm.game_id
        left join game_pitches_discord as gp on gp.message_id = ? and gp.user_id = u.user_id
        where gm.message_id = ?
    """

    cursor.execute(sql, (user_id, message_id, message_id))
    game = cursor.fetchone()
    return row_to_dictionary(cursor, game)
예제 #7
0
def get_game_voters(poll, game_id):
    cursor = dbc.cursor()

    sql = """
        select u.user_id, u.username, u.avatar_url
        from votes as v
        left join users as u on u.user_id = v.user_id
        where poll = ?
        and v.vote = 1
        and v.game_id = ?
        order by v.rowid
    """

    cursor.execute(sql, (poll, game_id))
    voters = cursor.fetchall()
    voters = [row_to_dictionary(cursor, row) for row in voters]
    return voters
예제 #8
0
def get_game_search(search_terms):
    cursor = dbc.cursor()

    search_terms = search_terms.replace(" ", "%")
    search_terms = f"%{search_terms}%"

    sql = """
        select id, name, cover_url, release_date
        from igdb_game
        where name_normal like ?
        LIMIT 50
    """

    cursor.execute(sql, (search_terms, ))
    games = cursor.fetchall()
    games = [row_to_dictionary(cursor, row) for row in games]
    return games
예제 #9
0
def get_game(game_id, user_id=0, poll=0):
    cursor = dbc.cursor()

    sql = """
        select id, name, cover_url_big, release_date, summary, v.vote, u.can_vote, b.block_level, b.reason,
            case when gp.user_id is null then 1 else 0 end as can_pitch
        from igdb_game as ig
        left join users as u on u.user_id = ?
        left join votes as v on v.game_id = ig.id and v.poll = ? and v.user_id = u.user_id
        left join blocked_games as b on b.game_id = ig.id and b.poll = ?
        left join game_pitches as gp on gp.game_id = ig.id and gp.user_id = u.user_id
        where ig.id = ?
    """

    cursor.execute(sql, (user_id, poll, poll, game_id))
    game = cursor.fetchone()
    return row_to_dictionary(cursor, game)
예제 #10
0
def get_latest_pitches():
    cursor = dbc.cursor()

    sql = """
        select cast(gp.message_id as text) as message_id, u.user_id,  gp.pitch, u.username, u.avatar_url, dm.game_name, ig.cover_url_big
        from game_pitches_discord as gp
        left join users as u on u.user_id = gp.user_id
        left join discord_game_map as dm on dm.message_id = gp.message_id
        left join igdb_game as ig on ig.id = dm.game_id
        where u.user_id <> 141021676040224768
        and gp.pinned <> 1
        order by gp.created_at desc
        limit 10
    """

    cursor.execute(sql)
    pitches = cursor.fetchall()
    pitches = [row_to_dictionary(cursor, row) for row in pitches]
    return pitches
예제 #11
0
async def calc_votes():
    cursor = dbc.cursor()

    sql = """
        select v.game_id, sum(vote) as votes, g.name
        from votes as v
        left join igdb_game as g on g.id = v.game_id
        left join blocked_games as b on b.game_id = g.id and b.poll = 0
        where v.poll = 0
        and b.block_level is null
        group by v.game_id
        having sum(vote) > 0
        order by sum(vote) desc
    """

    cursor.execute(sql)
    _votes = cursor.fetchall()
    _votes = [row_to_dictionary(cursor, row) for row in _votes]

    votes.data = _votes

    await send_votes()
예제 #12
0
def get_random_pitches():
    cursor = dbc.cursor()
    from app.discordbot import bot

    valid_message_ids = (str(id_) for id_ in bot.valid_message_ids)
    valid_message_ids = ",".join(valid_message_ids)

    sql = f"""
        select cast(gp.message_id as text) as message_id, u.user_id, gp.pitch, u.username, u.avatar_url, dm.game_name, ig.cover_url_big
        from game_pitches_discord as gp
        left join users as u on u.user_id = gp.user_id
        left join discord_game_map as dm on dm.message_id = gp.message_id
        left join igdb_game as ig on ig.id = dm.game_id
        where gp.message_id in ({valid_message_ids})
        and gp.pinned <> 1
        and ig.id < 690000
        order by random()
        limit 10
    """

    cursor.execute(sql)
    pitches = cursor.fetchall()
    pitches = [row_to_dictionary(cursor, row) for row in pitches]
    return pitches