<reponame>fennr/Samuro-HotsBot
import discord
from discord import Embed
from discord.ext import commands
from discord.ext.commands import command, Cog, errors
from discord_components import DiscordComponents, Button, ButtonStyle, Select, SelectOption
from discord_slash.context import ComponentContext, MenuContext
from utils import check
from utils.classes.Const import config

labels = {
    'Questions': {
        'Error': 'Ошибка',
        'Question': 'Вопрос',
        'Report': 'Жалоба',
        'Offer': 'Предложение',
    },
    'Close': 'Закрыть тикет'
}

TICKET_CATEGORY = 'Tickets'

menu_buttons = [
    # Button(style=ButtonStyle.gray, label=labels['Error'],),
    Button(style=ButtonStyle.gray, label=labels['Questions']['Question']),
    Button(style=ButtonStyle.gray, label=labels['Questions']['Report']),
    Button(style=ButtonStyle.gray, label=labels['Questions']['Offer']),
]

remove_button = [
    Button(style=ButtonStyle.red, label=labels['Close'])
]


class Report(commands.Cog, name="Report"):
    def __init__(self, bot):
        self.bot = bot

    @command(name='create_rep')
    @check.is_owner()
    async def create_report(self, ctx):
        message = 'Воспользовавшись кнопками ниже можно связаться с модерацией по интересующим вопросам'
        embed = Embed(
            title='Поддержка',
            description=message,
            color=config.success
        )
        await ctx.message.delete()
        await ctx.send(embed=embed, components=[menu_buttons])

    @command(name='ruhots_report')
    @check.is_admin()
    async def ruhots_report(self, ctx):
        message = 'Воспользовавшись кнопками ниже можно написать модераторам\n' \
                  'по интересующим вопросам'
        embed_image = Embed(
            color=config.grey,
        )
        embed = Embed(
            description=message,
            color=config.grey
        )
        await ctx.message.delete()
        filename = 'support.png'
        file = discord.File('data/img/support-ruhots.png', filename=filename)
        embed_image.set_image(url=f'attachment://{filename}')
        await ctx.send(file=file, embeds=[embed_image, embed], components=[menu_buttons])

    @command(name='select')
    async def select_test(self, ctx):
        stalk = discord.utils.get(ctx.guild.emojis, name='stalk')
        rqg = discord.utils.get(ctx.guild.emojis, name='RQG2')
        event_5x5 = discord.utils.get(ctx.guild.emojis, name='kotj')
        select = Select(
            options=[  # the options in your dropdown
                SelectOption(label="Сталк", value="stlk", emoji=stalk),
                SelectOption(label="RQG", value="rqg", emoji=rqg),
                SelectOption(label="Бои 5х5", value="5x5", emoji=event_5x5),
            ],
            placeholder="Выберите подписки",  # the placeholder text to show when no options have been chosen
            min_values=1,  # the minimum number of options a user must select
            max_values=2,  # the maximum number of options a user can select
        )
        await ctx.message.delete()
        await ctx.send("Здесь можно подписаться на разделы", components=[select])

    @Cog.listener()
    async def on_component(self, ctx: ComponentContext):
        if ctx.selected_options is not None:
            # ctx.selected_options is a list of all the values the user selected
            await ctx.send(content=f"You selected {ctx.selected_options}")

    @Cog.listener()
    async def on_button_click(self, interaction):
        if interaction.component.label == labels['Close']:
            await interaction.channel.delete()
        if interaction.component.label in labels['Questions'].values():
            category = discord.utils.get(interaction.guild.categories, name=TICKET_CATEGORY)
            name = f"{interaction.component.label}-{interaction.author.name}"
            channel = await interaction.guild.create_text_channel(name, category=category, sync_permissions=True)
            overwrite = discord.PermissionOverwrite()
            overwrite.send_messages = True
            overwrite.read_messages = True
            await channel.set_permissions(target=interaction.author, overwrite=overwrite)
            ticket_created_embed = discord.Embed(
                title="Заявка открыта",
                description=f"""Привет {interaction.author.name}! Напиши свое сообщение в данном чате.\n
                Если вопрос решен, заявку можно закрыть нажав кнопку ниже""",
            )
            await channel.send(
                interaction.author.mention, embed=ticket_created_embed, components=[remove_button]
            )  # ping the user who pressed the button, and send the embed
        try:
            await interaction.respond()
        except:
            pass


def setup(bot):
    bot.add_cog(Report(bot))

import discord
from discord import Embed
from discord.ext import commands
from discord.ext.commands import command, Cog, errors
from discord_components import DiscordComponents, Button, ButtonStyle, Select, SelectOption
from discord_slash.context import ComponentContext, MenuContext
from utils import check
from utils.classes.Const import config

