Beispiel #1
0
        async def confirm(cmd: Union[commands.Context, discord.Interaction],
                          message: YagooMessage, twtUser: tweepy.User):
            """
            Asks for confirmation of following the Twitter account that was requested.
            
            Arguments
            ---
            cmd: Context or interaction from the invoked command.
            message: The message used to display the confirmation.
            twtUser: The Twitter account.
            """
            message.embed.title = f"Following {twtUser.name} to this channel"
            message.embed.description = "Do you want to follow this Twitter account?"
            message.addButton(1,
                              "cancel",
                              "Cancel",
                              style=discord.ButtonStyle.red)
            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 #2
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 #3
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 #4
0
    async def follow(cmd: Union[commands.Context, discord.Interaction],
                     bot: commands.Bot, accLink: str):
        db = await botdb.getDB(bot.pool)
        if not accLink:
            raise ValueError("No Twitter ID")

        if isinstance(cmd, commands.Context):
            message = YagooMessage(bot, cmd.author)
            message.msg = await cmd.send("Searching for the Twitter user...")
        else:
            message = YagooMessage(bot, cmd.user)
        twtHandle = await TwitterUtils.getScreenName(accLink)
        twtUser = await TwitterScrape.getUserDetails(twtHandle)

        message.embed.title = f"Following {twtUser.name} to this channel"
        message.embed.description = "Do you want to follow this Twitter account?"
        message.addButton(1, "cancel", "Cancel", style=discord.ButtonStyle.red)
        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)

        if result.buttonID == "confirm":
            await dbTools.serverGrab(bot, str(cmd.guild.id),
                                     str(cmd.channel.id), ("url", ), db)
            dbExist = await TwitterUtils.dbExists(twtUser.id_str, db)
            if not dbExist["status"]:
                await TwitterUtils.newAccount(twtUser, db)
            status = await TwitterUtils.followActions("add",
                                                      str(cmd.channel.id),
                                                      [twtUser.id_str],
                                                      db=db)
            TwitterPrompts.follow.displayResult(message, twtUser.screen_name,
                                                status)
            message.msg = await message.msg.edit(content=None,
                                                 embed=message.embed,
                                                 view=None)
            await removeMessage(cmd=cmd)
            return
        await removeMessage(message, cmd)
Beispiel #5
0
    async def confirm(cmd: Union[commands.Context, discord.Interaction],
                      message: YagooMessage):
        """
        Prompts the user if they want to refresh the channel's webhook.
        
        Arguments
        ---
        cmd: Context or interaction from the invoked command.
        message: The message used for the prompt.
        """
        message.embed.title = "Refreshing Channel Webhook"
        message.embed.description = "Are you sure you want to refresh this channel's webhook?"
        message.addButton(1, "no", "No", style=discord.ButtonStyle.red)
        message.addButton(1, "yes", "Yes", style=discord.ButtonStyle.green)

        if isinstance(cmd, commands.Context):
            return await message.legacyPost(cmd)
        return await message.post(cmd, True, True)
Beispiel #6
0
 async def test(self, interaction: discord.Interaction):
     await interaction.response.defer()
     message = YagooMessage(self.bot,
                            interaction.user,
                            "Subscribing to a VTuber",
                            "Pick the VTuber's affiliation:",
                            color=discord.Color.from_rgb(32, 34, 37))
     message.embed.add_field(
         name="Action",
         value=
         "Pick an entry in the list or use the buttons below for further actions."
     )
     selectOptions = []
     for i in range(1, 100):
         selectOptions.append(YagooSelectOption(str(i)))
     message.addSelect(selectOptions)
     message.addButton(3, "search", "Search for a VTuber")
     message.addButton(3, "all", "Subscribe to all VTubers")
     message.addButton(4, "cancel", "Cancel", style=discord.ButtonStyle.red)
     response = await message.post(interaction, True, True)
     print(vars(response))
     if response.selectValues:
         await message.msg.edit(
             content=f"You picked the option: `{response.selectValues[0]}`",
             embed=None,
             view=None)
     elif response.buttonID:
         await message.msg.edit(
             content=f"You picked the button: `{response.buttonID}`",
             embed=None,
             view=None)
     else:
         await message.msg.edit(content="The message timed out!",
                                embed=None,
                                view=None)
