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

Commit

Permalink
Merge branch 'rewrite' of https://github.com/RealistikDash/GDPyS into…
Browse files Browse the repository at this point in the history
… rewrite
  • Loading branch information
spookybear0 committed Oct 14, 2020
2 parents b4c36d5 + 277da14 commit 117d9b4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cron/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async def run_cron():
logging.debug(traceback.format_exc())
# So we dont gett 32846238746238ms or 0.0s
t_str = time_str(t)
logging.info(lang.info("CRON_FINISH", job.__name__, time_str))
logging.info(lang.info("CRON_FINISH", job.__name__, t_str))

# Don't copy paste code now watch me not follow my own advice. If I have to use this somewhere else, I will move this to timehelper.
t_str = time_str(total_t)
Expand Down
40 changes: 39 additions & 1 deletion helpers/userhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from helpers.timehelper import get_timestamp, Timer
from helpers.crypthelper import decode_base64, hash_bcrypt, encode_base64
from helpers.lang import lang
from objects.accounts import Account, AccountExtras
from objects.accounts import Account, AccountExtras, FriendRequest
from objects.comments import AccountComment
from conn.mysql import myconn
from constants import Permissions
Expand Down Expand Up @@ -309,5 +309,43 @@ async def give_cp(self, account_id : int, cp : int = 1):
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

async def get_friends(self, account_id : int) -> list:
"""Returns a list of account IDs that are friends with the user."""
async with myconn.conn.cursor() as mycursor:
await mycursor.execute("SELECT person1, person2 FROM friendships WHERE person1 = %s OR person2 = %s", (account_id, account_id))
friendships_db = await mycursor.fetchall()
friends = []
for friend in friendships_db:
# Messy but it just works :tm:
if friend[0] == account_id:
friends.append(friend[1])
else:
friends.append(friend[0])
return friends

async def get_friend_requests_to(self, account_id : int) -> list: # May add some pagination system directly to the sql for speed ig.
"""Returns a list of friendrequest objs to account_id passed."""
# TODO: split up when the from version of this function is added.
async with myconn.conn.cursor() as mycursor:
await mycursor.execute("SELECT accountID, toAccountID, comment, uploadDate, ID, isNew FROM friendreqs WHERE toAccountID = %s", (account_id,))
requests_db = await mycursor.fetchall()

requests = []

for req in requests_db:
requests.append( # How to trigger people 101
FriendRequest(
id = req[4],
account_id=req[0],
target_id=req[1],
content_base64=req[2],
content=decode_base64(req[2]), # To make them easier to work with outside the game.
timestamp=req[3],
new=bool(req[5])
)
)

return requests

user_helper = UserHelper() # This has to be a common class.
11 changes: 11 additions & 0 deletions objects/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,14 @@ class AccountExtras():
friend_requests : list
sent_requests : list
received_requests : list

@dataclass
class FriendRequest():
"""Dataclass storing friend request info."""
id : int
account_id : int
target_id : int
content_base64 : str
content : str
timestamp : int
new : bool

0 comments on commit 117d9b4

Please sign in to comment.