diff --git a/bots/game_threads/__init__.py b/bots/game_threads/__init__.py index 786f4d6..243c3cb 100644 --- a/bots/game_threads/__init__.py +++ b/bots/game_threads/__init__.py @@ -1478,7 +1478,27 @@ def gameday_thread_update_loop(self, todayGamePks): # Only sticky when posting the thread # if self.settings.get('Reddit',{}).get('STICKY',False): self.sticky_thread(gameDayThread) - if not gameDayThread: + # Check if post game thread is already posted, and skip game day thread if so + if sum(1 for k, v in self.activeGames.items() if k != 0 and v.get("postGameThread")) == len(self.activeGames) - 1: + # Post game thread is already posted for all games + self.log.info("Post game thread is already submitted for all games, but game day thread is not. Skipping game day thread...") + skipFlag = True + self.activeGames[pk].update({"STOP_FLAG": True}) + else: + # Check DB (record in pkThreads with gamePk and type='post' and gameDate=today) + pgq = "select * from {}threads where type='post' and gamePk in ({}) and gameDate = '{}' and deleted=0;".format( + self.dbTablePrefix, ",".join([str(x) for x in self.activeGames.keys() if x != pk]), self.today["Y-m-d"] + ) + pgThread = rbdb.db_qry(pgq, closeAfter=True, logg=self.log) + + if len(pgThread) == len(self.activeGames) - 1: + self.log.info( + "Post Game Thread found in database for all games, but game day thread not posted yet. Skipping game day thread.." + ) + skipFlag = True + self.activeGames[pk].update({"STOP_FLAG": True}) + + if not gameDayThread and not skipFlag: # Submit game day thread (gameDayThread, gameDayThreadText) = self.prep_and_post( "gameday", @@ -1705,7 +1725,7 @@ def gameday_thread_update_loop(self, todayGamePks): return # Mark game day thread as stale - if self.activeGames[pk]["gameDayThread"]: + if self.activeGames[pk].get("gameDayThread"): self.staleThreads.append(self.activeGames[pk]["gameDayThread"]) self.log.debug("Ending gameday update thread...") @@ -1765,6 +1785,27 @@ def game_thread_update_loop(self, pk): # if self.settings.get('Reddit',{}).get('STICKY',False): self.sticky_thread(self.activeGames[pk]['gameThread']) if not gameThread: + # Check if post game thread is already posted, and skip game thread if so + if self.activeGames[pk].get("postGameThread"): + # Post game thread is already known + self.log.info("Post game thread is already submitted, but game thread is not. Skipping game thread...") + skipFlag = True + self.activeGames[pk].update({"STOP_FLAG": True}) + else: + # Check DB (record in pkThreads with gamePk and type='post' and gameDate=today) + pgq = "select * from {}threads where type='post' and gamePk = {} and gameDate = '{}' and deleted=0;".format( + self.dbTablePrefix, pk, self.today["Y-m-d"] + ) + pgThread = rbdb.db_qry(pgq, closeAfter=True, logg=self.log) + + if len(pgThread) > 0: + self.log.info( + "Post Game Thread found in database, but game thread not posted yet. Skipping game thread.." + ) + skipFlag = True + self.activeGames[pk].update({"STOP_FLAG": True}) + + if not gameThread and not skipFlag: # Determine time to post gameStart = self.commonData[pk]["gameTime"]["bot"] postBy = tzlocal.get_localzone().localize( diff --git a/redball/webserver.py b/redball/webserver.py index d4a2d14..12e5eb1 100644 --- a/redball/webserver.py +++ b/redball/webserver.py @@ -502,23 +502,24 @@ def bots(self, bot_id=None, *args, **kwargs): if isinstance(newBot.id, str): local_args.update({"errors": newBot.id, "errorcontainer_hide": ""}) else: - redball.BOTS.update({str(newBot.id): newBot}) - # Grant rw access to the bot creator - redball.LOGGED_IN_USERS[cherrypy.session.get("_cp_username")][ - "PRIVS" - ].append("rb_bot_{}_rw".format(newBot.id)) - q = ( - "UPDATE rb_users SET privileges = ? WHERE userid=?;", - ( - json.dumps( - redball.LOGGED_IN_USERS[ - cherrypy.session.get("_cp_username") - ]["PRIVS"] + if cherrypy.session.get("_cp_username") != "authOff": + redball.BOTS.update({str(newBot.id): newBot}) + # Grant rw access to the bot creator + redball.LOGGED_IN_USERS[cherrypy.session.get("_cp_username")][ + "PRIVS" + ].append("rb_bot_{}_rw".format(newBot.id)) + q = ( + "UPDATE rb_users SET privileges = ? WHERE userid=?;", + ( + json.dumps( + redball.LOGGED_IN_USERS[ + cherrypy.session.get("_cp_username") + ]["PRIVS"] + ), + cherrypy.session.get("_cp_username"), ), - cherrypy.session.get("_cp_username"), - ), - ) - database.db_qry(q, commit=True, closeAfter=True) + ) + database.db_qry(q, commit=True, closeAfter=True) elif kwargs.get("action") == "delete" and bot_id: if not user.check_privilege( cherrypy.session.get("_cp_username"),