Пример #1
0
async def simon(ctx):
    """
    Get the current Simon
    """
    simon_role = get(ctx.guild.roles, name=get_role("Simon"))

    if len(simon_role.members) == 0:
        await ctx.send("", embed=gen_embed("Current Simon", f"There are currently no users with the {simon_role.mention} role."))
    else:
        await ctx.send("", embed=gen_embed("Current Simon", ", ".join(map(str, simon_role.members))))
Пример #2
0
    async def gameover(self, ctx):
        """
        Remove all Simon Says roles
        """
        simon_role = get(ctx.guild.roles, name=get_role("Simon"))
        player_role = get(ctx.guild.roles, name=get_role("Player"))
        loser_role = get(ctx.guild.roles, name=get_role("Loser"))
        giveaway_role = get(ctx.guild.roles, name=get_role("Giveaways"))

        total_members = 0
        lines = []

        for member in simon_role.members:
            await member.remove_roles(simon_role, giveaway_role)
            total_members += 1
            lines.append(
                f"Removed {simon_role.mention} and {giveaway_role.mention} roles from {member}."
            )

        for role in [player_role, loser_role]:
            members = 0
            for member in role.members:
                await member.remove_roles(role)
                members += 1

            if members != 0:
                total_members += members
                lines.append(
                    f"Removed the {role.mention} role from {members} member(s)."
                )

        if total_members == 0:
            lines.append(f"There were no roles to remove.")

        await ctx.send("", embed=gen_embed("Game Over", "\n".join(lines)))
Пример #3
0
async def remaining(ctx):
    """
    Get the remaining Simon Says players
    """
    player_role = get(ctx.guild.roles, name=get_role("Player"))

    title = f"{len(player_role.members)} Player(s) Remaining"
    description = ', '.join(map(str, player_role.members))

    await ctx.send("", embed=gen_embed(title, description))
Пример #4
0
    async def winner(self, ctx, winner: Member):
        """
        Sets the last winner
        """
        winner_role = get(ctx.guild.roles, name=get_role("Winner"))

        for member in winner_role.members:
            await member.remove_roles(winner_role)

        await winner.add_roles(winner_role)
        await ctx.send("",
                       embed=gen_embed(f"Set {winner} as {winner_role.name}."))
Пример #5
0
    async def revive(self, ctx, *users: Member):
        """
        Revive users
        """
        player_role = get(ctx.guild.roles, name=get_role("Player"))
        loser_role = get(ctx.guild.roles, name=get_role("Loser"))

        for user in users:
            await user.remove_roles(loser_role)
            await user.add_roles(player_role)

        await ctx.send("", embed=gen_embed("Revived user(s)."))
Пример #6
0
async def setsimon(ctx, user: Member = None):
    """
    Set a user as Simon
    """
    if user == None:
        user = ctx.author

    simon_role = get(ctx.guild.roles, name=get_role("Simon"))
    player_role = get(ctx.guild.roles, name=get_role("Player"))
    loser_role = get(ctx.guild.roles, name=get_role("Loser"))
    giveaway_role = get(ctx.guild.roles, name=get_role("Giveaways"))

    await user.add_roles(simon_role, giveaway_role)
    await user.remove_roles(player_role, loser_role)

    await ctx.send("", embed=gen_embed("Updated Simon List", ", ".join(map(str, simon_role.members))))
Пример #7
0
    async def process_alert(self, data):
        if data['type'] == 'timeline':

            # Item created
            if data['TimelineEntry'][0]['state'] == 0:

                # New show
                if data['TimelineEntry'][0]['type'] == 2:

                    # Get tv show instance
                    show_key = int(data['TimelineEntry'][0]['itemID'])
                    show = plex.fetch_tv_show_item(show_key)
                    show_title = show.title

                    db.add_tv_show(show_key, show_title)

                    channel_id = getenv('PDB_NEW_SHOW_CHANNEL_ID')
                    if channel_id:

                        # Wait for metadata
                        stop = datetime.datetime.now() + datetime.timedelta(minutes=1)
                        while not show.summary and datetime.datetime.now() < stop:
                            await asyncio.sleep(5)
                            show = plex.fetch_tv_show_item(show_key)

                        # Extract summary from show
                        summary = show.summary

                        # Generate embed
                        embed = gen_embed(f'New Show - {show_title}', f"{show_title} has been added to the server!")

                        # If episode contains summary
                        if summary:
                            embed.add_field(name="Summary", value=summary, inline=False)

                        channel = self.bot.get_channel(int(channel_id))
                        await channel.send(embed=embed)

                # New episode
                elif data['TimelineEntry'][0]['type'] == 4:

                    # Get episode instance
                    episode_key = int(data['TimelineEntry'][0]['itemID'])
                    episode = plex.fetch_tv_show_item(episode_key)
                    
                    show_key = episode.grandparentRatingKey
                    subs = db.get_subscriptions_via_key(show_key)

                    # If show has subscribers
                    if subs:

                        # Wait for metadata
                        stop = datetime.datetime.now() + datetime.timedelta(minutes=1)
                        while (not episode.summary or episode.title == f"Episode {episode.index}") and datetime.datetime.now() < stop:
                            await asyncio.sleep(5)
                            episode = plex.fetch_tv_show_item(episode_key)

                        # Extract info from episode
                        show_title = episode.grandparentTitle
                        season_number = episode.seasonNumber
                        episode_number = episode.index
                        episode_title = episode.title
                        summary = episode.summary

                        # Generate embed
                        embed = gen_embed(f'Subscriptions - {show_title}',
                                          f"A new episode of {show_title} has been added to the server!")
                        embed.add_field(name="Title", value=episode_title)
                        embed.add_field(name="Season", value=season_number)
                        embed.add_field(name="Episode", value=episode_number)

                        # If episode contains summary
                        if summary:
                            embed.add_field(name="Summary", value=summary, inline=False)

                        # Send message to subscribed users
                        for sub in subs:
                            user = self.bot.get_user(sub[0])
                            await user.send(embed=embed)

            # Item deleted
            elif data['TimelineEntry'][0]['state'] == 9:

                # Show deleted
                if data['TimelineEntry'][0]['type'] == 2:
                    show_key = int(data['TimelineEntry'][0]['itemID'])
                    subs = db.get_subscriptions_via_key(show_key)

                    # If show has subscribers
                    if subs:
                        show_title = db.get_tv_show(show_key)[1]

                        # Generate embed
                        embed = gen_embed(f'Subscription Removed - {show_title}',
                                          f"Your subscription for {show_title} has been removed since the show has been"
                                          f" removed from the server.")

                        # Send message to subscribed users and remove subscription
                        for sub in subs:
                            discord_id = sub[0]

                            user = self.bot.get_user(discord_id)
                            db.unsubscribe(discord_id, show_key)
                            await user.send(embed=embed)

                    # Delete show from database
                    db.delete_tv_show(show_key)