From b90f6d2b7f6850b16b33087b8387feac92e8fe63 Mon Sep 17 00:00:00 2001 From: Miko Jimenez Date: Thu, 23 Jul 2020 19:37:57 -0400 Subject: [PATCH 01/17] Delete settings.json --- init/settings.json | 53 ---------------------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 init/settings.json diff --git a/init/settings.json b/init/settings.json deleted file mode 100644 index 226884e..0000000 --- a/init/settings.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "adminUsr": [ - "*SELF*", - "DozenIncBOT", - "goldenninjadragon" - ], - "clock": { - "hour1": 3, - "hour2": 9 - }, - "codes": [ - "SENSATIONAL-CHOCHOLATE-PISTOLS", - "A7J-3LX-GZ1", - "1836-0322-0935" - ], - "commands": { - "allowBotBroadcast": 1, - "allowSwitchTeam": 1, - "addRequests": 3, - "addRequestsOn": 1, - "burnAfter": 7, - "burnQuietly": 3, - "escapeHit": 1, - "maxRequests": 3, - "reviveAfter": 1, - "unlockBurn": 2, - "unlockInviteSwitch": 3, - "unlockLocate": 2, - "unlockRequest": 0, - "unlockRevive": 3, - "unlockVote": 1, - "useThreshold": 1, - "voteOneAfter": 11, - "voteThreshold": 2 - }, - "flairID": { - "alive": "", - "dead": "" - }, - "kickAfter": 8, - "reddit": { - "praw": "DozenIncBOT", - "sub": "SomethingsNotRight", - "targetPost": "hwq25z" - }, - "sql": { - "database": "Reddit", - "host": "127.0.0.1", - "password": "684239715", - "port": "3306", - "user": "root" - } -} From f58a15463c9b1e61ad1ef68b568ca886a64b5403 Mon Sep 17 00:00:00 2001 From: mikojimnz Date: Tue, 28 Jul 2020 04:10:33 -0400 Subject: [PATCH 02/17] Update info --- README.md | 2 +- init/statements.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 82c8085..783f679 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ All commands must be sent privately to u/DozenIncBOT. To use investigative comma |!vote USERNAME|Vote on who to eliminate. Can not be changed once voted per round.|2| |!digup USERNAME|Investigate the roles of other users. Has varying degree of reliability based on your tier|1| |!locate USERNAME|Shows the user's location. May give a clue as to what side they are on.|3| -|!convert USERNAME|Invite a user to switch to your team.|3| +|!convert USERNAME|Invite a user to switch to your team.|4| |!accept|Accept an invitation to switch teams.|1| |!unlock CODE|Enter a secret code in order to level up to the next tier.|1| |!stats|Gets the current stats for the game.|1| diff --git a/init/statements.json b/init/statements.json index 2d4cd9d..00e2694 100644 --- a/init/statements.json +++ b/init/statements.json @@ -295,7 +295,7 @@ "requestUser": "Your info request has been posted.", "reviveUser": "You have revived {}!", "revivedUser": "You have been revived by u/{}!\n\nGet back into the game and win!", - "showHelp": "List of available commands:\n* !burn: Exposes one of your teammates randomly for a 100% credible Intelligence Report. Can only be used once\n* !digup USERNAME: Gather intelligence on a user.\n* !help: Shows help.\n* !join: Join the game.\n* !leave: Leave the game. You cannot rejoin once the game has started.\n* !list: Show all players.\n* !locate USERNAME: Shows the location of the user.\n* !request USERNAME: Ask for intel on a player. Limited number of uses.\n* !rules: Shows the rules.\n* !revive USERNAME: Bring back one user back from the dead. Can only be used once.\n* !stats: Shows current number of players.\n* !unlock CODE: Enter a code to level up your rank and gain new investigative powers.\n* !vote USERNAME: Vote on which user to be eliminated.", + "showHelp": "List of available commands:\n* !burn: Exposes one of your teammates randomly for a 100% credible Intelligence Report. Can only be used once\n* !digup USERNAME: Gather intelligence on a user.\n* !help: Shows help.\n* !join: Join the game.\n* !leave: Leave the game. You cannot rejoin once the game has started.\n* !list: Show all players.\n* !locate USERNAME: Shows the location of the user.\n* !request USERNAME: Ask for intel on a player. Limited number of uses.\n* !rules: Shows the rules.\n* !revive USERNAME: Bring back one user back from the dead. Can only be used once.\n* !stats: Shows current number of players.\n* !unlock CODE: Enter a code to level up your rank and gain new investigative powers.\n* !vote USERNAME: Vote on which user to be eliminated.\n* !convert USERNAME: Invite a user to switch to your team.\n* !accept: Accept an invitation to switch teams.", "showRules": "Rules:\n1. Each user is assigned to either MI6 or the Twelve.\n2. You must investigate each other to determine who is on what side and eliminate the opponent.\n3. Decipher and decrypt the clues provided in order to advance your rank and unlock more powerful investigation tools.\n4. Vote out players who you suspect are the enemy. A player must receive a certain number of hits in order to be killed. After a certain amount of time, the number of votes required will be lowered to 1. Votes, aka hits, only last per round.\n4. At the end of each round, an announcement will be made how many people are alive how many were killed.\n5. You must choose your allies carefully to seek out the enemy.", "switchTeam": "Invitation Sent.\n\nYou may send another invitation next round.", "switchTeamAccept": "You have switched teams.", From 1d052b0903ebe593ebf143daa3b7e4c432eeac5f Mon Sep 17 00:00:00 2001 From: mikojimnz Date: Tue, 28 Jul 2020 04:29:05 -0400 Subject: [PATCH 03/17] Default praw.ini --- init/praw.ini | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 init/praw.ini diff --git a/init/praw.ini b/init/praw.ini new file mode 100644 index 0000000..8b4bc3a --- /dev/null +++ b/init/praw.ini @@ -0,0 +1,60 @@ +[DEFAULT] +# A boolean to indicate whether or not to check for package updates. +check_for_updates=True + +# Object to kind mappings +comment_kind=t1 +message_kind=t4 +redditor_kind=t2 +submission_kind=t3 +subreddit_kind=t5 +trophy_kind=t6 + +# The URL prefix for OAuth-related requests. +oauth_url=https://oauth.reddit.com + +# The amount of seconds to ratelimit +ratelimit_seconds=5 + +# The URL prefix for regular requests. +reddit_url=https://www.reddit.com + +# The URL prefix for short URLs. +short_url=https://redd.it + +# The timeout for requests to Reddit in number of seconds +timeout=16 + +[DEFAULT] +# A boolean to indicate whether or not to check for package updates. +check_for_updates=True + +# Object to kind mappings +comment_kind=t1 +message_kind=t4 +redditor_kind=t2 +submission_kind=t3 +subreddit_kind=t5 +trophy_kind=t6 + +# The URL prefix for OAuth-related requests. +oauth_url=https://oauth.reddit.com + +# The amount of seconds to ratelimit +ratelimit_seconds=5 + +# The URL prefix for regular requests. +reddit_url=https://www.reddit.com + +# The URL prefix for short URLs. +short_url=https://redd.it + +# The timeout for requests to Reddit in number of seconds +timeout=16 + +[Default] +client_id= +client_secret= +password= +username= +user_agent="OS:NAME:VERSION (by u/USERNAME)" From ee90770441075d5bc49146c77a37fc6992960fde Mon Sep 17 00:00:00 2001 From: mikojimnz Date: Wed, 29 Jul 2020 17:04:17 -0400 Subject: [PATCH 04/17] Keep sql connection alive when idle --- Mafia.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Mafia.py b/Mafia.py index a7442c0..ae9bda5 100644 --- a/Mafia.py +++ b/Mafia.py @@ -133,10 +133,16 @@ def wrapper(*args, **kwargs): return wrapper def schdWarn(min=00): + if (state != 1): + return -1 + reddit.submission(id=cfg['reddit']['targetPost']).reply(stm['comment']['actions']['schdWarn'].format(min)) print(f'Cycle Warning {min}') def autoCycle(): + if (state != 1): + return -1 + with open('data/save.json') as jsonFile2: sve = json.load(jsonFile2) curCycle = sve['curCycle'] @@ -165,6 +171,7 @@ def scheduleJobs(): schedule.every().day.at(f'{str(cfg["clock"]["hour2"] + 12).zfill(2)}:00').do(autoCycle) schedule.every(1).to(3).hours.do(makeComment) + schedule.every(4).hours.do(refreshConnection) print("Jobs Scheduled") @log_commit @@ -563,6 +570,9 @@ def showRules(): @log_commit def makeComment(): + if (state != 1): + return -1 + random.seed(time.time()) if (random.randint(0, 2) == 0): @@ -871,11 +881,16 @@ def sendMessage(name, message): reddit.redditor(name).message('Mafia', message) rateLimit() + def refreshConnection(): + con.execute('SHOW PROCESSLIST;') + conStat = con.fetchall() + print(f'Refreshed SQL Connection. {len(conStat)}') + con.execute(stm['preStm']['main'][0]) con.execute(stm['preStm']['main'][1], (time.time(),)) con.execute(stm['preStm']['addDummy']) con.execute('COMMIT;') - con.execute('SHOW PROCESSLIST') + con.execute('SHOW PROCESSLIST;') conStat = con.fetchall() scheduleJobs() @@ -887,8 +902,7 @@ def sendMessage(name, message): print('______') while True: - if (state == 1): - schedule.run_pending() + schedule.run_pending() try: for comment in commentStream: From 1ae8b34d2d8ce0d0dff49eb255ea484e8b748559 Mon Sep 17 00:00:00 2001 From: mikojimnz Date: Wed, 29 Jul 2020 23:10:21 -0400 Subject: [PATCH 05/17] Idle game messages --- Mafia.py | 6 ++++-- init/statements.json | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Mafia.py b/Mafia.py index ae9bda5..cff55c1 100644 --- a/Mafia.py +++ b/Mafia.py @@ -570,11 +570,13 @@ def showRules(): @log_commit def makeComment(): - if (state != 1): - return -1 random.seed(time.time()) + if (state == 0): + reddit.submission(id=cfg['reddit']['targetPost']).reply(stm['comment']['idle'][random.randint(0, len(stm['comment']['idle']) - 1)]) + return + if (random.randint(0, 2) == 0): con.execute(stm['preStm']['cycle']['getVotes']) r = con.fetchall() diff --git a/init/statements.json b/init/statements.json index 00e2694..26d70f1 100644 --- a/init/statements.json +++ b/init/statements.json @@ -19,6 +19,28 @@ "switchTeam": "A player has changed their allegiance!", "switchTeamInvite": "An offer was made to switch allegiances." }, + "idle": [ + "Join by PMing me !join.", + "Invite your friends!", + "Trust no one!", + "Read the tips and strategy guide!", + "Not too long now!", + "This is exciting!", + "Who will win this game?", + "Remeber to read the strategy guide!", + "Say hello!", + "Don't forget to introduce yourself!", + "Will it be MI6 or The Twelve?", + "Pro Tip: Use the !digup command multiple times.", + "Nothing is at it seems.", + "Teams will be assigned on game start!", + "Who will betray their own?", + "I have to kill some of you later.", + "You all look like bacon.", + "Players cannot join once the game starts! Join Now!", + "Remeber to use Private Messaging to send me commands.", + "You can team up with other players, but can you trust them?" + ], "spook": [ "Trust no one.", "There is darnkness in here.", From a7f4783ed225ea1c6e704a129027fa6dbe0d6449 Mon Sep 17 00:00:00 2001 From: mikojimnz Date: Thu, 30 Jul 2020 11:59:45 -0400 Subject: [PATCH 06/17] Minimize flair updates for alive players --- Mafia.py | 5 ++--- init/statements.json | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Mafia.py b/Mafia.py index cff55c1..47e6b46 100644 --- a/Mafia.py +++ b/Mafia.py @@ -212,7 +212,7 @@ def addUser(): con.execute(stm['preStm']['addUser'], (item.created_utc, item.author.name)) reddit.submission(id=cfg['reddit']['targetPost']).reply(stm['comment']['actions']['addUser'].format(item.author.name)) - sub.flair.set(item.author, text=stm['flairs']['alive'].format(1), flair_template_id=cfg['flairID']['alive']) + sub.flair.set(item.author, text=stm['flairs']['alive'], flair_template_id=cfg['flairID']['alive']) item.reply(stm['reply']['addUser'].format(item.author.name)) setItems(item.author.name, item) @@ -333,7 +333,7 @@ def reviveUser(): con.execute(stm['preStm']['revive'][2], (item.author.name,)) con.execute(stm['preStm']['revive'][3], (target,)) - sub.flair.set(reddit.redditor(target), text=stm['flairs']['alive'].format(curCycle + 1, flair_template_id=cfg['flairID']['alive'])) + sub.flair.set(reddit.redditor(target), text=stm['flairs']['alive'], flair_template_id=cfg['flairID']['alive']) sendMessage(target, stm['reply']['revivedUser'].format(item.author.name)) item.reply(stm['reply']['reviveUser'].format(target)) reddit.submission(id=cfg['reddit']['targetPost']).reply(stm['comment']['actions']['revive']) @@ -759,7 +759,6 @@ def cycle(curCycle): result = con.fetchall() for row in result: - sub.flair.set(reddit.redditor(row[0]), text=stm['flairs']['alive'].format(curCycle + 2), flair_template_id=cfg['flairID']['alive']) # sendMessage(row[0], stm['reply']['cycle'][1].format(curCycle + 2, alive, good, bad, killed, alive + killed)) sleep(0.2) diff --git a/init/statements.json b/init/statements.json index 26d70f1..c6803a5 100644 --- a/init/statements.json +++ b/init/statements.json @@ -157,7 +157,7 @@ "wrongCode": "Access Denied. Try Again." }, "flairs": { - "alive": "Mafia: Alive - Round {}", + "alive": "Mafia: Alive", "dead": "Mafia: {} on Round {}", "survived": "{}: Survived to Round {}" }, From 71dd61bb0e1842958781dd75a75faf9837a9256f Mon Sep 17 00:00:00 2001 From: mikojimnz Date: Thu, 30 Jul 2020 16:57:56 -0400 Subject: [PATCH 07/17] Adjust comment frequency, typo --- Mafia.py | 2 +- init/statements.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Mafia.py b/Mafia.py index 47e6b46..1005c0f 100644 --- a/Mafia.py +++ b/Mafia.py @@ -170,7 +170,7 @@ def scheduleJobs(): schedule.every().day.at(f'{str(cfg["clock"]["hour2"] - 1 + 12).zfill(2)}:55').do(schdWarn,min=5) schedule.every().day.at(f'{str(cfg["clock"]["hour2"] + 12).zfill(2)}:00').do(autoCycle) - schedule.every(1).to(3).hours.do(makeComment) + schedule.every(2).to(5).hours.do(makeComment) schedule.every(4).hours.do(refreshConnection) print("Jobs Scheduled") diff --git a/init/statements.json b/init/statements.json index c6803a5..bdc0620 100644 --- a/init/statements.json +++ b/init/statements.json @@ -32,7 +32,7 @@ "Don't forget to introduce yourself!", "Will it be MI6 or The Twelve?", "Pro Tip: Use the !digup command multiple times.", - "Nothing is at it seems.", + "Nothing is as it seems.", "Teams will be assigned on game start!", "Who will betray their own?", "I have to kill some of you later.", From 9d3e4adb8e62e2116a08ca71cf31a3f077303962 Mon Sep 17 00:00:00 2001 From: mikojimnz Date: Thu, 6 Aug 2020 21:14:23 -0400 Subject: [PATCH 08/17] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 783f679..122ba33 100644 --- a/README.md +++ b/README.md @@ -30,12 +30,12 @@ Play against other members to find out who amongst each other you can trust and |Team|Role|Tier|Description| |:-|:-|:-|:-| -|The Twelve|Trainee|1|Access to digup (low accuracy), vote, and max 3 requests.| -|The Twelve|Assassin|2|Digup accuracy increased.| +|The Twelve|Trainee|1|Access to digup (low accuracy) and max 3 requests.| +|The Twelve|Assassin|2|Vote unlocked, Digup accuracy increased.| |The Twelve|Handler|3|Digup accuracy increased. Unlocked locate and burn command (Tier 3 or lower). 3 Additional requests. Can escape hits.| |The Twelve|Keeper|4|Revive and convert unlocked. Burn does not announce who you are.| -|MI6|Recruit|1|Access to digup (low accuracy), vote, and max 3 requests.| -|MI6|Analyst|2|Digup accuracy increased.| +|MI6|Recruit|1|Access to digup (low accuracy) and max 3 requests.| +|MI6|Analyst|2|Vote unlocked, Digup accuracy increased.| |MI6|Operative|3|Digup accuracy increased. Unlocked locate and burn command (Tier 3 or lower). 3 Additional requests. Can escape hits.| |MI6|Supervisor|4|Revive and convert unlocked. Burn does not announce who you are.| From f255c4e2d9c49cd5a8650a8b276f076abfe644ca Mon Sep 17 00:00:00 2001 From: mikojimnz Date: Fri, 7 Aug 2020 21:12:18 -0400 Subject: [PATCH 09/17] Fix log action and autocycle check --- Mafia.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Mafia.py b/Mafia.py index 1005c0f..a880e38 100644 --- a/Mafia.py +++ b/Mafia.py @@ -61,7 +61,7 @@ def wrapper(*args, **kwargs): utc = item.created_utc result = func(*args, **kwargs) - pattern = re.search(r'^![\w]{1,}\s([\w\d_\-\s]+)', command) + pattern = re.search(r'^![\w]{1,}\s([\w\d_\-\s/]+)', command) readable = time.strftime('%m/%d/%Y %H:%M:%S', time.gmtime(utc)) action = '' @@ -673,7 +673,7 @@ def cycle(curCycle): item.reply(stm['err']['notStarted']) return -1 - if (item.author.name not in cfg['adminUsr']): + if ((item.author.name != None) and (item.author.name not in cfg['adminUsr'])): con.execute(stm['preStm']['log'], (item.created_utc, item.author.name, 'ATTEMPTED ADMIN COMMAND: cycle')) return -1 From 45f01e243e89ed57e15dd7b53f50fe9d2dbf57f2 Mon Sep 17 00:00:00 2001 From: mikojimnz Date: Sat, 8 Aug 2020 04:10:16 -0400 Subject: [PATCH 10/17] Fix autocycle check #2 --- Mafia.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mafia.py b/Mafia.py index a880e38..eb8bcb7 100644 --- a/Mafia.py +++ b/Mafia.py @@ -673,7 +673,7 @@ def cycle(curCycle): item.reply(stm['err']['notStarted']) return -1 - if ((item.author.name != None) and (item.author.name not in cfg['adminUsr'])): + if ((item.author.name is not None) and (item.author.name not in cfg['adminUsr'])): con.execute(stm['preStm']['log'], (item.created_utc, item.author.name, 'ATTEMPTED ADMIN COMMAND: cycle')) return -1 From d8062f19a3351f3728c41aab10c9c009ca0e513b Mon Sep 17 00:00:00 2001 From: mikojimnz Date: Sat, 8 Aug 2020 09:14:13 -0400 Subject: [PATCH 11/17] Fix autocycle check #3 --- Mafia.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Mafia.py b/Mafia.py index eb8bcb7..2dcb25c 100644 --- a/Mafia.py +++ b/Mafia.py @@ -673,9 +673,12 @@ def cycle(curCycle): item.reply(stm['err']['notStarted']) return -1 - if ((item.author.name is not None) and (item.author.name not in cfg['adminUsr'])): - con.execute(stm['preStm']['log'], (item.created_utc, item.author.name, 'ATTEMPTED ADMIN COMMAND: cycle')) - return -1 + if (item is None): + pass + else: + if (item.author.name not in cfg['adminUsr']): + con.execute(stm['preStm']['log'], (item.created_utc, item.author.name, 'ATTEMPTED ADMIN COMMAND: cycle')) + return -1 threshold = 1 @@ -766,7 +769,12 @@ def cycle(curCycle): con.execute('TRUNCATE TABLE TeamInvite;'); comment = reddit.submission(id=cfg['reddit']['targetPost']).reply(stm['sticky']['cycle'].format(curCycle + 2, alive, good, bad, killed, alive + killed)) comment.mod.distinguish(how='yes', sticky=True) - if (item != None): item.reply(f'**Moved to Round {curCycle + 2}**') + + if (item is None): + pass + else: + item.reply(f'**Moved to Round {curCycle + 2}**') + print(f'Moved to Round {curCycle + 1}') curCycle += 1 save(state, curCycle) From cdd6827d61c0c36f2eaec2d9b1f9520c9b509bff Mon Sep 17 00:00:00 2001 From: mikojimnz Date: Sat, 8 Aug 2020 13:21:37 -0400 Subject: [PATCH 12/17] Fixed incorrect digup grammar --- Mafia.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Mafia.py b/Mafia.py index 2dcb25c..561beb8 100644 --- a/Mafia.py +++ b/Mafia.py @@ -362,7 +362,7 @@ def digupUser(): role = stm['teams'][0][random.randint(0,maxTeams)] elif (tier == 1): if (random.randint(0,5) == 0): - role = stm['teams'][1][r[0][0]][r[0][1]] + role = stm['teams'][2][r[0][0]][r[0][1]] else: role = stm['teams'][2][random.randint(0,maxTeams)][random.randint(0,maxRoles)] elif (tier >= 2): @@ -774,7 +774,7 @@ def cycle(curCycle): pass else: item.reply(f'**Moved to Round {curCycle + 2}**') - + print(f'Moved to Round {curCycle + 1}') curCycle += 1 save(state, curCycle) From 667f424fe14712bb010ed57a90d6460ed4a93d63 Mon Sep 17 00:00:00 2001 From: Miko Jimenez Date: Sun, 9 Aug 2020 06:39:05 -0400 Subject: [PATCH 13/17] Dead players can use game commands --- init/statements.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init/statements.json b/init/statements.json index bdc0620..522daad 100644 --- a/init/statements.json +++ b/init/statements.json @@ -207,7 +207,7 @@ ], "chkBurn": "SELECT `username`,`team`,`tier` FROM Mafia WHERE (`username`=%s AND `burn`=1);", "chkCmt": "SELECT `username` FROM Mafia WHERE (`username`=%s AND `comment`>=%s);", - "chkUsr": "SELECT `username`,`team`,`tier` FROM Mafia WHERE (`username`=%s AND (`alive`=0 or `alive`=1));", + "chkUsr": "SELECT `username`,`team`,`tier` FROM Mafia WHERE (`username`=%s AND `alive`=1);", "chkUsrState": "SELECT `team`,`tier`,`loc`,`alive`,`burn`,`revive`,`request` From Mafia WHERE `username`=%s", "comment": "UPDATE Mafia SET `comment` = `comment` + 1 WHERE `username`=%s;", "cycle": { From 56c830252b156482aad9d2358f8c874d606993a4 Mon Sep 17 00:00:00 2001 From: mikojimnz Date: Sun, 9 Aug 2020 22:37:32 -0400 Subject: [PATCH 14/17] Fixed burn user selections --- Mafia.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Mafia.py b/Mafia.py index 561beb8..9291775 100644 --- a/Mafia.py +++ b/Mafia.py @@ -145,8 +145,8 @@ def autoCycle(): with open('data/save.json') as jsonFile2: sve = json.load(jsonFile2) - curCycle = sve['curCycle'] - cycle(curCycle) + + curCycle = cycle(sve['curCycle']) print(f'Auto Cycle {curCycle}') def scheduleJobs(): @@ -288,8 +288,12 @@ def burnUser(): item.reply(stm['err']['noBurnLeft']) return -1 - burned = toBurn[0][random.randint(0, len(toBurn) - 1)] - exposed = toReport[0][random.randint(0, len(toReport) - 1)] + print(toBurn) + print(toReport) + burned = toBurn[random.randint(0, len(toBurn) - 1)][0] + exposed = toReport[random.randint(0, len(toReport) - 1)][0] + print(burned) + print(exposed) deathMsg = random.randint(0,len(stm['deathMsg']) - 1) con.execute(stm['preStm']['burn'][4], (item.author.name,)) con.execute(stm['preStm']['burn'][5], (burned,)) From 02791d76f945f933f5e5e404d05085ae6b6bd2d9 Mon Sep 17 00:00:00 2001 From: mikojimnz Date: Sun, 9 Aug 2020 22:40:48 -0400 Subject: [PATCH 15/17] Removed debug prints --- Mafia.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Mafia.py b/Mafia.py index 9291775..54bb32d 100644 --- a/Mafia.py +++ b/Mafia.py @@ -288,12 +288,8 @@ def burnUser(): item.reply(stm['err']['noBurnLeft']) return -1 - print(toBurn) - print(toReport) burned = toBurn[random.randint(0, len(toBurn) - 1)][0] exposed = toReport[random.randint(0, len(toReport) - 1)][0] - print(burned) - print(exposed) deathMsg = random.randint(0,len(stm['deathMsg']) - 1) con.execute(stm['preStm']['burn'][4], (item.author.name,)) con.execute(stm['preStm']['burn'][5], (burned,)) From 43036a759d6c16595d3883abdc6063dbdc9421b0 Mon Sep 17 00:00:00 2001 From: mikojimnz Date: Sun, 9 Aug 2020 22:47:45 -0400 Subject: [PATCH 16/17] Typos --- init/statements.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init/statements.json b/init/statements.json index 522daad..686d83d 100644 --- a/init/statements.json +++ b/init/statements.json @@ -133,7 +133,7 @@ "err": { "alive": "The player is alive.", "alreadyStarted": "The game has already started.", - "burnUsed": "You have already used your abulity to burn.", + "burnUsed": "You have already used your ability to burn.", "impFmt": "Invalid command input.", "maxTier": "You have already reached the max tier available.", "noBurnLeft": "There is no one left to burn on your or the other's team.", @@ -145,7 +145,7 @@ "notPM": "Please enter commands through [private message](https://www.reddit.com/message/compose/?to=DozenIncBOT).", "notStarted": "The game has not started yet.", "notUnlocked": "Command not authorized!.\n\nCrack more game codes to unlock this command.", - "reviveUsed": "You have already used your abulity to revive.", + "reviveUsed": "You have already used your ability to revive.", "spec": "You are a spectator. You cannot use this command.", "switchTeam": "You already sent an invitation this round", "switchTeamBlocked": "Someone has already made an offer to that player this round.\n\nYou may try to convince them to reject their existing offer.", From 00fc4b01835fad47885545d617764788c4e055d5 Mon Sep 17 00:00:00 2001 From: mikojimnz Date: Tue, 22 Sep 2020 21:09:52 -0400 Subject: [PATCH 17/17] 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)):