Beispiel #1
0
def team_from_message(command):
    newteam = games.team()
    roster = command.split("\n", 1)[1].split("\n")
    newteam.name = roster[0]  #first line is team name
    newteam.slogan = roster[1]  #second line is slogan
    for rosternum in range(2, len(roster) - 1):
        if roster[rosternum] != "":
            if len(roster[rosternum]) > 70:
                raise CommandError(
                    f"{roster[rosternum]} is too long, chief. 70 or less.")
            newteam.add_lineup(
                games.player(ono.get_stats(roster[rosternum].rstrip())))
    if len(roster[len(roster) - 1]) > 70:
        raise CommandError(
            f"{roster[len(roster)-1]} is too long, chief. 70 or less.")
    newteam.set_pitcher(
        games.player(ono.get_stats(
            roster[len(roster) - 1].rstrip())))  #last line is pitcher name

    if len(newteam.name) > 30:
        raise CommandError(
            "Team names have to be less than 30 characters! Try again.")
    elif len(newteam.slogan) > 100:
        raise CommandError(
            "We've given you 100 characters for the slogan. Discord puts limits on us and thus, we put limits on you. C'est la vie."
        )

    return newteam
Beispiel #2
0
async def on_reaction_add(reaction, user):
    if reaction.message in setupmessages.keys():
        game = setupmessages[reaction.message]
        try:
            if str(reaction.emoji) == "🔼" and not user == client.user:
                new_player = games.player(ono.get_stats(db.get_user_player(user)["name"]))
                game.teams["away"].add_lineup(new_player)
                await reaction.message.channel.send(f"{new_player} {new_player.star_string('batting_stars')} takes spot #{len(game.teams['away'].lineup)} on the away lineup.")
            elif str(reaction.emoji) == "🔽" and not user == client.user:
                new_player = games.player(ono.get_stats(db.get_user_player(user)["name"]))
                game.teams["home"].add_lineup(new_player)
                await reaction.message.channel.send(f"{new_player} {new_player.star_string('batting_stars')} takes spot #{len(game.teams['home'].lineup)} on the home lineup.")
        except:
            await reaction.message.channel.send(f"{user.display_name}, we can't find your idol. Maybe you don't have one yet?")
Beispiel #3
0
    async def execute(self, msg, command):
        if (command.startswith("meme")):
            meme = True
            command = command.split(" ", 1)[1]
        else:
            meme = False

        player_name = discord.utils.escape_mentions(command)
        if len(player_name) >= 70:
            await msg.channel.send(
                "That name is too long. Please keep it below 70 characters, for my sake and yours."
            )
            return
        try:
            player_json = ono.get_stats(player_name)
            db.designate_player(msg.author, json.loads(player_json))
            if not meme:
                await msg.channel.send(f"{player_name} is now your idol.")
            else:
                await msg.channel.send(
                    f"{player_name} is now {msg.author.display_name}'s idol.")
                await msg.channel.send(
                    f"Reply if {player_name} is your idol also.")
        except:
            await msg.channel.send("Something went wrong. Tell xvi.")
def get_real_players(num):
    names = []
    for i in range(0, num):
        names.append(random_real_player())
    players = {}
    for name in names:
        players[name] = json.loads(ono.get_stats(name))
    return players
Beispiel #5
0
    def add_taken(self, add_name, range="Sheet1!A", name_is_row=False):
        end_index = self.end_name_index()
        end_range = range + str(end_index + 1) + ":F"
        append_body = {"range": end_range}
        if name_is_row:
            append_body["values"] = [add_name]
        else:
            append_body["values"] = [self.player_row(ono.get_stats(add_name))]

        self.sheets.values().update(spreadsheetId=self.sheet_id,
                                    range=end_range,
                                    valueInputOption="RAW",
                                    body=append_body).execute()
Beispiel #6
0
    def add_available(self, add_name, range="Sheet1!A"):
        player_row, row_number = self.find_name(add_name)
        if player_row:
            self.remove_taken(add_name)
        else:
            player_row = self.player_row(ono.get_stats(add_name))
        old_index_start = self.available_names_index()
        self.slide_sheet(old_index_start + 1, 1)

        new_name_row = range + str(old_index_start) + ":F" + str(
            old_index_start)
        new_body = {"range": new_name_row, "values": [player_row]}
        self.sheets.values().update(spreadsheetId=self.sheet_id,
                                    range=new_name_row,
                                    valueInputOption="RAW",
                                    body=new_body).execute()
        return True
