Example #1
0
async def main(args=None, command=None, bot=None, prefix=None, msg=None, message=None, guildid=None, guild=None, memid=None, mem=None, mentions=None, channel=None, user=None, game=None, gamedata=None, dbguild=None, msgcontent=None, ids=None):
    if mentions:
        try:
            g = db.get_game_recent(mentions[0].id)
        except:
            await channel.send(mentions[0].mention+" hasn't played any games!")
            return
        if g == None:
            await channel.send(mentions[0].mention+" hasn't played any games!")
            return
    else:
        if len(args) > 1:
            try:
                g = db.get_game_from_id(args[1])
            except:
                await channel.send("Invalid game id!")
                return
            if g == None:
                await channel.send("Game not found!")
                return
        else:
            try:
                g = db.get_game_recent(memid)
            except:
                await channel.send("You haven't played any games!")
                return
            if g == None:
                await channel.send("You haven't played any games!")
                return

    em = discord.Embed()
    em.title="Game "+str(g["_id"])
    em.colour = discord.Colour(config.COLOR)
    em.type = "rich"
    em.description = str(pgn_from_moves(g["moves"]))
    em.add_field(name="White",value=db.get_user(g["1"])["name"],inline=True)
    em.add_field(name="Black",value=db.get_user(g["2"])["name"],inline=True)
    if g["done"]:
        em.add_field(name="Outcome",value=g["outcome"].title(),inline=True)
    else:
        em.add_field(name="Outcome",value="Unfinished",inline=True)
    em.add_field(name="Completed",value=str(g["done"]),inline=True)
    if g["outcome"] in ["checkmate", "resign"]:
        em.add_field(name="Winner",value=db.get_user(g["winner"])["name"],inline=True)

    em.add_field(name="Timestamp",value=str(g["timestamp"].strftime('%m-%d-%Y %H:%M:%S')),inline=True)

    await channel.send(embed=em)
Example #2
0
def api_user(userid):
    try:
        user = db.get_user(userid)
        del user["_id"]
        return jsonify(user)
    except:
        return jsonify({'error': 'unknown'})
Example #3
0
def on_vote():
    print(request.headers)
    if request.headers.get('Authorization') == tok.WEBHOOKTOKEN:
        data = request.json

        try:
            user = int(data['user'])

        except Exception as E:
            return jsonify({'success': False})
        try:
            member = db.get_user(user)
            db.inc_user(user, "xp", 70)
            db.inc_user(user, "votes", 1)
            if "voter" not in member["badges"]:
                db.add_badge(user, "voter")
                config.send_message(
                    config.VOTECHANNEL, member["name"] +
                    " voted and got 70 tokens plus the voter badge!")
            else:
                config.send_message(
                    config.VOTECHANNEL,
                    member["name"] + " voted and got 70 tokens!")
        except Exception as E:
            pass

        return jsonify({'success': True})
    else:
        return jsonify({'success': False})
Example #4
0
async def main(args=None,
               command=None,
               bot=None,
               prefix=None,
               msg=None,
               message=None,
               guildid=None,
               guild=None,
               memid=None,
               mem=None,
               mentions=None,
               channel=None,
               user=None,
               game=None,
               gamedata=None,
               dbguild=None,
               msgcontent=None,
               ids=None):
    if mentions:
        gs = [i for i in db.get_games(mentions[0].id)]
        u = db.get_user(mentions[0].id)
        if gs == []:
            channel.send(mentions[0].mention + " hasn't played any games!")
            return

    else:
        gs = [i for i in db.get_games(memid)]
        u = user
        if gs == []:
            channel.send("You haven't played any games!")
            return

    em = discord.Embed()
    em.title = u["name"] + "'s games"
    em.colour = discord.Colour(config.COLOR)
    em.type = "rich"
    em.description = "Game ids sorted by time"
    for g in gs:
        em.add_field(name=str(g["_id"]),
                     value=db.get_user(g["1"])["name"] + " vs " +
                     db.get_user(g["2"])["name"])

    await channel.send(embed=em)
Example #5
0
async def main(args=None, command=None, bot=None, prefix=None, msg=None, message=None, guildid=None, guild=None, memid=None, mem=None, mentions=None, channel=None, user=None, game=None, gamedata=None, dbguild=None, msgcontent=None, ids=None):
	if args[0] == "hasbeat":

		if not len(message.raw_mentions)<2:
			try:
				user = db.get_user(message.raw_mentions[0])
				if message.raw_mentions[1] in user["unique"]:
					await channel.send("<@!"+str(message.raw_mentions[0])+"> **has** beat <@!"+str(message.raw_mentions[1])+">!")
				else:
					await channel.send("<@!"+str(message.raw_mentions[0])+"> **has not** beat <@!"+str(message.raw_mentions[1])+">!")
			except:
				await channel.send("<@!"+str(message.raw_mentions[0])+"> **has not** beat <@!"+str(message.raw_mentions[1])+">!")
		else:
			await channel.send("You must mention two people!")
