Skip to content

Commit

Permalink
FIX: GameDay and Game threads get posted when bot is restarted after …
Browse files Browse the repository at this point in the history
…game is postponed

FIX: Error when creating bot with AUTH_TYPE=None (see #13 for other known issues)
  • Loading branch information
toddrob99 committed Jul 31, 2020
1 parent ee210ac commit f29021b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 18 deletions.
45 changes: 43 additions & 2 deletions bots/game_threads/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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...")
Expand Down Expand Up @@ -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(
Expand Down
33 changes: 17 additions & 16 deletions redball/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit f29021b

Please sign in to comment.