Exemple #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):
    u = user

    if u["team"] != None:
        team = db.get_team(u["team"])
        if u["id"] == team["owner"]:
            await channel.send("As the team owner, you may not leave.")
        else:
            db.update_user(u["id"], "team", None)
            db.pull_team(u["team"], "members", u["id"])
            await channel.send("You have left " + team["name"] + "!")
            await bot.get_channel(config.LOGCHANNEL
                                  ).send("`Leave Team: " + u["name"] + " " +
                                         team["id"] + " " + str(guildid) + "`")
    else:
        await channel.send("You are not in a team!")
Exemple #2
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 len(args) > 1:
        u = user

        bio = ' '.join(args[1:])
        if len(bio) <= 250:
            db.update_user(u["id"], "bio", bio)
            await channel.send("Bio set!")
        else:
            await channel.send('Your bio is too long! (Over 250 characters)')
    else:
        await channel.send('You must specify a bio!')
Exemple #3
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 len(args) > 1:
        u = user

        if u["team"] != None:
            name = args[1].replace("@", "")
            if len(name) > 2 and len(name) < 17:
                if not name in db.teams.distinct('name'):
                    if u["xp"] >= 200:
                        team = db.get_team(u["team"])
                        db.inc_user(u["id"], "xp", -200)
                        db.update_team(u["team"], "id", name)
                        db.update_team(name, "name", name)
                        for m in team["members"]:
                            db.update_user(m, "team", name)

                        await channel.send("Team " + team["name"] +
                                           " has been renamed to " + name +
                                           "!")
                        await bot.get_channel(
                            config.LOGCHANNEL
                        ).send("`Rename Team: " + team["name"] + " " + name +
                               "`")
                    else:
                        await channel.send(
                            "You do not have enough tokens to rename your team! 200T needed!"
                        )
                else:
                    await channel.send("That team name is already taken!")
            else:
                await channel.send(
                    "The team name must be in between 3 and 16 characters long (and one word)!"
                )
        else:
            await channel.send("You do not own a team!")
    else:
        await channel.send("You must specify a team name!")
Exemple #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 len(args) > 1:
        u = user

        if u["team"] == None:
            name = args[1].replace("@", "")
            if len(name) > 2 and len(name) < 17:
                if not name in db.teams.distinct('name'):
                    if u["xp"] >= 800:
                        db.inc_user(u["id"], "xp", -800)
                        db.new_team(name, u["id"])
                        db.update_user(u["id"], "team", name)
                        await channel.send("Team " + name +
                                           " has been created by <@!" +
                                           str(u["id"]) + ">!")
                        await bot.get_channel(config.LOGCHANNEL
                                              ).send("`Create Team: " + name +
                                                     "`")
                    else:
                        await channel.send(
                            "You do not have enough tokens to create a team! 800T needed!"
                        )
                else:
                    await channel.send("That team name is already taken!")
            else:
                await channel.send(
                    "The team name must be in between 3 and 16 characters long (and one word)!"
                )
        else:
            await channel.send("You are already in a team! Leave it first.")
    else:
        await channel.send("You must specify a team name!")
Exemple #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):
    await channel.trigger_typing()
    if mentions:
        u1 = user

        u2 = db.get_member(mentions[0])

        if u2["team"] == u1["team"]:
            team = db.get_team(u1["team"])
            if team != None and team["owner"] == u1["id"]:
                db.pull_team(team["id"], "members", u2["id"])
                db.update_user(u2["id"], "team", None)
                await channel.send('<@!' + str(u2["id"]) +
                                   '>, you have been kicked from team ' +
                                   team["name"] + '!')
                await bot.get_channel(config.LOGCHANNEL
                                      ).send("`Kick Team: " + u2["name"] +
                                             " " + team["id"] + " " +
                                             str(guildid) + "`")
            else:
                await channel.send('You do not own a team!')
        else:
            await channel.send("That user isn't in your team!")
    else:
        await channel.send('You must mention another user!')
Exemple #6
0
async def on_member_update(before, after):
    user = db.get_member(after)
    if str(after) != user["name"]:
        db.update_user(user["id"], "name", str(after))
Exemple #7
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:
        u1 = user

        u2 = db.get_member(mentions[0])

        if u2["team"] == None:
            team = db.get_team(u1["team"])
            if team != None and team["owner"] == u1["id"]:
                if len(team["members"]) < config.MAXTEAMSIZE:
                    await channel.send(
                        str(mentions[0].mention) +
                        ", you are being invited to " + str(mem.mention) +
                        "'s team! Use `" + prefix + "join` to join or `" +
                        prefix + "decline` to decline the request!")
                    try:

                        def check(message):
                            return message.author == mentions[0] and (
                                message.content == prefix + 'join'
                                or message.content == prefix + 'decline')

                        resp = await bot.wait_for('message',
                                                  check=check,
                                                  timeout=50)
                        if resp.content == prefix + 'join':
                            team = db.get_team(u1["team"])
                            if len(team["members"]) < config.MAXTEAMSIZE:
                                await resp.channel.trigger_typing()
                                db.push_team(team["id"], "members", u2["id"])
                                db.update_user(u2["id"], "team", team["id"])
                                await resp.channel.send("<@!" + str(u2["id"]) +
                                                        "> has joined team " +
                                                        team["name"] + "!")
                                await bot.get_channel(
                                    config.LOGCHANNEL
                                ).send("`Join Team: " + u2["name"] + " " +
                                       team["id"] + " " + str(guildid) + "`")
                            else:
                                await resp.channel.send('That team is full!')
                        elif resp.content == prefix + 'decline':
                            await resp.channel.send(
                                'You have declined the request!')
                    except:
                        await channel.send("The request has timed out!")
                else:
                    await channel.send('Your team is full!')
            else:
                await channel.send('You do not own a team!')
        else:
            await channel.send('That user is already in a team!')
    else:
        await channel.send('You must mention another user!')
Exemple #8
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")