Skip to content

Commit

Permalink
Tickets cog
Browse files Browse the repository at this point in the history
  • Loading branch information
Xarlos89 committed Dec 31, 2024
1 parent 877bf7e commit e3dfcdc
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/bot/cogs/features/ticket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""
This cog allows us to create tickets.
"""
import logging

import discord
from discord.ext import commands

logger = logging.getLogger(__name__)


class AddTicketButton(commands.Cog):
"""
This is the slash command that sends our UI element.
"""

def __init__(self, eos):
self.eos = eos

@commands.command(description="Make a ticket and contact the Staff.")
async def ticket(self, ctx):
"""
A simple command with a view.
"""
logger.info("%s used the %s command.", ctx.author.name, ctx.command)
await ctx.send(
"Do you need help, or do you have a question for the Staff?",
view=MakeATicket(self.eos),
ephemeral=True,
)


class MakeATicket(discord.ui.View):
"""
A UI component that sends a button, which does other things.
"""

def __init__(self, eos, *, timeout=None):
super().__init__(timeout=timeout)
self.eos = eos

@discord.ui.button(label="Open a support Ticket", style=discord.ButtonStyle.primary)
async def button_callback(self, interaction, button):
"""
The callback on the button, or... what happens on click.
"""
await interaction.response.defer()
button.label = "Ticket Created!"
button.disabled = True
await interaction.edit_original_response(view=self)

support = interaction.channel #TODO: guild specific settings for a support channel
staff = interaction.guild.get_role(self.eos.api.get_one_role("3")[0]["roles"][2]) # Staff

ticket = await support.create_thread(
name=f"[Ticket] - {interaction.user}",
message=None,
auto_archive_duration=4320,
type=discord.ChannelType.private_thread,
reason=None,
)

for person in interaction.guild.members:
if staff in person.roles:
await ticket.add_user(person)

await ticket.add_user(interaction.user)
interaction.delete_original_response()
await ticket.send(f"**{interaction.user.mention}, we have received your ticket.**")
await ticket.send("To better help you, please describe your issue.")


async def setup(bot: commands.Bot) -> None:
"""boink"""
await bot.add_cog(AddTicketButton(bot))

0 comments on commit e3dfcdc

Please sign in to comment.