1
0
Fork 0
mirror of synced 2024-06-27 18:50:35 +12:00

Corrected syntax errors

This commit is contained in:
phxntxm 2016-08-16 06:12:36 -05:00
parent f26e04b1a4
commit 8239d66524
2 changed files with 42 additions and 39 deletions

View file

@ -50,7 +50,8 @@ class Strawpoll:
elif poll_id in server_polls.keys():
poll = server_polls[poll_id]
async with self.session.get("{}/{}".format(self.url, poll_id), headers={'User-Agent': 'Bonfire/1.0.0') as response:
async with self.session.get("{}/{}".format(self.url, poll_id),
headers={'User-Agent': 'Bonfire/1.0.0'}) as response:
data = await response.json()
# The response for votes and options is provided as two separate lists

View file

@ -7,6 +7,7 @@ from .utils import checks
import re
import random
class Board:
def __init__(self, player1, player2):
self.board = [[' ', ' ', ' '], [' ', ' ', ' '], [' ', ' ', ' ']]
@ -115,8 +116,7 @@ class TicTacToe:
# Return whoever is x's so that we know who is going first
return self.boards[server_id].challengers['x']
def update_records(winner, loser):
def update_records(self, winner, loser):
matches = config.get_content('tictactoe')
if matches is None:
matches = {winner.id: "1-0", loser.id: "0-1"}
@ -155,7 +155,7 @@ class TicTacToe:
matches[winner.id] = winner_stats
matches[loser.id] = loser_stats
return config.save_content('tictactoe', battles)
return config.save_content('tictactoe', matches)
@commands.group(pass_context=True, aliases=['tic', 'tac', 'toe'], no_pm=True, invoke_without_command=True)
@checks.custom_perms(send_messages=True)
@ -208,7 +208,6 @@ class TicTacToe:
elif (left or right) and not (top or bottom):
x = 1
# If all checks have been made, x and y should now be defined correctly based on the matches, and we can go ahead and:
if not board.update(x, y):
await self.bot.say("Someone has already played there!")
@ -216,9 +215,10 @@ class TicTacToe:
winner = board.check()
if winner:
loser = board.challengers['x'] if board.challengers['x'] != winner else board.challengers['o']
await self.bot.say("{} has won this game of TicTacToe, better luck next time {}".format(winner.display_name, loser.display_name))
await self.bot.say("{} has won this game of TicTacToe, better luck next time {}".format(winner.display_name,
loser.display_name))
update_records(winner, loser)
self.update_records(winner, loser)
del self.boards[ctx.message.server.id]
else:
if board.full():
@ -232,14 +232,16 @@ class TicTacToe:
async def start_game(self, ctx, player2: discord.Member):
"""Starts a game of tictactoe with another player"""
player1 = ctx.message.author
if self.boards.get(ctx.message.server.id) != None:
if self.boards.get(ctx.message.server.id) is not None:
await self.bot.say("Sorry but only one Tic-Tac-Toe game can be running per server!")
return
x_player = self.create(ctx.message.server.id, player1, player2)
fmt = "A tictactoe game has just started between {} and {}".format(player1.display_name, player2.display_name)
fmt += str(self.boards[ctx.message.server.id])
fmt += "I have decided at random, and {} is going to be x's this game. It is your turn first!".format(x_player.display_name)
fmt += "I have decided at random, and {} is going to be x's this game. It is your turn first!".format(
x_player.display_name)
await self.bot.say(fmt)
def setup(bot):
bot.add_cog(TicTacToe(bot))