示例#1
0
async def refreshCommand(cmd: Union[commands.Context, discord.Interaction],
                         bot: commands.Bot):
    """
    Refreshes the channel's webhook on request.
    
    Arguments
    ---
    cmd: Context or interaction from the invoked command.
    bot: The Discord bot.
    """
    db = await botdb.getDB(bot.pool)
    if isinstance(cmd, commands.Context):
        message = YagooMessage(bot, cmd.author)
    else:
        message = YagooMessage(bot, cmd.user)

    result = await refreshPrompts.confirm(cmd, message)
    if result.responseType:
        if result.buttonID == "yes":
            await refreshWebhook(bot, cmd.guild, cmd.channel, db)
            message.resetEmbed()
            message.embed.title = "Successfully Refreshed!"
            message.embed.description = "The channel's webhook should now be refreshed. "\
                                        "Channel notifications will be posted after a short while."
            message.msg = await message.msg.edit(content=None,
                                                 embed=message.embed,
                                                 view=None)
            return
    await removeMessage(message, cmd)
示例#2
0
    async def displayResult(message: YagooMessage,
                            unsubData: UnsubscriptionResponse):
        """
        Displays the unsubscription result.
        
        message: The message used to display the result.
        unsubData: The unsubscription data.
        """
        subTypeText = ""
        channels = ""

        for subType in unsubData.subTypes:
            subTypeText += f"{subType.capitalize()}, "

        if len(unsubData.channels) <= 5:
            for channel in unsubData.channels:
                channels += f"{channel.channelName}, "
        else:
            channels = f"{len(unsubData.channels)} channels"

        message.resetEmbed()
        message.embed.title = "Successfully Unsubscribed!"
        message.embed.description = f"This channel is now unsubscribed from {channels.strip(', ')}."
        message.embed.color = discord.Color.green()
        message.embed.add_field(name="Subscription Types",
                                value=subTypeText.strip(", "),
                                inline=False)
        message.msg = await message.msg.edit(content=None,
                                             embed=message.embed,
                                             view=None)
        return
示例#3
0
 async def displaySubbed(message: YagooMessage,
                         subResult: SubscriptionResponse):
     """
     Gives a status to the user about subbed accounts.
     
     Arguments
     ---
     message: The message that will be used as the display.
     subResult: The `SubscriptionResponse` from the subscription prompts.
     """
     channels = ""
     message.resetEmbed()
     for name in subResult.channelNames:
         channels += f"{name}, "
     if subResult.subTypes:
         message.embed.title = "Successfully Subscribed!"
         message.embed.description = f"This channel is now subscribed to {channels.strip(', ')}."
         message.embed.color = discord.Colour.green()
         subTypes = ""
         for subType in subResult.subTypes:
             subTypes += f"{subType.capitalize()}, "
         message.embed.add_field(name="Subscription Types",
                                 value=subTypes.strip(", "))
     else:
         message.embed.title = "Already Subscribed!"
         message.embed.description = f"This channel is already subscribed to {channels.strip(', ')}!"
         message.embed.color = discord.Colour.red()
     message.msg = await message.msg.edit(content=None,
                                          embed=message.embed,
                                          view=None)
