def cache_ranks(cron_cursor): time = Timer() time.start() logger.info("Caching ranks... ") cron_cursor.execute("SELECT extID FROM users WHERE isBanned = 0 ORDER BY stars") Leaderboards = cron_cursor.fetchall() Leaderboards.reverse() Ranks.clear() UserRank = 0 for User in Leaderboards: UserRank += 1 Ranks[str(User[0])] = UserRank time.end() logger.info(f"Done! {time.ms_return()}ms")
def cache_comment_bans(cron_cursor): """Caches comment bans so a lookup doesn't have to be made.""" time = Timer() time.start() logger.info("Caching comment bans...") timestamp = round(pytime.time()) #so expired bans dont get cached cron_cursor.execute("SELECT accountID, endTimestamp, reason FROM commentbans WHERE endTimestamp > %s", (timestamp,)) comment_bans = cron_cursor.fetchall() CommentBanCache.clear() for ban in comment_bans: CommentBanCache[ban[0]] = { "end_time" : ban[1], "reason" : ban[2] } time.end() logger.info(f"Done with {len(comment_bans)} comment bans cached! {time.ms_return()}ms")
def cache_server_stats(cron_cursor): """Caches server statistics.""" time = Timer() time.start() logger.info("Caching server statictics...") cron_cursor.execute("SELECT COUNT(*) FROM accounts") ServerStatsCache["registered"] = cron_cursor.fetchone()[0] week_ago = round(pytime.time()) - 604800 cron_cursor.execute("SELECT COUNT(*) FROM accounts WHERE registerDate > %s", (week_ago,)) ServerStatsCache["registered_in_last_week"] = cron_cursor.fetchone()[0] cron_cursor.execute("SELECT COUNT(*) FROM levels WHERE uploadDate > %s", (week_ago,)) ServerStatsCache["levels_in_last_week"] = cron_cursor.fetchone()[0] time.end() logger.info(f"Done! {time.ms_return()}ms")
def max_star_count_ban(cron_cursor) -> None: """[CheatlessAC Cron] Bans people who have a star count higher than the total starcount of the server.""" # TODO : Make the same thing for usercoins and regular coins if UserConfig["CheatlessCronChecks"] and UserConfig["CheatlessAC"]: time = Timer() time.start() logger.info("Running CheatlessAC Cron Starcount Check... ") TotalStars = 187 #from RobTop levels #get all star rated levels cron_cursor.execute("SELECT starStars FROM levels WHERE starStars > 0") StarredLevels = cron_cursor.fetchall() #add em all up for Level in StarredLevels: TotalStars += Level[0] #count query cron_cursor.execute("SELECT COUNT(*) FROM users WHERE stars > %s", (TotalStars,)) BannedCount = cron_cursor.fetchone()[0] #ban em cron_cursor.execute("UPDATE users SET isBanned = 1 WHERE stars > %s", (TotalStars,)) mydb.commit() time.end() logger.info(f"Done with {BannedCount} users banned! {time.ms_return()}ms")
def calculate_cp(cron_cursor): """Cron job that calculates CP for the whole server.""" time = Timer() time.start() logger.info("Beginning to calculate CP... ") #Cronjob code cp_values = {} cron_cursor.execute("UPDATE users SET creatorPoints = 0") #set everyones cp to 0 as we wont be calculating everyone #now we get specific levels that match our criteria cron_cursor.execute("SELECT userID, starStars, starFeatured, starEpic, awarded, magic FROM levels WHERE starStars > 0 OR starFeatured > 0 OR starEpic > 0 OR awarded > 0 OR magic > 0") rated_levels = cron_cursor.fetchall() for level in rated_levels: if level[0] not in list(cp_values.keys()): cp_values[level[0]] = 0 cp_values[level[0]] += calc_cp_for_level(level) #finally apply calcs for cp in list(cp_values.keys()): cron_cursor.execute("UPDATE users SET creatorPoints = %s WHERE userID = %s LIMIT 1", (cp_values[cp], cp)) mydb.commit() time.end() logger.info(f"Done! {time.ms_return()}ms")