async def prompt(cmd: Union[commands.Context, discord.Interaction], message: YagooMessage, buttonText: str = "Subscribe", buttonID: str = "subscribe", subTypes: dict = None, allowNone: bool = False): """ Prompts the user for subscription types. The title and description must be set beforehand. Arguments --- ctx: Context from the executed command. msg: The message that will be used as the prompt. buttonText: The text for the subscribe button. buttonID: The ID for the subscribe button. subTypes: Existing subscription type status as a `dict`. allowNone: To allow the user to select none of the subscription types. Returns --- `SubscriptionData` if the user confirmed the choice. `YagooViewResponse` if cancelled or timed out. """ buttonStates = subTypes if not buttonStates: buttonStates = {} subTypes = allSubTypes(False) for subType in subTypes: buttonStates[subType] = False while True: message.resetComponents() await subPrompts.subTypes.editMsg(subTypes, message, buttonStates, buttonText, buttonID, allowNone) if isinstance(cmd, commands.Context): result = await message.legacyPost(cmd) else: result = await message.post(cmd, True, True) if result.responseType: if result.buttonID not in ["cancel", "all", buttonID]: buttonStates[result.buttonID] = not buttonStates[ result.buttonID] elif result.buttonID == "all": allBool = True for button in buttonStates: if allBool: allBool = buttonStates[button] for button in buttonStates: buttonStates[button] = not allBool else: if result.buttonID == buttonID: return SubscriptionData(buttonStates) return result else: return result
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)
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