def comment_ban(request): """Comment bans and returns an alert.""" #check if all args are not empty for a in ["date", "username", "reason"]: if request.form[a] == "": return (False, "All arguments must be filled.") #ok now we parse the date input type end_timestamp = time.mktime( datetime.strptime(request.form["date"], "%Y-%m-%d").timetuple()) if time.time() > end_timestamp: return (False, "That time is in the past!") #find the user mycursor.execute("SELECT accountID FROM accounts WHERE userName LIKE %s", (request.form["username"], )) account_id = mycursor.fetchone() if not account_id: return (False, "Could not find user!") account_id = account_id[0] #insert comment ban mycursor.execute( "INSERT INTO commentbans (accountID, endTimestamp, reason) VALUES (%s,%s,%s)", (account_id, end_timestamp, request.form["reason"])) mydb.commit() return (True, request.form["username"], TimeAgoFromNow(end_timestamp))
def SendMessage(self, Target: int, Body: str, Subject: str): """Sends a message from the bot.""" #first we base64 encode the body and subject Subject = base64.b64encode(Subject.encode()).decode("ascii") Body = base64.b64encode(Body.encode()).decode("ascii") Timestamp = round(time.time()) #and we create the message mycursor.execute( "INSERT INTO messages (accID, toAccountID, userName, userID, subject, body, timestamp, isNew) VALUES (%s, %s, 'GDPyS Bot', %s, %s, %s, %s, 0)", (self.BotID, Target, self.BotUserId, Subject, Body, Timestamp)) mydb.commit()
def _RegitsterBot(self, BotName="GDPySBot"): """Creates the bot account.""" Timestamp = round(time.time()) Password = CreateBcrypt( RandomString(16) ) #no one ever ever ever should access the bot account. if they do, you messed up big time mycursor.execute( "INSERT INTO accounts (userName, password, email, secret, saveData, registerDate, isBot) VALUES (%s, %s, '*****@*****.**', '', '', %s, 1)", (BotName, Password, Timestamp)) mydb.commit() #so the fetchid before works??? mycursor.execute( "INSERT INTO users (isRegistered, extID, userName, IP) VALUES (1, %s, %s, '1.1.1.1')", ( self._FetchID(), BotName, )) mydb.commit() Success(f"Created bot user ({BotName})!")
def change_password(post_data: dict, session: dict) -> dict: """Changes a user's password.""" if not session["LoggedIn"]: return False new_password = post_data["password"] prev_bcrypt = GetBcryptPassword(session["AccountID"]) old_password = post_data["oldpass"] if not CheckBcryptPw(prev_bcrypt, old_password): return False #change it here new_password = CreateBcrypt(new_password) mycursor.execute( "UPDATE accounts SET password = %s WHERE accountID = %s LIMIT 1", ( new_password, session["AccountID"], )) mydb.commit() return True
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")
def unban_user(self, user_id) -> None: """Unbans the user with the given userID""" cursor.execute("UPDATE users SET isBanned = 0 WHERE userID = %s LIMIT 1", (user_id,)) mydb.commit()
def ban_user(self, UserID): """Bans the user with the given userID.""" cursor.execute("UPDATE users SET isBanned = 1 WHERE userID = %s LIMIT 1", (UserID,)) mydb.commit()
def reupload_level_api(level_id: str, server: str, session): """[NOT RESTFUL] Reuploads a level from an external source.""" server = urllib.parse.unquote(server) #urldecode it if not HasPrivilege(session["AccountID"], ToolLevelReupload): return { "status": 403, "message": "You don't have sufficient privileges for this action!" } if glob.reuploaded_levels >= UserConfig["MaxReuploadedLevels24h"]: return { "status": 403, "message": "The limit for levels reuploaded a day has been reached!" } #fix link in case if server[-4:] != ".php": if server[-1] != "/": server += "/downloadGJLevel22.php" else: server += "/downloadGJLevel22.php" try: level_data = requests.post( server, { "gameVersion": 21, "binaryVersion": 35, "gdw": 0, "levelID": level_id, "secret": "Wmfd2893gb7", "inc": 1, "extras": 0 }).text except Exception: return {"status": 500, "message": "The request failed!"} if level_data in ["", "-1", "No no no"]: return { "status": 403, "message": "This server hates you." if not level_data == "-1" else "This level doesn't exist." } level = level_data.split("#")[0].split( ":") #remove the hashes and divide the level values ### OK THIS PART IS A PORT OF CVOLTONS LEVEL REUPLOAD AS IM TIRED AND NEED THIS QUICKLY ### DEADLINES, THEY SUCK # TODO: MAKE MY OWN def chk_array(src): return "0" if src == "" else src level_dict = {} for i in range(1, len(level) + 1): var = level[i - 1] if i % 2 == 0: level_dict[f"a{arg_num}"] = var else: arg_num = var #check if level isnt just total emptyness (a4 is level str) if level_dict["a4"] == "": return { "status": 500, "message": "There is something wrong with the level!" } timestamp = round(time.time()) level_string = chk_array(level_dict["a4"]) game_version = chk_array(level_dict["a13"]) if level_string[:2] == "eJ": level_string = level_string.replace("_", "/").replace("-", "+") level_string = zlib.decompress(level_string, zlib.MAX_WBITS | 32).decode() if game_version > 18: game_version = 18 mycursor.execute("SELECT COUNT(*) FROM levels WHERE originalReup = %s", (level_dict["a1"], )) if mycursor.fetchone()[0] != 0: return {"status": 403, "message": "This level already exists"} two_player = chk_array(level_dict["a31"]) song_id = chk_array(level_dict["a35"]) extra_str = chk_array(level_dict["a36"]) coins = chk_array(level_dict["a37"]) req_stars = chk_array(level_dict["a39"]) ldm = chk_array(level_dict["a40"]) password_unxor = chk_array(level_dict["a27"]) password = Xor(base64.b64decode(password_unxor.encode()).decode(), 26364) #this sql query is gonna make me cry... mycursor.execute( """ INSERT INTO levels ( levelName, gameVersion, binaryVersion, userName, levelDesc, levelVersion, levelLength, audioTrack, auto, password, original, twoPlayer, songID, objects, coins, requestedStars, extraString, levelString, levelInfo, uploadDate, updateDate, originalReup, userID, extID, unlisted, isLDM, secret, hostname ) VALUES ( #hey mysql also uses hashtags for comments neat %s, #levelname %s, #gameversion 27, #binary version 'GDPyS Bot', #username %s, #description %s, #level ver %s, # length %s, # audiotrack 0, # auto %s, #password %s, #original %s, #twoplayer %s, #songid 0, #objects %s, #coins %s, #requested stars %s, #extra string %s, #level string 0, #level info %s, #upload date %s, #update date %s, #orignal reup %s, #userID %s, #extID 0, #unlisted %s, #is ldm 'blah its reupload', 'MYSELF' #todo: change to users ip ) """, ( level_dict["a2"], #level name game_version, #game ver level_dict["a3"], #description level_dict["a5"], #level ver level_dict["a15"], #length level_dict["a12"], #audiotrack password, #password level_dict["a1"], #original two_player, #twoplayer song_id, #songid coins, #coins req_stars, #req stars extra_str, #extra string level_string, #level str timestamp, #upload date timestamp, #update date level_dict["a1"], #original reup Bot.BotUserId, #user id Bot.BotID, #ext od ldm #ldm )) mydb.commit() NewLevelID = mycursor.lastrowid #write level to file with open(f"./Data/Levels/{NewLevelID}", "w+") as File: File.write(level_string) File.close() ### POST REUPLOAD STUFF glob.reuploaded_levels += 1 #bump return { "status": 200, "levelID": NewLevelID, "percentage": levels_reuploaded_left() }