Beispiel #7
0
async def save_team_batch(message, command):
    newteam = games.team()
    #try:
    roster = command.split("\n", 1)[1].split("\n")
    newteam.name = roster[0]  #first line is team name
    newteam.slogan = roster[1]  #second line is slogan
    for rosternum in range(2, len(roster) - 1):
        if roster[rosternum] != "":
            if len(roster[rosternum]) > 70:
                await channel.send(
                    f"{roster[rosternum]} is too long, chief. 70 or less.")
                return
            newteam.add_lineup(
                games.player(ono.get_stats(roster[rosternum].rstrip())))
    if len(roster[len(roster) - 1]) > 70:
        await channel.send(
            f"{roster[len(roster)-1]} is too long, chief. 70 or less.")
        return
    newteam.set_pitcher(
        games.player(ono.get_stats(
            roster[len(roster) - 1].rstrip())))  #last line is pitcher name

    if len(newteam.name) > 30:
        await message.channel.send(
            "Team names have to be less than 30 characters! Try again.")
        return
    elif len(newteam.slogan) > 100:
        await message.channel.send(
            "We've given you 100 characters for the slogan. Discord puts limits on us and thus, we put limits on you. C'est la vie."
        )
        return

    await message.channel.send(embed=build_team_embed(newteam))
    checkmsg = await message.channel.send("Does this look good to you, boss?")
    await checkmsg.add_reaction("👍")
    await checkmsg.add_reaction("👎")

    def react_check(react, user):
        return user == message.author and react.message == checkmsg

    try:
        react, user = await client.wait_for('reaction_add',
                                            timeout=20.0,
                                            check=react_check)
        if react.emoji == "👍":
            await message.channel.send("You got it, chief. Saving now.")
            games.save_team(newteam, message.author.id)
            await message.channel.send(
                "Saved! Thank you for flying Air Matteo. We hope you had a pleasant data entry."
            )
            return
        elif react.emoji == "👎":
            await message.channel.send(
                "Message received. Pumping brakes, turning this car around. Try again, chief."
            )
            return
    except asyncio.TimeoutError:
        await message.channel.send(
            "Look, I don't have all day. 20 seconds is long enough, right? Try again."
        )
        return