示例#4
0
async def defaultSubtype(cmd: Union[commands.Context, discord.Interaction],
                         bot: commands.Bot):
    """
    Prompts the user to either set or change the default subscription types for the channel.
    
    Arguments
    ---
    cmd: Context or interaction from the invoked command
    bot: The Discord bot.
    """
    db = await botdb.getDB(bot.pool)
    server = await dbTools.serverGrab(bot, str(cmd.guild.id),
                                      str(cmd.channel.id), ("subDefault", ),
                                      db)
    if isinstance(cmd, commands.Context):
        message = YagooMessage(bot, cmd.author)
        message.msg = await cmd.send("Loading channel subscription defaults..."
                                     )
    else:
        message = YagooMessage(bot, cmd.user)

    subTypes = {}
    for subType in allSubTypes(False):
        subTypes[subType] = False
    if not (server["subDefault"] is None or server["subDefault"] == ""):
        for subType in await botdb.listConvert(server["subDefault"]):
            subTypes[subType] = True

    message.embed.title = "Default Channel Subscription Types"
    message.embed.description = "Pick the subscription types for this channel to subscribe to by default."
    result = await subPrompts.subTypes.prompt(cmd, message, "Confirm",
                                              "confirm", subTypes, True)
    if isinstance(result, SubscriptionData):
        subDefault: List[str] = []
        for subType in result.subList:
            if result.subList[subType]:
                subDefault.append(subType)
        await botdb.addData(
            (str(cmd.channel.id), await botdb.listConvert(subDefault)),
            ("channel", "subDefault"), "servers", db)

        message.resetEmbed()
        message.embed.title = "Successfully Set Channel Defaults!"
        if subDefault == []:
            message.embed.description = "Subscription commands will now ask for subscription types first."
            message.embed.color = discord.Color.from_rgb(0, 0, 0)
        else:
            defaultSubs = ""
            for sub in subDefault:
                defaultSubs += f"{sub.capitalize()}, "
            message.embed.description = "Subscription commands will now follow the channel's defaults."
            message.embed.color = discord.Color.green()
            message.embed.add_field(name="Default Subscriptions",
                                    value=defaultSubs.strip(", "),
                                    inline=False)
        await message.msg.edit(content=" ", embed=message.embed, view=None)
        return await removeMessage(cmd=cmd)
    await removeMessage(message, cmd)
示例#5
0
 async def displayProgress(message: YagooMessage):
     message.resetEmbed()
     message.embed.title = "Currently Subscribing..."
     message.embed.description = "Currently subscribing to the channels specified.\n" \
                                 "This might take longer if the amount of channels is larger."
     message.embed.color = discord.Color.from_rgb(0, 0, 0)
     message.msg = await message.msg.edit(content=None,
                                          embed=message.embed,
                                          view=None)
示例#6
0
 def displayResult(message: YagooMessage, accName: str, status: bool):
     """
     Display the result of the follow action.
     
     Arguments
     ---
     message: The message used to display the result.
     accName: The Twitter account name.
     status: The status from the follow command.
     """
     message.resetEmbed()
     if status:
         message.embed.title = "Successfully Followed Account!"
         message.embed.description = f"This channel is now following @{accName}."
         message.embed.color = discord.Color.green()
     else:
         message.embed.title = "Already Followed Account!"
         message.embed.description = f"This channel is already following @{accName}."
         message.embed.color = discord.Color.red()
示例#7
0
        def displayResult(message: YagooMessage,
                          unfollowData: TwitterUnfollowResponse):
            """
            Display the result of the follow action.
            
            Arguments
            ---
            message: The message used to display the result.
            unfollowData: The channel's unfollow data.
            """
            message.resetEmbed()
            message.embed.title = "Successfully Unfollowed Accounts!"
            message.embed.color = discord.Color.green()

            accounts = ""
            if len(unfollowData.accounts) <= 3:
                for account in unfollowData.accounts:
                    accounts += f"@{account.handle}, "
            else:
                accounts = f"{len(unfollowData.accounts)} accounts'"
            if unfollowData.allAccounts:
                accounts = "all Twitter accounts'"
            message.embed.description = f"The channel has been unfollowed from {accounts.strip(', ')} tweets."
