1
0
Fork 0
mirror of synced 2024-09-29 17:01:19 +13: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(): elif poll_id in server_polls.keys():
poll = server_polls[poll_id] 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() data = await response.json()
# The response for votes and options is provided as two separate lists # 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 re
import random import random
class Board: class Board:
def __init__(self, player1, player2): def __init__(self, player1, player2):
self.board = [[' ', ' ', ' '], [' ', ' ', ' '], [' ', ' ', ' ']] self.board = [[' ', ' ', ' '], [' ', ' ', ' '], [' ', ' ', ' ']]
@ -115,8 +116,7 @@ class TicTacToe:
# Return whoever is x's so that we know who is going first # Return whoever is x's so that we know who is going first
return self.boards[server_id].challengers['x'] return self.boards[server_id].challengers['x']
def update_records(self, winner, loser):
def update_records(winner, loser):
matches = config.get_content('tictactoe') matches = config.get_content('tictactoe')
if matches is None: if matches is None:
matches = {winner.id: "1-0", loser.id: "0-1"} matches = {winner.id: "1-0", loser.id: "0-1"}
@ -155,7 +155,7 @@ class TicTacToe:
matches[winner.id] = winner_stats matches[winner.id] = winner_stats
matches[loser.id] = loser_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) @commands.group(pass_context=True, aliases=['tic', 'tac', 'toe'], no_pm=True, invoke_without_command=True)
@checks.custom_perms(send_messages=True) @checks.custom_perms(send_messages=True)
@ -208,7 +208,6 @@ class TicTacToe:
elif (left or right) and not (top or bottom): elif (left or right) and not (top or bottom):
x = 1 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 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): if not board.update(x, y):
await self.bot.say("Someone has already played there!") await self.bot.say("Someone has already played there!")
@ -216,9 +215,10 @@ class TicTacToe:
winner = board.check() winner = board.check()
if winner: if winner:
loser = board.challengers['x'] if board.challengers['x'] != winner else board.challengers['o'] 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] del self.boards[ctx.message.server.id]
else: else:
if board.full(): if board.full():
@ -232,14 +232,16 @@ class TicTacToe:
async def start_game(self, ctx, player2: discord.Member): async def start_game(self, ctx, player2: discord.Member):
"""Starts a game of tictactoe with another player""" """Starts a game of tictactoe with another player"""
player1 = ctx.message.author 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!") await self.bot.say("Sorry but only one Tic-Tac-Toe game can be running per server!")
return return
x_player = self.create(ctx.message.server.id, player1, player2) 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 = "A tictactoe game has just started between {} and {}".format(player1.display_name, player2.display_name)
fmt += str(self.boards[ctx.message.server.id]) 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) await self.bot.say(fmt)
def setup(bot): def setup(bot):
bot.add_cog(TicTacToe(bot)) bot.add_cog(TicTacToe(bot))