Beispiel #1
0
        async def prompt(cmd: Union[commands.Context, discord.Interaction],
                         message: YagooMessage, followData: TwitterFollowData):
            """
            Prompts the user for which Twitter accounts to be unfollowed.
            
            Arguments
            ---
            cmd: Context or interaction from the invoked command.
            msg: The message that will be used as the prompt.
            options: The Discord channel's Twitter follows.
            
            Returns
            ---
            `TwitterUnfollowResponse`
            """
            response = TwitterUnfollowResponse(False)

            message.resetMessage()
            message.embed.title = "Unfollowing from Twitter Accounts"
            message.embed.description = "Choose the account(s) to be unfollowed."
            message.embed.add_field(
                name="Note seeing the Twitter account on this list?",
                value=
                "Twitter accounts followed through the `subscribe` command "
                "will need to be unfollowed through the `unsubscribe` command."
            )

            options = []
            for account in followData.accounts:
                options.append(
                    YagooSelectOption(account.name, account.accountID,
                                      f"@{account.handle}"))
            message.addSelect(options,
                              "Pick the Twitter account(s) here",
                              max_values=25)
            message.addButton(3, "all", "Unfollow from all Twitter Channels")
            message.addButton(4,
                              "cancel",
                              "Cancel",
                              style=discord.ButtonStyle.red)

            if isinstance(cmd, commands.Context):
                result = await message.legacyPost(cmd)
            else:
                result = await message.post(cmd, True, True)

            if result.responseType:
                if result.selectValues:
                    response.status = True
                    for handle in result.selectValues:
                        account = followData.findAccount(handle)
                        response.addAccount(account.accountID, account.handle,
                                            account.name)
                elif result.buttonID == "all":
                    response.status = True
                    response.allAccounts = True
            return response
Beispiel #2
0
        async def prompt(cmd: commands.Context, message: YagooMessage,
                         category: dict, catName: str):
            """
            Prompts the user for which VTuber to pick.
            
            Arguments
            ---
            cmd: Context or interaction from the invoked command.
            msg: The message that will be used as the prompt.
            category: The category as a `dict` containing `id` as the header, `name` as the sub-key.
            catName: The name of the category.
            
            Returns
            ---
            An instance of `CategorySubscriptionResponse`
            """
            options = await subPrompts.channelPick.parseToPages(category)

            message.resetMessage()
            message.embed.title = f"Subscribing to {catName} VTubers"
            message.embed.description = "Pick a VTuber in the select below."
            message.embed.add_field(
                name="Not finding a VTuber in this category?",
                value=
                "Search for a VTuber by adding the VTuber's name after the `subscribe` command."
            )
            message.addSelect(options,
                              f"Pick the {catName} VTubers here",
                              max_values=25)
            message.addButton(2, "all", f"Subscribe to all {catName} VTubers")
            message.addButton(3,
                              "cancel",
                              "Cancel",
                              style=discord.ButtonStyle.red)

            if isinstance(cmd, commands.Context):
                response = await message.legacyPost(cmd)
            else:
                response = await message.post(cmd, True, True)

            if response.responseType:
                if response.responseType == "select":
                    return CategorySubscriptionResponse(
                        True,
                        catName,
                        channelIDs=response.selectValues,
                        channelData=category)
                if response.buttonID == "all":
                    return CategorySubscriptionResponse(True, catName, True)
            return CategorySubscriptionResponse(False)
Beispiel #3
0
        async def prompt(cmd: Union[commands.Context, discord.Interaction],
                         message: YagooMessage, title: str, action: str):
            """
            Prompts to either confirm the choice of VTuber, cancel, or search for another VTuber.
            
            Arguments
            ---
            ctx: Context from the executed command.
            bot: The Discord bot.
            msg: The message that will be used for the prompt.
            title: The title of the prompt.
            
            Returns
            ---
            A `dict` with:
            - status: `True` if a user requested to search or confirms the choice.
            - action: The action that is requested by the user (`search`/`confirm`).
            """
            message.resetMessage()
            message.embed.title = title
            if action.lower() == "unsubscribe":
                message.embed.description = "Are you sure you want to unsubscribe from this channel?"
            else:
                message.embed.description = f"Are you sure you want to {action} to this channel?"
            message.addButton(1,
                              "cancel",
                              "Cancel",
                              style=discord.ButtonStyle.red)
            message.addButton(1,
                              "results",
                              "Search Results",
                              style=discord.ButtonStyle.primary)
            message.addButton(1,
                              "confirm",
                              "Confirm",
                              style=discord.ButtonStyle.green)

            if isinstance(cmd, commands.Context):
                result = await message.legacyPost(cmd)
            else:
                result = await message.post(cmd, True, True)

            return result
