示例#1
0
async def stats(server: AbstractServer, msg: Message):
    warnMsg = False
    msgContent = msg.content.split(' ', 2)

    user = msgContent[1][3:-1]
    userName = msg.mentions[0]
    print(msgContent)
    if len(msgContent) > 1:
        validGametype = server.GetDatabase().hasGameType(msgContent[2])
        if not validGametype[0]:
            gameType = "any"
            warnMsg = True
        else:
            gameType = msgContent[2]
    else:
        gameType = "any"
    user: PapStats = server.GetDatabase().getStatsForUserInGuild(
        int(user), gameType)
    if warnMsg:
        await msg.channel.send(
            f"That is not a valid category. please look it up using command 'category'"
        )
    else:
        await msg.channel.send(
            f"{userName}'s rank in {user.gameType} is {user.rank}")
async def pprefix(server: AbstractServer, msg: Message):
    """ changes the personal prefix """
    prefix: str = msg.content[8:].strip()
    if len(prefix) > 4:
        await msg.channel.send(f'prefix too long! maximum lenght is 4.')
    elif len(prefix) == 0:
        await msg.channel.send(f'prefix too short! minimum lenght is 1.')
    else:
        server.secondaryPrefix[msg.author.id] = prefix
        user: '******' = server.GetDatabase().getUser(msg.author.id)
        user.personalPrefix = prefix
        server.GetDatabase().setUser(user)
        await msg.channel.send(f'personal prefix changed to "{prefix}"')
示例#3
0
async def ttt(server: AbstractServer, msg: Message):
	try:

		gameID = gameUtils.getRandomGameID([msg.author.id, msg.mentions[0].id] if msg.mentions else [msg.author.id, 0])
		player1 = msg.author
		player2 = None if not msg.mentions else msg.mentions[0]
		newGame = TicTacToe(player1=player1, player2=player2, data=None, gameID=gameID)

		if not msg.mentions:
			server.GetDatabase().initStatsForUserInGuild(msg.author.id, 'tic tac toe')
			live = 1

			server.GetDatabase().setGame(
				PapGame(
					gameID=gameID,
					gameType='tic tac toe',
					userIDs=[msg.author.id, msg.mentions[0].id] if msg.mentions else [msg.author.id, 0],
					gameData=newGame.getData(),
					live=live
				)
			)

			tttContent = f'This game is between {msg.author.mention} and our AI'

		else:
			if msg.mentions:
				server.GetDatabase().make.GameRequest(
					discordID=msg.author.id,
					discordID2=msg.mentions[0].id,
					channelID=msg.channel.id,
					gameID=gameID,
					gametype='tic tac toe'
				)

			tttContent = f'This game is between {msg.author.mention} and {msg.mentions[0].mention}.' \
						 ' Please wait until your opponent accept the game.'

		tttEmbed = embed(
			title='New tic tac toe Game.',
			content=tttContent,
			color=getColor(random=True)
		)
		await msg.channel.send(embed=tttEmbed)

	except GameRequestAlreadyLive:
		await msg.channel.send('GameRequestAlreadyLive')
示例#4
0
async def category(server: AbstractServer, msg: Message):
    allGameTypes = server.GetDatabase().getGameTypes()
    listEmbed = embed(title="Categories",
                      content="\n".join(gameType for gameType in allGameTypes),
                      color=getColor(RGB="255, 0, 0"))
    listEmbed.set_thumbnail(
        url=
        "https://lh3.googleusercontent.com/proxy/iGs72HNJCfm445aBtT8dxVquNExB5imv0ynMdO_QrdDOpo-kZaUmQ9_2Dp81W56uTZCOFuVTmnsd-SXtj6essFtzN7aXrnil_TfFpk_jqYwVQNLxWFGfKZCF59JC0A-5_p0kLF5_M4HxBioZpQ"
    )
    await msg.channel.send(embed=listEmbed)
示例#5
0
async def surrender(server: AbstractServer, msg: Message):
    resumeGame = server.GetDatabase().getLiveGameForUser(msg.author.id)[0]

    server.GetDatabase().setGame(
        PapGame(gameID=resumeGame.gameID,
                gameType=resumeGame.gameType,
                gameData=resumeGame.gameData,
                userIDs=resumeGame.userIDs,
                live=False))
    for userId in resumeGame.userIDs.split(','):
        if userId == msg.author.id:
            server.GetDatabase().saveStatsForUserInGuild(
                userID=userId, loss=True, gameType=resumeGame.gameType)
        else:
            server.GetDatabase().saveStatsForUserInGuild(
                userID=userId, win=True, gameType=resumeGame.gameType)

    await msg.channel.send("You surrendered the game. Stats are updated.")

    pass