示例#8
0
        async def prompt(cmd: Union[commands.Context, discord.Interaction],
                         message: YagooMessage,
                         channelIDs: Optional[List[str]] = None,
                         subData: Optional[ChannelSubscriptionData] = None,
                         allChannels: bool = False):
            """
            Prompts the user for which subscription type to unsubscribe from.
            
            Arguments
            ---
            ctx: Context from the executed command.
            msg: The message that will be used as the prompt.
            channelIDs: IDs of the VTuber channels to be unsubscribed from.
            subData: The subscription data of the current channel.
            allChannels: If all channels are to be unsubscribed.
            
            Returns
            ---
            A `dict` with:
            - status: `True` if an option was chosen by the user.
            - unsubbed: A `list` with subscription types to unsubscribe from.
            """
            if not allChannels:
                channels = await unsubPrompts.removePrompt.parseToChannels(
                    channelIDs, subData)
            else:
                channels = subData.allChannels
            subTypes = {}

            if allChannels:
                name = "All Channels"
            elif len(channelIDs) > 1:
                name = "Multiple Channels"
            else:
                name = channels[0].channelName
            message.resetEmbed()
            message.embed.title = f"Unsubscribing from {name}"
            message.embed.description = "Choose the subscription types to unsubscribe from."

            if not allChannels:
                for channel in channels:
                    for subType in subData.findTypes(channel.channelID):
                        if subType not in subTypes:
                            subTypes[subType] = True
            else:
                for subType in allSubTypes(False):
                    subTypes[subType] = True

            while True:
                await unsubPrompts.removePrompt.editMsg(message, subTypes)
                if isinstance(cmd, commands.Context):
                    result = await message.legacyPost(cmd)
                else:
                    result = await message.post(cmd, True, True)

                if result.responseType:
                    if result.buttonID == "cancel":
                        return UnsubscriptionResponse(False)
                    if result.buttonID == "submit":
                        unsubbed = []
                        for subType in subTypes:
                            if not subTypes[subType]:
                                unsubbed.append(subType)
                        return UnsubscriptionResponse(True, unsubbed, channels)
                    if result.buttonID == "select":
                        allSubs = True
                        for subType in subTypes:
                            if subTypes[subType]:
                                allSubs = False
                        for subType in subTypes:
                            subTypes[subType] = allSubs
                    else:
                        subTypes[
                            result.buttonID] = not subTypes[result.buttonID]
                else:
                    return UnsubscriptionResponse(False)
示例#9
0
    async def subAll(cmd: Union[commands.Context, discord.Interaction],
                     message: YagooMessage,
                     server: dict,
                     channelId: str,
                     db: mysql.connector.MySQLConnection,
                     category: str = None):
        """
        Subscribes to all channels (in a category if specified, every channel if otherwise).
        
        Arguments
        ---
        cmd: Context or interaction from the invoked command.
        bot: The Discord bot.
        message: The message that will be used for prompts.
        server: The server as a `dict` containing `subDefault` and other subscription types.
        channelId: The channel ID of the current Discord channel.
        db: An existing MySQL connection to reduce unnecessary connections.
        category: The category filter for subscribing to channels within the category.
        
        Returns
        ---
        A `dict` with:
        - status: `True` if the subscription command was executed successfully.
        - subbed: A list containing the subscribed subscription types.
        """
        channel = await botdb.getAllData("channels", ("id", "twitter"),
                                         category,
                                         "category",
                                         db=db)
        subDefault = await subUtils.checkDefault(server)
        twitter = []
        channels = []

        for ch in channel:
            if ch["id"]:
                channels.append(ch["id"])
            if ch["twitter"]:
                twitter.append(ch["twitter"])

        if category is None:
            category = ""
        else:
            category += " "

        if subDefault == [''] or subDefault is None:
            subDefault = []
            message.resetEmbed()
            message.embed.title = f"Subscribing to all {category}VTubers"
            message.embed.description = "Pick the notifications to be posted to this channel.\n" \
                                        "(This prompt can be bypassed by setting a default subscription type " \
                                        "using the `subDefault` command)"
            result = await subPrompts.subTypes.prompt(cmd, message)
            if isinstance(result, SubscriptionData):
                for subType in result.subList:
                    if result.subList[subType]:
                        subDefault.append(subType)
            else:
                return SubscriptionResponse(False)
        for subType in subDefault:
            serverType = await botdb.listConvert(server[subType])
            if serverType is None:
                serverType = []
            if subType != "twitter":
                newData = list(set(serverType) | set(channels))
            else:
                newData = list(set(serverType) | set(twitter))
            await botdb.addData((channelId, await botdb.listConvert(newData)),
                                ("channel", subType), "servers", db)
        return SubscriptionResponse(True, subDefault)
