예제 #1
0
def get_stats_candy(server):
    query = "SELECT a.id, name, emoji, chance, message, command, value " \
            "FROM STATS_CANDY a JOIN SETTINGS_CANDY b ON a.id = b.id " \
            "WHERE a.server = ? AND b.server = ?"
    rows = DB.execute(query, (server, server)).fetchall()
    return CandyCollection(
        *[CandyValue(Candy(*row[:-1]), row[-1]) for row in rows])
예제 #2
0
 def from_db(cls, rows):
     items = []
     for row in rows:
         role = row[0]
         candy = Candy(row[1], row[2], row[3], row[4])
         cost = CandyValue(candy, row[5])
         try:
             shop_item = next(x for x in items if x.item == role)
             shop_item.cost += cost
         except StopIteration:
             items.append(ShopItem(role, CandyCollection(cost)))
     return cls(items)
예제 #3
0
def get_inv(server, *users):
    # TODO: Why are we getting candy values we don't need? Also, improve this.
    query = "SELECT user, id, name, emoji, chance, message, command, value " \
            "FROM INV a JOIN SETTINGS_CANDY b ON a.candy = b.id " \
            "WHERE a.server = ? AND b.server = ?"
    if users:
        query += f" AND user IN ({', '.join('?' * len(users))})"
    rows = DB.execute(query, (server, server, *users)).fetchall()
    invs = defaultdict(CandyCollection)
    for row in rows:
        candy = Candy(*row[1:-1])
        candy_value = CandyValue(candy, row[-1])
        user = row[0]
        invs[user] += candy_value
    return invs
예제 #4
0
def get_candy(server):
    query = "SELECT id, name, emoji, chance, message, command FROM SETTINGS_CANDY WHERE server = ?"
    rows = DB.execute(query, (server, )).fetchall()
    return [Candy(*row) for row in rows]