Example #6
0
async def main(args=None,
               command=None,
               bot=None,
               prefix=None,
               msg=None,
               message=None,
               guildid=None,
               guild=None,
               memid=None,
               mem=None,
               mentions=None,
               channel=None,
               user=None,
               game=None,
               gamedata=None,
               dbguild=None,
               msgcontent=None,
               ids=None):
    if mentions:
        user = db.get_member(mentions[0])

        team = db.get_team(user["team"])
        if team == None:
            await channel.send(mentions[0].mention + " is not in a team!")

    else:
        if len(args) > 1:
            team = db.get_team(args[1])
            if team == None:
                await channel.send('Team not found!')
        else:
            user = user

            team = db.get_team(user["team"])
            if team == None:
                await channel.send("You are not in a team!")

    if team != None:
        em = discord.Embed()
        em.title = team["name"]
        if "image" in team:
            em.set_thumbnail(url=team["image"])
        else:
            em.set_thumbnail(
                url=
                "https://cdn4.iconfinder.com/data/icons/glyph-seo-icons/48/business-strategy-512.png"
            )
        em.colour = discord.Colour(4623620)
        em.type = "rich"
        if team["bio"] != None:
            em.description = team["bio"]
        em.add_field(name="Members",
                     value=', '.join(
                         [db.get_user(i)["name"] for i in team["members"]]),
                     inline=False)
        em.add_field(name="Owner",
                     value=db.get_user(team["owner"])["name"],
                     inline=True)
        em.add_field(name="Shards", value=team["cur"], inline=True)
        em.add_field(name="Wins", value=team["wins"], inline=True)
        em.add_field(name="Losses", value=team["loss"], inline=True)
        try:
            em.add_field(
                name="W/G",
                value=str(round(team["wins"] / team["games"], 2) * 100) + "%",
                inline=True)
        except:
            em.add_field(name="W/G", value="None", inline=True)

        em.add_field(name="Draws", value=team["draws"], inline=True)
        em.add_field(name="Games", value=team["games"], inline=True)

        await channel.send(embed=em)