labels = {
    'Questions': {
        'Error': 'Ошибка',
        'Question': 'Вопрос',
        'Report': 'Жалоба',
        'Offer': 'Предложение',
    },
    'Close': 'Закрыть тикет'
}

TICKET_CATEGORY = 'Tickets'

menu_buttons = [
    # Button(style=ButtonStyle.gray, label=labels['Error'],),
    Button(style=ButtonStyle.gray, label=labels['Questions']['Question']),
    Button(style=ButtonStyle.gray, label=labels['Questions']['Report']),
    Button(style=ButtonStyle.gray, label=labels['Questions']['Offer']),
]

remove_button = [
    Button(style=ButtonStyle.red, label=labels['Close'])
]


class Report(commands.Cog, name="Report"):
    def __init__(self, bot):
        self.bot = bot

    @command(name='create_rep')
    @check.is_owner()
    async def create_report(self, ctx):
        message = 'Воспользовавшись кнопками ниже можно связаться с модерацией по интересующим вопросам'
        embed = Embed(
            title='Поддержка',
            description=message,
            color=config.success
        )
        await ctx.message.delete()
        await ctx.send(embed=embed, components=[menu_buttons])

    @command(name='ruhots_report')
    @check.is_admin()
    async def ruhots_report(self, ctx):
        message = 'Воспользовавшись кнопками ниже можно написать модераторам\n' \
                  'по интересующим вопросам'
        embed_image = Embed(
            color=config.grey,
        )
        embed = Embed(
            description=message,
            color=config.grey
        )
        await ctx.message.delete()
        filename = 'support.png'
        file = discord.File('data/img/support-ruhots.png', filename=filename)
        embed_image.set_image(url=f'attachment://{filename}')
        await ctx.send(file=file, embeds=[embed_image, embed], components=[menu_buttons])

    @command(name='select')
    async def select_test(self, ctx):
        stalk = discord.utils.get(ctx.guild.emojis, name='stalk')
        rqg = discord.utils.get(ctx.guild.emojis, name='RQG2')
        event_5x5 = discord.utils.get(ctx.guild.emojis, name='kotj')
        select = Select(
            options=[  # the options in your dropdown
                SelectOption(label="Сталк", value="stlk", emoji=stalk),
                SelectOption(label="RQG", value="rqg", emoji=rqg),
                SelectOption(label="Бои 5х5", value="5x5", emoji=event_5x5),
            ],
            placeholder="Выберите подписки",  # the placeholder text to show when no options have been chosen
            min_values=1,  # the minimum number of options a user must select
            max_values=2,  # the maximum number of options a user can select
        )
        await ctx.message.delete()
        await ctx.send("Здесь можно подписаться на разделы", components=[select])

    @Cog.listener()
    async def on_component(self, ctx: ComponentContext):
        if ctx.selected_options is not None:
            # ctx.selected_options is a list of all the values the user selected
            await ctx.send(content=f"You selected {ctx.selected_options}")

    @Cog.listener()
    async def on_button_click(self, interaction):
        if interaction.component.label == labels['Close']:
            await interaction.channel.delete()
        if interaction.component.label in labels['Questions'].values():
            category = discord.utils.get(interaction.guild.categories, name=TICKET_CATEGORY)
            name = f"{interaction.component.label}-{interaction.author.name}"
            channel = await interaction.guild.create_text_channel(name, category=category, sync_permissions=True)
            overwrite = discord.PermissionOverwrite()
            overwrite.send_messages = True
            overwrite.read_messages = True
            await channel.set_permissions(target=interaction.author, overwrite=overwrite)
            ticket_created_embed = discord.Embed(
                title="Заявка открыта",
                description=f"""Привет {interaction.author.name}! Напиши свое сообщение в данном чате.\n
                Если вопрос решен, заявку можно закрыть нажав кнопку ниже""",
            )
            await channel.send(
                interaction.author.mention, embed=ticket_created_embed, components=[remove_button]
            )  # ping the user who pressed the button, and send the embed
        try:
            await interaction.respond()
        except:
            pass


def setup(bot):
    bot.add_cog(Report(bot))
# Button(style=ButtonStyle.gray, label=labels['Error'],), # the options in your dropdown # the placeholder text to show when no options have been chosen # the minimum number of options a user must select # the maximum number of options a user can select # ctx.selected_options is a list of all the values the user selected Привет {interaction.author.name}! Напиши свое сообщение в данном чате.\n                 Если вопрос решен, заявку можно закрыть нажав кнопку ниже # ping the user who pressed the button, and send the embed