示例#6
0
async def mystats(server: AbstractServer, msg: Message):
    warnMsg = False
    msgContent = msg.content.split(' ', 1)
    if len(msgContent) > 1:
        validGametype = server.GetDatabase().hasGameType(msgContent[1])
        if not validGametype[0]:
            gameType = "any"
            warnMsg = True
        else:
            gameType = msgContent[1]
    else:
        gameType = "any"
    user: PapStats = server.GetDatabase().getStatsForUserInGuild(
        msg.author.id, gameType)
    if warnMsg:
        await msg.channel.send(
            f"That is not a valid category. please look it up using command 'category'"
        )
    else:
        await msg.channel.send(f"Your rank in {user.gameType} is {user.rank}")
    async def onMessage(server: AbstractServer, msg: Message):

        database: AbstractGuild = server.GetDatabase()

        try:
            acceptObj: Dict[str, Any] = database.getGameRequest(msg.author.id)
            accepted: bool = None

            if (acceptObj['channelID'] == msg.channel.id) and ("accept"
                                                               in msg.content):
                accepted = True
                database.delGameRequest(msg.author.id, accepted)
            elif (acceptObj['channelID']
                  == msg.channel.id) and ("deny" in msg.content):
                accepted = False
                database.delGameRequest(msg.author.id, accepted)

            if accepted:
                acceptedEmbed = utils.embed(
                    title="Game accepted. Prepare",
                    content=
                    f"This game is between {msg.author.mention} and his opponent TODO: get actual names, ty",
                    color=utils.getColor(RGB="0,255,0"))
                await msg.channel.send(embed=acceptedEmbed)
                game = database.getGamesForUser(
                    msg.author.id, gameType=acceptObj['gameType'])[0]
                database.setGame(
                    PapGame(gameID=game.gameID,
                            gameType=game.gameType,
                            userIDs=game.userIDs,
                            gameData=game.gameData,
                            live=True))
            elif accepted is not None:
                deniedEmbed = utils.embed(title="Game denied.",
                                          content="This game is cancelled.",
                                          color=utils.getColor(RGB="255,0,0"))
                await msg.channel.send(embed=deniedEmbed)
        except GameRequestNotFound:
            pass
示例#8
0
async def draw(server: AbstractServer, msg: Message):
	try:
		gameData: PapGame = server.GetDatabase().getLiveGameForUserForGametype(
			discordID=msg.author.id,
			gameType="tic tac toe"
		)
		still_live = True

		resumeGame = TicTacToe(player1=None, player2=None, data=gameData, gameID=gameData.gameID)
		resumeGameID = gameData.gameID
		userIDs = gameData.userIDs

		if resumeGame.turn.user != msg.author.id:
			await msg.channel.send("Ehi bud it's not your turn yet")
		else:
			params = msg.content.split()
			pos = params[1]
			code = resumeGame.makeMove(pos)

			if code == 3:
				await msg.channel.send("That position is invalid, try again")
			elif code == 0:
				await msg.channel.send("The game is still going on")
			elif code == 1:
				await msg.channel.send(f"Congrats {msg.author.mention} you won")
				for userid in userIDs.split(','):
					if userid == msg.author.id:
						server.GetDatabase().saveStatsForUserInGuild(
							userID=str(userid),
							loss=True,
							gameType='tic tac toe')
					else:
						server.GetDatabase().saveStatsForUserInGuild(
							userID=str(userid),
							win=True,
							gameType='tic tac toe')
				still_live = False
			elif code == 10:
				await msg.channel.send("Sorry but you lost and our AI WON, ggs")
				server.GetDatabase().saveStatsForUserInGuild(
					userID=msg.author.id,
					loss=True,
					gameType='tic tac toe')
				still_live = False
			elif code == 100:
				await msg.channel.send("This is a tie")
				for userid in userIDs.split(','):
					server.GetDatabase().saveStatsForUserInGuild(
						userID=str(userid),
						tie=True,
						gameType='tic tac toe')
				still_live = False

			drawEmbed = embed(
				title="Tic Tac Toe",
				content="X: Player1 \tO: Player2",
				color=getColor(random=True)
			)
			file = File(
				f'{os.getcwd()}/modules/tic_tac_toe/src/tictactoe_images/{resumeGameID}.png',
				filename='test.png'
			)
			drawEmbed.set_image(url=f'attachment://test.png')
			# drawEmbed.add_field(name="game_status", value={'Still live' if still_live else 'Ended'}, inline=False)
			await msg.channel.send(file=file, embed=drawEmbed)
			updateGame = PapGame(
				gameData.gameID,
				[int(username) for username in (gameData.userIDs.replace(',', ' ').split(' '))],
				resumeGame.getData(),
				gameData.gameType,
				still_live
			)
			server.GetDatabase().setGame(
				updateGame
			)
	except GameNotFound:
		await msg.channel.send(f"There is no game for you bud.")
示例#9
0
async def c4stats(server: AbstractServer, msg: Message):
    
    user = server.GetDatabase().getStatsForUserInGuild(msg.author.id)

    await msg.channel.send(f'Stats for you: Wins {user[3]}. Losses {user[4]}.  Ties {user[5]}.')
async def savedata(server: AbstractServer, msg: Message):
    if msg.author.id in utils.getAuthors()():
        server.GetDatabase().db.save()
示例#11
0
async def viewgames(server: AbstractServer, msg: Message):
    server_games = server.GetDatabase().getLiveGamesForGuild()
    # EXPLANATION: This should result in a string, which puts al the "vs" stuff. Idk anymore
    output = '\n'.join(vs[2] for vs in server_games)
    await msg.channel.send(f"Current Games in this server: {output}")