示例#10
0
    async def subOne(cmd: commands.Context, message: YagooMessage,
                     server: dict, channelId: str,
                     channels: List[YouTubeChannel],
                     db: mysql.connector.MySQLConnection):
        """
        Subscribes to one/multiple channel(s) with the specified channel ID(s).
        
        Arguments
        ---
        cmd: Context or interaction from the executed command.
        msg: The message that will be used as a prompt.
        server: The server as a `dict` containing `subDefault` and other subscription types.
        channelId: The channel ID of the current Discord channel.
        channels: A `list` of `YouTubeChannel` of the currently being subscribed channels.
        db: An existing MySQL connection to reduce unnecessary connections.
        
        Returns
        ---
        An instance of `SubscriptionResponse`
        """
        subDefault = await subUtils.checkDefault(server)
        subbed = []

        if len(channels) > 1:
            ytChName = "Multiple Channels"
        else:
            ytChName = channels[0].channelName
        if subDefault == [''] or subDefault is None:
            message.resetEmbed()
            message.embed.title = f"Subscribing to {ytChName}"
            message.embed.description = "Pick the notifications to be posted to this channel.\n" \
                                        "(This prompt can be bypassed by setting a default subscription type " \
                                        "using the `subDefault` command)"
            result = await subPrompts.subTypes.prompt(cmd, message)
            if isinstance(result, YagooViewResponse):
                return SubscriptionResponse(False)
            subDefault = []
            for subType in result.subList:
                if result.subList[subType]:
                    subDefault.append(subType)
        for channel in channels:
            for subType in subDefault:
                stData = await botdb.listConvert(server[subType])
                if not stData:
                    stData = []
                if subType == "twitter":
                    twitter = (await botdb.getData(channel.channelID, "id",
                                                   ("twitter", ), "channels",
                                                   db))["twitter"]
                    if twitter is not None:
                        if twitter not in stData:
                            stData.append(twitter)
                            server[subType] = await botdb.listConvert(stData)
                            await botdb.addData(
                                (channelId, await botdb.listConvert(stData)),
                                ("channel", subType), "servers", db)
                            if subType not in subbed:
                                subbed.append(subType)
                else:
                    if channel.channelID not in stData:
                        stData.append(channel.channelID)
                        server[subType] = await botdb.listConvert(stData)
                        await botdb.addData(
                            (channelId, await botdb.listConvert(stData)),
                            ("channel", subType), "servers", db)
                        if subType not in subbed:
                            subbed.append(subType)
        if len(channels) <= 5:
            channelNames = []
            for channel in channels:
                channelNames.append(channel.channelName)
        else:
            channelNames = [f"{len(channels)} channels"]
        return SubscriptionResponse(True, subbed, channelNames=channelNames)
示例#11
0
    async def channelSearch(cmd: Union[commands.Context, discord.Interaction],
                            bot: commands.Bot,
                            message: YagooMessage,
                            channel: str,
                            action: str = "subscribe"):
        """
        Searches for a channel with input from the user.
        
        Arguments
        ---
        ctx: Context or interaction from the invoked command.
        bot: The Discord bot.
        message: The message that will be used for the prompt.
        channel: The name of the channel if already provided by the user.
        action: The action that is currently is being done with this search.
        
        Result
        ---
        A `dict` with:
        - status: `True` if the user successfully searches for a VTuber.
        - channelID: The channel ID of the VTuber channel.
        - channelName: The name of the channel.
        """
        wikiName = await FandomScrape.searchChannel(channel)

        while True:
            if wikiName.status.cannotMatch:
                wikiName = await subPrompts.searchPick(cmd, message, channel,
                                                       wikiName)

                if not wikiName.status.matched:
                    return FandomChannel()

            uConfirm = await subPrompts.vtuberConfirm.prompt(
                cmd, message, wikiName.channelName, action)
            if uConfirm.responseType:
                if uConfirm.buttonID == "confirm":
                    break
                elif uConfirm.buttonID == "results":
                    wikiName.cannotMatch()
                else:
                    return FandomChannel()
            else:
                return FandomChannel()

        channelData = await FandomScrape.getChannelURL(wikiName.channelName)
        if channelData.success:
            db = await botdb.getDB(bot.pool)
            if not await botdb.checkIfExists(channelData.channelID, "id",
                                             "channels", db):
                message.resetEmbed()
                message.embed.title = "Getting Channel Data..."
                message.embed.description = "This channel is new in the database.\nPlease wait while we're getting the channel's info."
                message.embed.color = discord.Color.from_rgb(0, 0, 0)
                message.msg = await message.msg.edit(content=None,
                                                     embed=message.embed,
                                                     view=None)
                chData = await subUtils.addChannel(channelData.channelID,
                                                   channelData.channelName,
                                                   ("id", "name"), db)
            else:
                chData = await botdb.getData(channelData.channelID, "id",
                                             ("id", "name"), "channels", db)
            return FandomChannel(True, chData["id"], chData["name"])
        return FandomChannel()