Beispiel #8
0
async def setup_game(channel, owner, newgame):
    newgame.owner = owner
    await channel.send(
        f"Game sucessfully created!\nStart any commands for this game with `{newgame.name}` so I know who's talking about what."
    )
    await asyncio.sleep(1)
    await channel.send("Who's pitching for the away team?")

    def input(msg):
        return msg.content.startswith(
            newgame.name
        ) and msg.channel == channel  #if author or willing participant and in correct channel

    while newgame.teams["home"].pitcher == None:

        def nameinput(msg):
            return msg.content.startswith(
                newgame.name
            ) and msg.channel == channel  #if author or willing participant and in correct channel

        while newgame.teams["away"].pitcher == None:
            try:
                namemsg = await client.wait_for('message', check=input)
                new_pitcher_name = discord.utils.escape_mentions(
                    namemsg.content.split(f"{newgame.name} ")[1])
                if len(new_pitcher_name) > 70:
                    await channel.send(
                        "That player name is too long, chief. 70 or less.")
                else:
                    new_pitcher = games.player(ono.get_stats(new_pitcher_name))
                    newgame.teams["away"].set_pitcher(new_pitcher)
                    await channel.send(
                        f"{new_pitcher} {new_pitcher.star_string('pitching_stars')}, pitching for the away team!\nNow, the home team's pitcher. Same dance, folks."
                    )
            except NameError:
                await channel.send("Uh.")

        try:
            namemsg = await client.wait_for('message', check=input)
            new_pitcher_name = discord.utils.escape_mentions(
                namemsg.content.split(f"{newgame.name} ")[1])
            if len(new_pitcher_name) > 70:
                await channel.send(
                    "That player name is too long, chief. 70 or less.")
            else:
                new_pitcher = games.player(ono.get_stats(new_pitcher_name))
                newgame.teams["home"].set_pitcher(new_pitcher)
                await channel.send(
                    f"And {new_pitcher} {new_pitcher.star_string('pitching_stars')}, pitching for the home team."
                )
        except:
            await channel.send("Uh.")

    #pitchers assigned!
    team_join_message = await channel.send(
        f"""Now, the lineups! I need somewhere between 1 and 12 batters. Cloning helps a lot with this sort of thing.
React to this message with 🔼 to have your idol join the away team, or 🔽 to have them join the home team.
You can also enter names like you did for the pitchers, with a slight difference: `away [name]` or `home [name]` instead of just the name.

Creator, type `{newgame.name} done` to finalize lineups.""")
    await team_join_message.add_reaction("🔼")
    await team_join_message.add_reaction("🔽")

    setupmessages[team_join_message] = newgame

    #emoji_task = asyncio.create_task(watch_for_reacts(team_join_message, ready, newgame))
    #msg_task = asyncio.create_task(watch_for_messages(channel, ready, newgame))
    #await asyncio.gather(
    #    watch_for_reacts(team_join_message, newgame),
    #    watch_for_messages(channel, newgame)
    #    )

    def messagecheck(msg):
        return (msg.content.startswith(newgame.name)
                ) and msg.channel == channel and msg.author != client.user

    while not newgame.ready:
        try:
            msg = await client.wait_for('message',
                                        timeout=120.0,
                                        check=messagecheck)
        except asyncio.TimeoutError:
            await channel.send(
                "Game timed out. 120 seconds between players is a bit much, see?"
            )
            del setupmessages[team_join_message]
            del newgame
            return

        new_player = None
        if msg.author == newgame.owner and msg.content == f"{newgame.name} done":
            if newgame.teams['home'].finalize(
            ) and newgame.teams['away'].finalize():
                newgame.ready = True
                break
        else:
            side = None
            if msg.content.split(f"{newgame.name} ")[1].split(" ",
                                                              1)[0] == "home":
                side = "home"
            elif msg.content.split(f"{newgame.name} ")[1].split(
                    " ", 1)[0] == "away":
                side = "away"

            if side is not None:
                new_player_name = discord.utils.escape_mentions(
                    msg.content.split(f"{newgame.name} ")[1].split(" ", 1)[1])
                if len(new_player_name) > 70:
                    await channel.send(
                        "That player name is too long, chief. 70 or less.")
                else:
                    new_player = games.player(ono.get_stats(new_player_name))
        try:
            if new_player is not None:
                newgame.teams[side].add_lineup(new_player)
                await channel.send(
                    f"{new_player} {new_player.star_string('batting_stars')} takes spot #{len(newgame.teams[side].lineup)} on the {side} lineup."
                )
        except:
            True

    del setupmessages[team_join_message]  #cleanup!

    await channel.send("Name the away team, creator.")

    def ownercheck(msg):
        return msg.author == newgame.owner

    while newgame.teams["home"].name == None:
        while newgame.teams["away"].name == None:
            newname = await client.wait_for('message', check=ownercheck)
            if len(newname.content) < 30:
                newgame.teams['away'].name = newname.content
                await channel.send(
                    f"Stepping onto the field, the visitors: {newname.content}!\nFinally, the home team, and we can begin."
                )
            else:
                await channel.send(
                    "Hey, keep these to 30 characters or less please. Discord messages have to stay short."
                )
        newname = await client.wait_for('message', check=ownercheck)
        if len(newname.content) < 30:
            newgame.teams['home'].name = newname.content
            await channel.send(
                f"Next on the diamond, your home team: {newname.content}!")
        else:
            await channel.send(
                "Hey, keep these to 30 characters or less please. Discord messages have to stay short."
            )

    await asyncio.sleep(3)
    await channel.send(
        f"**{newgame.teams['away'].name} at {newgame.teams['home'].name}**")

    game_task = asyncio.create_task(watch_game(channel, newgame))
    await game_task
Beispiel #9
0
 async def execute(self, msg, command):
     player_name = json.loads(ono.get_stats(command.split(" ", 1)[1]))
     await msg.channel.send(embed=build_star_embed(player_name))
