Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tickets #13

Merged
merged 2 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,4 @@ dmypy.json
# Cython debug symbols
cython_debug/

/.obsidian/
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))