From 00fc4b01835fad47885545d617764788c4e055d5 Mon Sep 17 00:00:00 2001 From: mikojimnz Date: Tue, 22 Sep 2020 21:09:52 -0400 Subject: [PATCH] Fixed #26 --- Mafia.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/Mafia.py b/Mafia.py index 54bb32d..b43ff7c 100644 --- a/Mafia.py +++ b/Mafia.py @@ -22,7 +22,15 @@ from random import randrange from time import sleep +exceptCnt = 0 +state = None +curCycle = None + def main(): + global exceptCnt + global state + global curCycle + with open('init/statements.json') as jsonFile1: stm = json.load(jsonFile1) with open('data/save.json') as jsonFile2: @@ -140,13 +148,15 @@ def schdWarn(min=00): print(f'Cycle Warning {min}') def autoCycle(): + global curCycle + if (state != 1): return -1 with open('data/save.json') as jsonFile2: sve = json.load(jsonFile2) - curCycle = cycle(sve['curCycle']) + cycle() print(f'Auto Cycle {curCycle}') def scheduleJobs(): @@ -176,6 +186,8 @@ def scheduleJobs(): @log_commit def gameState(state): + global curCycle + pattern = re.search(r'^!GAMESTATE\s([0-9]{1,1})(\s-[sS])?', item.body) setState = int(pattern.group(1)) silent = pattern.group(2) @@ -218,6 +230,8 @@ def addUser(): @log_commit def removeUser(): + global curCycle + con.execute(stm['preStm']['removeUser'], (curCycle, item.author.name)) reddit.submission(id=cfg['reddit']['targetPost']).reply(stm['comment']['actions']['removeUser'].format(item.author.name)) sub.flair.delete(item.author) @@ -226,6 +240,8 @@ def removeUser(): @log_commit @game_command def voteUser(): + global curCycle + con.execute(stm['preStm']['unlock'][0], (item.author.name,)) r = con.fetchall() @@ -258,6 +274,8 @@ def voteUser(): @log_commit @game_command def burnUser(): + global curCycle + con.execute(stm['preStm']['unlock'][0], (item.author.name,)) r = con.fetchall() @@ -531,6 +549,8 @@ def getList(): @log_commit def getStats(): + global curCycle + team = 'The Spectators' tier = 'Spectator' loc = 'Nowhere' @@ -615,6 +635,8 @@ def gameStart(): @log_commit def gameEnd(): + global curCycle + round = curCycle + 1 con.execute(stm['preStm']['cycle']['resetInactive']) con.execute(stm['preStm']['cycle']['incrementInactive']) @@ -668,7 +690,9 @@ def gameEnd(): comment.mod.distinguish(how='yes', sticky=True) @log_commit - def cycle(curCycle): + def cycle(): + global curCycle + if (state == 0): item.reply(stm['err']['notStarted']) return -1 @@ -942,6 +966,12 @@ def refreshConnection(): except: pass + with open('data/save.json') as jsonFile2: + sve = json.load(jsonFile2) + + state = sve['state'] + curCycle = sve['curCycle'] + if (re.search(r'^!join', item.body)): addUser() elif (re.search(r'^!leave', item.body)): @@ -975,7 +1005,7 @@ def refreshConnection(): elif (re.search(r'^!GAMESTATE', item.body)): state = gameState(state) elif (re.search(r'^!CYCLE', item.body)): - curCycle = cycle(curCycle) + curCycle = cycle() elif (re.search(r'^!BROADCAST', item.body)): broadcast() elif (re.search(r'^!RESTART', item.body)):