async def on_message(msg):

    if msg.author == client.user:
        return

    command_b = False
    for prefix in config()["prefix"]:
        if msg.content.startswith(prefix):
            command_b = True
            command = msg.content.split(prefix, 1)[1]
    if not command_b:
        return

    if msg.author.id in config()["owners"] and command == "introduce":
        await introduce(msg.channel)

    elif msg.channel.id == config()["soulscream channel id"]:
        try:
            await msg.channel.send(ono.get_scream(msg.author.nick))
        except TypeError or AttributeError:
            await msg.channel.send(ono.get_scream(msg.author.name))
        except AttributeError:
            await msg.channel.send(ono.get_scream(msg.author.name))

    elif command.startswith("roman "):
        possible_int_string = command.split(" ", 1)[1]
        try:
            await msg.channel.send(roman.roman_convert(possible_int_string))
        except ValueError:
            await msg.channel.send(
                f"\"{possible_int_string}\" isn't an integer in Arabic numerals."
            )

    elif command.startswith("idolize"):
        if (command.startswith("idolizememe")):
            meme = True
        else:
            meme = False
        player_name = discord.utils.escape_mentions(command.split(" ", 1)[1])
        if len(player_name) >= 70:
            await msg.channel.send(
                "That name is too long. Please keep it below 70 characters, for my sake and yours."
            )
            return
        try:
            player_json = ono.get_stats(player_name)
            db.designate_player(msg.author, json.loads(player_json))
            if not meme:
                await msg.channel.send(f"{player_name} is now your idol.")
            else:
                await msg.channel.send(
                    f"{player_name} is now {msg.author.display_name}'s idol.")
                await msg.channel.send(
                    f"Reply if {player_name} is your idol also.")
        except:
            await msg.channel.send("Something went wrong. Tell xvi.")

    elif command == "showidol":
        try:
            player_json = db.get_user_player(msg.author)
            embed = build_star_embed(player_json)
            embed.set_footer(text=msg.author.display_name)
            await msg.channel.send(embed=embed)
        except:
            await msg.channel.send(
                "We can't find your idol. Looked everywhere, too.")

    elif command.startswith("showplayer "):
        player_name = json.loads(ono.get_stats(command.split(" ", 1)[1]))
        await msg.channel.send(embed=build_star_embed(player_name))

    elif command.startswith("startgame\n"):
        if len(gamesarray) > 45:
            await msg.channel.send(
                "We're running 45 games and we doubt Discord will be happy with any more. These edit requests don't come cheap."
            )
            return
        elif config()["game_freeze"]:
            await msg.channel.send(
                "Patch incoming. We're not allowing new games right now.")
            return

        try:
            team1 = games.get_team(command.split("\n")[1])
            team2 = games.get_team(command.split("\n")[2])
            innings = int(command.split("\n")[3])
        except IndexError:
            await msg.channel.send(
                "We need four lines: startgame, away team, home team, and the number of innings."
            )
            return
        except:
            await msg.channel.send(
                "Something about that command tripped us up. Either we couldn't find a team, or you gave us a bad number of innings."
            )
            return

        if innings < 2:
            await msg.channel.send(
                "Anything less than 2 innings isn't even an outing. Try again."
            )
            return

        elif innings > 30 and msg.author.id not in config()["owners"]:
            await msg.channel.send(
                "Y'all can't behave, so we've limited games to 30 innings. Ask xvi to start it with more if you really want to."
            )
            return

        if team1 is not None and team2 is not None:
            game = games.game(msg.author.name, team1, team2, length=innings)
            channel = msg.channel
            await msg.delete()
            game_task = asyncio.create_task(watch_game(channel, game))
            await game_task

    elif command.startswith("setupgame"):
        if len(gamesarray) > 45:
            await msg.channel.send(
                "We're running 45 games and we doubt Discord will be happy with any more. These edit requests don't come cheap."
            )
            return
        elif config()["game_freeze"]:
            await msg.channel.send(
                "Patch incoming. We're not allowing new games right now.")
            return

        for game in gamesarray:
            if game.name == msg.author.name:
                await msg.channel.send(
                    "You've already got a game in progress! Wait a tick, boss."
                )
                return
        try:
            inningmax = int(command.split("setupgame ")[1])
        except:
            inningmax = 3
        game_task = asyncio.create_task(
            setup_game(
                msg.channel, msg.author,
                games.game(msg.author.name,
                           games.team(),
                           games.team(),
                           length=inningmax)))
        await game_task

    elif command.startswith("saveteam\n"):
        if db.get_team(command.split("\n", 1)[1].split("\n")[0]) == None:
            save_task = asyncio.create_task(save_team_batch(msg, command))
            await save_task
        else:
            name = command.split('\n', 1)[1].split('\n')[0]
            await msg.channel.send(
                f"{name} already exists. Try a new name, maybe?")

    elif command.startswith("showteam "):
        team = games.get_team(command.split(" ", 1)[1])
        if team is not None:
            await msg.channel.send(embed=build_team_embed(team))
        else:
            await msg.channel.send("Can't find that team, boss. Typo?")

    elif command == ("showallteams"):
        list_task = asyncio.create_task(team_pages(msg, games.get_all_teams()))
        await list_task

    elif command.startswith("searchteams "):
        search_term = command.split("searchteams ", 1)[1]
        if len(search_term) > 30:
            await msg.channel.send(
                "Team names can't even be that long, chief. Try something shorter."
            )
            return
        list_task = asyncio.create_task(
            team_pages(msg,
                       games.search_team(search_term),
                       search_term=search_term))
        await list_task

    elif command == "credit":
        await msg.channel.send(
            "Our avatar was graciously provided to us, with permission, by @HetreaSky on Twitter."
        )

    elif command.startswith("help"):
        command_descriptions = {
            "idolize":
            ("m;idolize [name]",
             "Records any name as your idol, used elsewhere. There's a limit of 70 characters. That should be *plenty*."
             ),
            "showidol":
            ("m;showidol",
             "Displays your idol's name and stars in a nice discord embed."),
            "showplayer":
            ("m;showplayer [name]",
             "Displays any name's stars in a nice discord embed."),
            "setupgame":
            ("m;setupgame",
             "Begins setting up a 3-inning pickup game. Pitchers, lineups, and team names are given during the setup process by anyone able to type in that channel. Idols are easily signed up via emoji during the process. The game will start automatically after setup."
             ),
            "saveteam":
            ("m;saveteam",
             """To save an entire team, send this command at the top of a list, with lines seperated by newlines (shift+enter in discord, or copy+paste from notepad)
  - the first line of the list is your team's name (cannot contain emoji)
  - the second is your team's slogan
  - the rest of the lines are your players' names
  - the last player is designated your pitcher
if you did it correctly, you'll get a team embed with a prompt to confirm. Hit the 👍 and it'll be saved."""
             ),
            "showteam": ("m;showteam [name]",
                         "You can view any saved team with this command"),
            "showallteams":
            ("m;showallteams",
             "This displays a paginated list of all teams available for `startgame`"
             ),
            "searchteams":
            ("m;searchteams [searchterm]",
             "Displays paginated list of all teams whose names contain `searchterm`"
             ),
            "startgame":
            ("m;startgame",
             """To start a game with premade teams, use this command at the top of a list as above
  - the first line is the away team's name
  - the second is the home team's name
  - the third is the number of innings, which must be greater than 2."""),
            "credit": ("m;credit", "Shows artist credit for matteo's avatar."),
            "roman":
            ("m;roman [number]",
             "Converts any natural number less than 4,000,000 into roman numerals. This one is just for fun."
             ),
            "help":
            ("m;help [command]",
             "Displays a list of all commands, or the description of the given command if one is present."
             )
        }
        if command == "help":
            text = "Here's everything we know how to do; use `m;help [command]` for more info:"
            for name in command_descriptions:
                text += "\n  - {}".format(name)
        else:
            lookup = command[4:].strip()
            if lookup in command_descriptions:
                text = "`{}`:\n{}".format(command_descriptions[lookup][0],
                                          command_descriptions[lookup][1])
            else:
                text = "Can't find that command, boss; try checking the list with `m;help`."
        await msg.channel.send(text)

    elif command == "countactivegames" and msg.author.id in config()["owners"]:
        await msg.channel.send(
            f"There's {len(gamesarray)} active games right now, boss.")