Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
Fixed #26
Browse files Browse the repository at this point in the history
  • Loading branch information
mikojimnz committed Sep 23, 2020
1 parent 43036a7 commit 00fc4b0
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions Mafia.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -531,6 +549,8 @@ def getList():

@log_commit
def getStats():
global curCycle

team = 'The Spectators'
tier = 'Spectator'
loc = 'Nowhere'
Expand Down Expand Up @@ -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'])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)):
Expand Down Expand Up @@ -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)):
Expand Down

0 comments on commit 00fc4b0

Please sign in to comment.