Beispiel #7
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 #8
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 #9
0
    async def ctgPicker(cmd: Union[commands.Context, discord.Interaction],
                        channels: dict, ctgMsg: YagooMessage):
        """
        Prompts the user for a VTuber's affiliation.
        
        Arguments
        ---
        ctx: Context or interaction from the executed command.
        channels: Data from `channels` in `dict` form, with `id` as the main key.
        ctgMsg: Message to be used as the prompt message.
        
        Returns
        ---
        A `dict` with:
        - status: `True` if the user picked a category, `False` if otherwise.
        - all: `True` if the user picks to subscribe to all VTubers.
        - search: `True` if the user picks to search for a VTuber.
        - category: Contains the name of the category, `None` if there is no category picked.
        """
        categories = await subPrompts.categoryPages(channels)

        ctgMsg.resetComponents()
        ctgMsg.embed.title = "Subscribing to a VTuber"
        ctgMsg.embed.description = "Pick the VTuber's affiliation:"
        ctgMsg.embed.add_field(
            name="Searching for a specific VTuber?",
            value="Add the VTuber's name after the `subscribe` command.",
            inline=False)
        ctgMsg.addSelect(categories,
                         placeholder="Select the VTuber's Affiliation")
        ctgMsg.addButton(2, "search", "Search for a VTuber", disabled=True)
        ctgMsg.addButton(2, "all", "Subscribe to all VTubers")
        ctgMsg.addButton(3, "cancel", "Cancel", style=discord.ButtonStyle.red)

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

        return response
Beispiel #10
0
 async def editMsg(message: YagooMessage, subTypes: dict):
     message.resetComponents()
     allSubs = True
     selected = False
     rowSort = {
         "livestream": 0,
         "milestone": 1,
         "premiere": 2,
         "twitter": 3
     }
     for subType in subTypes:
         if subTypes[subType]:
             message.addButton(rowSort[subType],
                               subType,
                               f"{subType.capitalize()} Notifications",
                               style=discord.ButtonStyle.green)
             allSubs = False
         else:
             message.addButton(rowSort[subType],
                               subType,
                               f"{subType.capitalize()} Notifications",
                               style=discord.ButtonStyle.grey)
             selected = True
     if not allSubs:
         message.addButton(4,
                           "cancel",
                           "Cancel",
                           style=discord.ButtonStyle.red)
         message.addButton(4, "select", "Select All")
         message.addButton(4,
                           "submit",
                           "Unsubscribe",
                           style=discord.ButtonStyle.green,
                           disabled=not selected)
     else:
         message.addButton(4,
                           "cancel",
                           "Cancel",
                           style=discord.ButtonStyle.red)
         message.addButton(4,
                           "select",
                           "Select None",
                           style=discord.ButtonStyle.grey)
         message.addButton(4,
                           "submit",
                           "Unsubscribe",
                           style=discord.ButtonStyle.green,
                           disabled=not selected)
Beispiel #11
0
 async def editMsg(subTypes: List[str], message: YagooMessage,
                   buttonStates: dict, subText: str, subID: str,
                   allowNone: bool):
     """Supplementary command to `subTypes.prompt`"""
     selected = False
     allTypes = True
     rowNum = 0
     for subType in subTypes:
         if buttonStates[subType]:
             message.addButton(rowNum,
                               subType,
                               f"{subType.capitalize()} Notifications",
                               style=discord.ButtonStyle.green)
             selected = True
         else:
             message.addButton(rowNum,
                               subType,
                               f"{subType.capitalize()} Notifications",
                               style=discord.ButtonStyle.red)
             allTypes = False
         rowNum += 1
     if allowNone:
         selected = True
     message.addButton(rowNum,
                       "cancel",
                       "Cancel",
                       style=discord.ButtonStyle.red)
     if not allTypes:
         message.addButton(rowNum,
                           "all",
                           "Select All",
                           style=discord.ButtonStyle.primary)
     else:
         message.addButton(rowNum,
                           "all",
                           "Select None",
                           style=discord.ButtonStyle.grey)
     message.addButton(rowNum,
                       subID,
                       subText,
                       style=discord.ButtonStyle.green,
                       disabled=not selected)
Beispiel #12
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)