Example #7
0
async def reward_game(winner, loser, outcome, gamedata, channel, bot):
    if gamedata["ranked"]:
        winner = db.get_user(winner)
        loser = db.get_user(loser)
        guildid = channel.guild.id

        if (outcome == "resign"
                and len(gamedata["moves"]) >= 10) or outcome == "checkmate":
            db.inc_user(winner["id"], "wins", 1)
            db.inc_user(loser["id"], "loss", 1)
            db.inc_user(winner["id"], "games", 1)
            db.inc_user(loser["id"], "games", 1)
            if loser["id"] not in winner["unique"]:
                db.push_user(winner["id"], "unique", loser["id"])
                db.inc_user(winner["id"], "xp", 150)
            else:
                db.inc_user(winner["id"], "xp", 50)

            new_elo = elo_rating(winner["elo"], loser["elo"], config.ELO_K)
            db.update_user(winner["id"], "elo", new_elo[0])
            db.update_user(loser["id"], "elo", new_elo[1])

            if winner["team"] != None and loser["team"] != None and winner[
                    "team"] != loser["team"]:
                lteam = db.get_team(loser["team"])
                mon = int(lteam["cur"] * 0.05)
                db.inc_team(winner["team"], "cur", mon)
                db.inc_team(loser["team"], "cur", -mon)
                db.inc_team(winner["team"], "games", 1)
                db.inc_team(loser["team"], "games", 1)
                db.inc_team(winner["team"], "wins", 1)
                db.inc_team(loser["team"], "loss", 1)

        if outcome == "checkmate":
            await channel.send("<@!" + str(winner["id"]) + "> " +
                               random.choice(config.WINMESSAGES) + " <@!" +
                               str(loser["id"]) + ">! Checkmate!")
            db.end_game(gamedata["_id"], winner["id"], loser["id"],
                        "checkmate")
            await bot.get_channel(config.LOGCHANNEL
                                  ).send("`Checkmate Game: " + winner["name"] +
                                         " " + loser["name"] + " " +
                                         str(guildid) + "`")

        if outcome == "resign":
            if len(gamedata["moves"]) >= 10:
                await channel.send("You have resigned! <@!" +
                                   str(winner["id"]) + "> wins!")
                db.end_game(gamedata["_id"], winner["id"], loser["id"],
                            "resign")
                await bot.get_channel(
                    config.LOGCHANNEL
                ).send("`Resign Game: " + winner["name"] + " " +
                       loser["name"] + " " + str(guildid) + "`")

            else:
                await channel.send("You have resigned!")
                await bot.get_channel(config.LOGCHANNEL
                                      ).send("`Exit Game: " + winner["name"] +
                                             " " + loser["name"] + " " +
                                             str(guildid) + "`")
                db.end_game(gamedata["_id"], None, None, "exit")

        if outcome == "draw" or outcome == "stalemate" or outcome == "accepteddraw":
            db.inc_user(winner["id"], "games", 1)
            db.inc_user(loser["id"], "games", 1)
            db.inc_user(winner["id"], "draws", 1)
            db.inc_user(loser["id"], "draws", 1)
            if outcome == "draw":
                await channel.send("Unable to Checkmate! The game is a draw!")
                db.end_game(gamedata["_id"], None, None, "draw")
            if outcome == "accepteddraw":
                await channel.send("Draw offer accepted! The game is a draw!")
                db.end_game(gamedata["_id"], None, None, "draw")
            if outcome == "stalemate":
                await channel.send("Stalemate! The game is a draw!")
                db.end_game(gamedata["_id"], None, None, "stalemate")

            if winner["team"] != None and loser["team"] != None and winner[
                    "team"] != loser["team"]:
                db.inc_team(winner["team"], "games", 1)
                db.inc_team(loser["team"], "games", 1)
                db.inc_team(winner["team"], "draws", 1)
                db.inc_team(loser["team"], "draws", 1)

        if outcome == "exit":
            await channel.send('You have exited the game!')
            db.end_game(gamedata["_id"], None, None, "exit")
            await bot.get_channel(config.LOGCHANNEL
                                  ).send("`Exit Game: " + str(guildid) + "`")

        if winner["wins"] == 2:
            if not "novice" in winner["badges"]:
                db.push_user(winner["id"], "badges", "novice")
                await channel.send(
                    "<@!" + str(winner["id"]) +
                    ">, congratulations! You have earned the Novice badge!")
        if winner["wins"] == 6:
            if not "expert" in winner["badges"]:
                db.push_user(winner["id"], "badges", "expert")
                await channel.send(
                    "<@!" + str(winner["id"]) +
                    ">, congratulations! You have earned the Expert badge!")
        if winner["wins"] == 14:
            if not "pro" in winner["badges"]:
                db.push_user(winner["id"], "badges", "pro")
                await channel.send(
                    "<@!" + str(winner["id"]) +
                    ">, congratulations! You have earned the Pro badge!")
        if winner["games"] == 24:
            if not "addicted" in winner["badges"]:
                db.push_user(winner["id"], "badges", "addicted")
                await channel.send(
                    "<@!" + str(winner["id"]) +
                    ">, congratulations! You have earned the Addicted badge!")
        if loser["games"] == 24:
            if not "addicted" in loser["badges"]:
                db.push_user(loser["id"], "badges", "addicted")
                await channel.send(
                    "<@!" + str(loser["id"]) +
                    ">, congratulations! You have earned the Addicted badge!")

        if loser["id"] == 206519445160460288:
            if not "beat-moca" in winner["badges"] and outcome in [
                    "resign", "checkmate"
            ]:
                db.push_user(winner["id"], "badges", "beat-moca")
                await channel.send(
                    "<@!" + str(winner["id"]) +
                    ">, congratulations! You have earned the Beat Moca badge!")

    else:
        await channel.send(
            "<@!" + str(loser["id"]) +
            ">, congratulations! You have earned the Addicted badge!")
        if outcome == "resign":
            await channel.send("You have resigned! The computer wins!")
            db.end_game(gamedata["_id"], "computer", loser, "resign")
        if outcome == "exit":
            await channel.send('You have exited the game!')
            db.end_game(gamedata["_id"], None, None, "exit")
        if outcome == "checkmate":
            if winner == "computer":
                await channel.send(winner + " " +
                                   random.choice(config.WINMESSAGES) + " <@!" +
                                   loser + ">! Checkmate!")
                db.end_game(gamedata["_id"], "computer", loser, "checkmate")
            else:
                await channel.send("<@!" + winner + "> " +
                                   random.choice(config.WINMESSAGES) + " " +
                                   loser + " Checkmate!")
                db.end_game(gamedata["_id"], winner, "computer", "checkmate")

        if outcome == "draw":
            await channel.send("Unable to Checkmate! The game is a draw!")
            db.end_game(gamedata["_id"], None, None, "draw")
        if outcome == "stalemate":
            await channel.send("Stalemate! The game is a draw!")
            db.end_game(gamedata["_id"], None, None, "stalemate")