<commit_before>import asyncio
import datetime
import unicodedata
import xml.etree.ElementTree as et
import discord
from bs4 import BeautifulSoup
from discord.ext import tasks
from discord import app_commands
from discord.app_commands import Choice

from .daily import DAILY_CATEGORIES
from .exceptions import APIError


class DailyCategoriesDropdown(discord.ui.Select):

    def __init__(self, interaction, cog, behavior, pin_message, channel):
        options = []
        self.cog = cog
        self.behavior = behavior
        self.pin_message = pin_message
        self.channel = channel
        self.selected_values = []
        for category in DAILY_CATEGORIES:
            emoji = cog.get_emoji(interaction,
                                  f"daily_{category}",
                                  return_obj=True)
            options.append(
                discord.SelectOption(label=category["name"],
                                     value=category["value"],
                                     emoji=emoji or None))
        super().__init__(
            placeholder="Select which categories you want the bot to post",
            min_values=1,
            max_values=len(options),
            options=options)

    async def callback(self, interaction: discord.Interaction):
        self.view.selected_options = self.values
        await interaction.response.defer(ephemeral=True)
        categories = self.values
        embed = await self.cog.daily_embed(categories, interaction=interaction)
        autodelete = False
        autoedit = False
        if self.behavior == "autodelete":
            autodelete = True
        if self.behavior == "autoedit":
            autoedit = True
        settings = {
            "daily.on": True,
            "daily.channel": self.channel.id,
            "daily.autopin": self.pin_message,
            "daily.autodelete": autodelete,
            "daily.autoedit": autoedit,
            "daily.categories": categories
        }
        await self.cog.bot.database.set(interaction.guild, settings, self)
        await interaction.edit_original_message(
            content="I will now send "
            f"dailies to {self.channel.mention}. Here's an example "
            "notification:",
            embed=embed,
            view=None)
        self.view.stop()


class NotiifiersMixin:
    notifier_group = app_commands.Group(name="notifier",
                                        description="Notifier Commands")

    @notifier_group.command(name="daily")
    @app_commands.checks.has_permissions(manage_guild=True)
    @app_commands.guild_only()
    @app_commands.describe(
        enabled="Enable or disable Daily Notifier. If "
        "enabling, channel argument must be set",<commit_msg>Fix generating malformed configs for daily notifis<commit_after>import asyncio
import datetime
import unicodedata
import xml.etree.ElementTree as et
import discord
from bs4 import BeautifulSoup
from discord.ext import tasks
from discord import app_commands
from discord.app_commands import Choice

from .daily import DAILY_CATEGORIES
from .exceptions import APIError


class DailyCategoriesDropdown(discord.ui.Select):

    def __init__(self, interaction, cog, behavior, pin_message, channel):
        options = []
        self.cog = cog
        self.behavior = behavior
        self.pin_message = pin_message
        self.channel = channel
        self.selected_values = []
        for category in DAILY_CATEGORIES:
            emoji = cog.get_emoji(interaction,
                                  f"daily_{category}",
                                  return_obj=True)
            options.append(
                discord.SelectOption(label=category["name"],
                                     value=category["value"],
                                     emoji=emoji or None))
        super().__init__(
            placeholder="Select which categories you want the bot to post",
            min_values=1,
            max_values=len(options),
            options=options)

    async def callback(self, interaction: discord.Interaction):
        self.view.selected_options = self.values
        await interaction.response.defer(ephemeral=True)
        categories = self.values
        embed = await self.cog.daily_embed(categories, interaction=interaction)
        autodelete = False
        autoedit = False
        if self.behavior == "autodelete":
            autodelete = True
        if self.behavior == "autoedit":
            autoedit = True
        settings = {
            "daily.on": True,
            "daily.channel": self.channel.id,
            "daily.autopin": self.pin_message,
            "daily.autodelete": autodelete,
            "daily.autoedit": autoedit,
            "daily.categories": categories
        }
        await self.cog.bot.database.set(interaction.guild, settings, self.cog)
        await interaction.edit_original_message(
            content="I will now send "
            f"dailies to {self.channel.mention}. Here's an example "
            "notification:",
            embed=embed,
            view=None)
        self.view.stop()


class NotiifiersMixin:
    notifier_group = app_commands.Group(name="notifier",
                                        description="Notifier Commands")

    @notifier_group.command(name="daily")
    @app_commands.checks.has_permissions(manage_guild=True)
    @app_commands.guild_only()
    @app_commands.describe(
        enabled="Enable or disable Daily Notifier. If "
        "enabling, channel argument must be set",
{'fraction_non_alphanumeric': 0.08428081573723155, 'fraction_numerical': 0.0007218913553510197, 'mean_word_length': 2.09608938547486, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1515151', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1431, 'n_words': 337}