Skip to content
This repository has been archived by the owner on Jun 10, 2023. It is now read-only.

Commit

Permalink
cp add on rate
Browse files Browse the repository at this point in the history
  • Loading branch information
RealistikDash committed Oct 7, 2020
1 parent 7bccaa6 commit cd3c9a0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
21 changes: 21 additions & 0 deletions helpers/levelhelper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from helpers.generalhelper import dict_keys
from helpers.timehelper import get_timestamp
from helpers.crypthelper import hash_sha1
from helpers.userhelper import user_helper
from conn.mysql import myconn
from objects.levels import Level, Rating, DailyLevel
from config import user_config
Expand Down Expand Up @@ -263,11 +264,31 @@ async def upload_level(self, level : Level) -> int:

async def rate_level(self, rating : Rating) -> None:
"""Rates a level."""
# CP Calculation time
level = await self.get_level_obj(rating.level_id)
cp_diff = 0
# Mess i tell you.
if level.featured and not rating.featured:
cp_diff -= 1
if not level.featured and rating.featured:
cp_diff += 1
if level.epic and not rating.epic:
cp_diff -= 1
if not level.epic and rating.epic:
cp_diff += 1
if level.stars and not rating.stars:
cp_diff -= 1
if not level.stars and rating.stars:
logging.debug("Cp for star.")
cp_diff += 1
await user_helper.give_cp(level.account_id, cp_diff)

async with myconn.conn.cursor() as mycursor:
await mycursor.execute("UPDATE levels SET starStars = %s, starFeatured=%s,starEpic = %s, starCoins=%s,starDemonDiff=%s WHERE levelID = %s LIMIT 1", (
rating.stars, int(rating.featured), int(rating.epic), int(rating.verified_coins), rating.demon_diff, rating.level_id
))
await myconn.conn.commit()
await self._cache_level_obj(level.ID)

async def _daily_level_from_db(self) -> DailyLevel:
"""Gets daily level from database."""
Expand Down
2 changes: 1 addition & 1 deletion helpers/searchhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async def get_levels(self, search_filters : SearchQuery) -> QueryResponse:
levels = await self.search_engine.get_levels(search_filters)
return QueryResponse(
levels.total_results,
await level_helper.level_list_objs(levels)
await level_helper.level_list_objs(levels.results)
)

search_helper = SearchQueryFormatter()
8 changes: 8 additions & 0 deletions helpers/userhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,5 +300,13 @@ async def update_profile_settings(self, account_id : int, youtube : str, twitter
await myconn.conn.commit()

await self.recache_object(account_id) # May make this func just edit the current obj

async def give_cp(self, account_id : int, cp : int = 1):
"""Gives a user an amount of CP."""
logging.debug(f"{account_id} has gained {cp} CP")
async with myconn.conn.cursor() as mycursor:
await mycursor.execute("UPDATE users SET creatorPoints = creatorPoints + %s WHERE extID = %s LIMIT 1", (cp, account_id,))
await myconn.conn.commit()
await self.recache_object(account_id) # May make this func just edit the current obj

user_helper = UserHelper() # This has to be a common class.

0 comments on commit cd3c9a0

Please sign in to comment.