Beispiel #1
0
    async def unfollow(cmd: Union[commands.Context, discord.Interaction],
                       bot: commands.Bot):
        db = await botdb.getDB(bot.pool)
        if isinstance(cmd, commands.Context):
            message = YagooMessage(bot, cmd.author)
            message.msg = await cmd.send("Loading custom Twitter accounts...")
        else:
            message = YagooMessage(bot, cmd.user)

        server = await dbTools.serverGrab(bot, str(cmd.guild.id),
                                          str(cmd.channel.id), ("custom", ),
                                          db)
        customTwt = await botdb.getAllData("twitter",
                                           ("twtID", "name", "screenName"), 1,
                                           "custom", "twtID", db)
        followedData = await botdb.listConvert(server["custom"])
        if followedData == [''] or followedData == [] or not followedData:
            raise NoFollows(cmd.channel.id)
        followData = await TwitterPrompts.unfollow.parse(
            followedData, customTwt)
        userPick = await TwitterPrompts.unfollow.prompt(
            cmd, message, followData)
        if userPick.status:
            await TwitterUtils.followActions("remove", str(cmd.channel.id),
                                             userPick.accountIDs(),
                                             userPick.allAccounts, db)
            TwitterPrompts.unfollow.displayResult(message, userPick)
            message.msg = await message.msg.edit(content=None,
                                                 embed=message.embed,
                                                 view=None)
            await removeMessage(cmd=cmd)
        else:
            await removeMessage(message, cmd)
Beispiel #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
Beispiel #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)
Beispiel #4
0
async def subCustom(cmd: Union[commands.Context, discord.Interaction],
                    bot: commands.Bot, search: str):
    """
    Subscribes to a VTuber with the channel name provided to the user.
    
    Arguments
    ---
    ctx: Context from the executed command.
    bot: The Discord bot.
    search: The name of the channel to search for.
    """
    db = await botdb.getDB(bot.pool)
    if isinstance(cmd, commands.Context):
        message = YagooMessage(bot, cmd.author)
        message.msg = await cmd.send("Loading channels list...")
    else:
        message = YagooMessage(bot, cmd.user)

    result = await subUtils.channelSearch(cmd, bot, message, search)
    if result.success:
        server = await dbTools.serverGrab(
            bot, str(cmd.guild.id), str(cmd.channel.id),
            tuple(["subDefault"] + allSubTypes(False)), db)
        subResult = await subUtils.subOne(
            cmd, message, server, str(cmd.channel.id),
            [YouTubeChannel(result.channelID, result.channelName)], db)
        if subResult.status:
            await subPrompts.displaySubbed(message, subResult)
            await removeMessage(cmd=cmd)
            return
    await removeMessage(message, cmd)
Beispiel #5
0
async def sublistDisplay(cmd: Union[commands.Context, discord.Interaction],
                         bot: commands.Bot):
    """
    Show the user about the current subscriptions 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),
                                      tuple(allSubTypes(False)), db)
    if isinstance(cmd, commands.Context):
        message = YagooMessage(bot, cmd.author)
        message.msg = await cmd.send("Loading channel subscriptions...")
    else:
        message = YagooMessage(bot, cmd.user)

    subList = await unsubUtils.parseToSubTypes(server, db)
    pages = await subPrompts.sublistDisplay.parseToPages(subList)
    if len(pages) == 0:
        raise NoSubscriptions(str(cmd.channel.id))
    await subPrompts.sublistDisplay.prompt(cmd, message, pages, subList)
    await removeMessage(cmd=cmd)
Beispiel #6
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)
Beispiel #7
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)
Beispiel #8
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 #9
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)
Beispiel #10
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()
Beispiel #11
0
async def subCategory(cmd: Union[commands.Context, discord.Interaction],
                      bot: commands.Bot):
    """
    Subscription prompt that uses a category and channel based selection.
    
    Arguments
    ---
    cmd: Context or interaction from the executed command.
    bot: The Discord bot.
    """
    db = await botdb.getDB(bot.pool)
    if isinstance(cmd, commands.Context):
        message = YagooMessage(bot, cmd.author)
        message.msg = await cmd.send("Loading channels list...")
    else:
        message = YagooMessage(bot, cmd.user)

    channels = await botdb.getAllData("channels", ("id", "category"),
                                      keyDict="id",
                                      db=db)
    ctgPick = await subPrompts.ctgPicker(cmd, channels, message)

    if checkCancel(ctgPick):
        await removeMessage(message, cmd)
        return

    server = await dbTools.serverGrab(
        bot, str(cmd.guild.id), str(cmd.channel.id),
        ("subDefault", "livestream", "milestone", "premiere", "twitter"), db)
    if ctgPick.buttonID == "all":
        subResult = await subUtils.subAll(cmd, message, server,
                                          str(cmd.channel.id), db)
        subResult.channelNames = ["all VTubers"]
    else:
        channels = await botdb.getAllData("channels", ("id", "name"),
                                          ctgPick.selectValues[0],
                                          "category",
                                          keyDict="id",
                                          db=db)
        result = await subPrompts.channelPick.prompt(cmd, message, channels,
                                                     ctgPick.selectValues[0])
        if result.status:
            await subPrompts.displayProgress(message)
            if result.allInCategory:
                subResult = await subUtils.subAll(cmd, message, server,
                                                  str(cmd.channel.id), db,
                                                  ctgPick.selectValues[0])
                subResult.channelNames = [
                    f"all {ctgPick.selectValues[0]} VTubers"
                ]
            else:
                subResult = await subUtils.subOne(cmd, message, server,
                                                  str(cmd.channel.id),
                                                  result.channels, db)
        else:
            subResult = SubscriptionResponse(False)
    if subResult.status:
        await subPrompts.displaySubbed(message, subResult)
        await removeMessage(cmd=cmd)
        return
    await removeMessage(message, cmd)
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)