Beispiel #4
0
    async def searchPick(cmd: Union[commands.Context, discord.Interaction],
                         message: YagooMessage, searchTerm: str,
                         searchResult: ChannelSearchResponse):
        """
        A prompt to pick possible search matches.
        
        Arguments
        ---
        cmd: Context or interaction from the invoked command.
        message: The message that will be used as the prompt.
        searchTerm: The search term by the user.
        searchResult: The `ChannelSearchResult` returned from searching for a channel.
        
        Returns
        ---
        `ChannelSearchResult`
        """
        choices = []

        message.resetMessage()
        message.embed.title = "Searching for a VTuber"
        message.embed.description = f"Displaying search results for: `{searchTerm}`\n"
        for item in searchResult.searchResults:
            choices.append(YagooSelectOption(item, item))
        message.addSelect(choices, "Select the search result here")
        message.addButton(2, "cancel", "Cancel", style=discord.ButtonStyle.red)

        if isinstance(cmd, commands.Context):
            result = await message.legacyPost(cmd)
        else:
            result = await message.post(cmd, True, True)

        if not result.responseType or result.buttonID == "cancel":
            searchResult.failed()
            return searchResult

        searchResult.matched()
        searchResult.channelName = result.selectValues[0]
        return searchResult
Beispiel #5
0
async def unsubChannel(cmd: Union[commands.Context, discord.Interaction],
                       bot: commands.Bot,
                       channel: str = None):
    """
    Unsubscribes from a VTuber. (bypasses a prompt if a channel is given)
    
    Arguments
    ---
    ctx: Context or interaction from the invoked command.
    bot: The Discord bot.
    channel: The search term for the VTuber.
    """
    db = await botdb.getDB(bot.pool)
    if isinstance(cmd, commands.Context):
        message = YagooMessage(bot, cmd.author)
        message.msg = await cmd.send("Loading channel subscriptions...")
    else:
        message = YagooMessage(bot, cmd.user)
    server = await dbTools.serverGrab(bot, str(cmd.guild.id),
                                      str(cmd.channel.id),
                                      tuple(allSubTypes(False)), db)

    subData = await unsubUtils.parseToSubTypes(server, db)
    if not subData.exists:
        raise NoSubscriptions(cmd.channel.id)
    if not channel:
        message.resetMessage()
        message.embed.title = "Unsubscribing from VTuber Channels"
        message.embed.description = "Choose the VTuber(s) to be unsubscribed from."
        message.embed.add_field(
            name="Searching for a VTuber?",
            value="Enter the VTuber's name after the `unsubscribe` command.")
        message.addSelect(await unsubUtils.parseToPages(subData),
                          "Choose the VTuber(s) here",
                          max_values=25)
        message.addButton(2,
                          "search",
                          label="Search for a VTuber",
                          disabled=True)
        message.addButton(2, "all", "Unsubscribe from all VTubers")
        message.addButton(3, "cancel", "Cancel", style=discord.ButtonStyle.red)

        if isinstance(cmd, commands.Context):
            result = await message.legacyPost(cmd)
        else:
            result = await message.post(cmd, True, True)
    else:
        wikiName = await subUtils.channelSearch(cmd, bot, message, channel,
                                                "unsubscribe")
        if wikiName.success:
            result = YagooViewResponse()
            result.responseType = "select"
            result.selectValues = [wikiName.channelID]
        else:
            result = YagooViewResponse()

    if result.responseType:
        if result.buttonID == "all":
            unsubResult = await unsubPrompts.removePrompt.prompt(
                cmd, message, None, subData, True)
            if not unsubResult.status:
                return await removeMessage(message, cmd)
            await unsubUtils.unsubAll(str(cmd.channel.id), unsubResult, db)
        elif result.buttonID == "cancel":
            return await removeMessage(message, cmd)
        else:
            unsubResult = await unsubPrompts.removePrompt.prompt(
                cmd, message, result.selectValues, subData)
            if not unsubResult.status:
                return await removeMessage(message, cmd)
            await unsubUtils.unsubOne(server, str(cmd.channel.id), unsubResult,
                                      db)
        await unsubPrompts.displayResult(message, unsubResult)
        return await removeMessage(cmd=cmd)
    await removeMessage(message, cmd)