Skip to content

Commit

Permalink
add close commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Selyss committed Dec 8, 2023
1 parent 61661c4 commit 222f49a
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 20 deletions.
59 changes: 39 additions & 20 deletions cogs/inquiry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
from nextcord.ext import commands
import nextcord

CLOSED_CATEGORY = 1182473403303723128

with open("config.json", "r", encoding="utf-8") as config_file:
config = json.load(config_file)
REQUEST_CHANNEL: int = config["request_channel"]
# PAID_CATEGORY: int = config["paid_category"]

# TODO: add as config fields
TICKET_CATEGORY: int = 1178415757378461727
TICKET_CATEGORY: int = 1182104505270149221
PAID_CATEGORY: int = 1181391079698878555
EMBED_COLOR = 0xFF88FF
EMBED_SUCCESS = 0x2ECC71
AD_EMBED_COLOR = 0x2ECC71
MARLOW_ID: int = 630872658027872273
ADVERTISING_ROLE: int = 1096584186304942111
Expand Down Expand Up @@ -66,8 +68,25 @@ async def advertisement(self, btn: nextcord.ui.Button, inter: nextcord.Interacti
await inter.response.send_modal(AdForm())


class CloseView(nextcord.ui.View):
def __init__(self) -> None:
super().__init__(timeout=None)

@nextcord.ui.button(
label="Close", style=nextcord.ButtonStyle.red, custom_id="ticket:close"
)
async def close(self, btn: nextcord.ui.Button, inter: nextcord.Interaction):
await self.inter.channel.send("Closing ticket...")
await self.inter.channel.edit(
category=self.inter.bot.get_channel(CLOSED_CATEGORY)
)
await self.inter.channel.set_permissions(
self.inter.author, read_messages=False, send_messages=False
)


class QuickResponse(nextcord.ui.Modal):
def __init__(self, person) -> None:
def __init__(self, person: nextcord.Member) -> None:
super().__init__(
title="Quick Response",
timeout=None,
Expand All @@ -89,8 +108,8 @@ async def callback(self, inter: nextcord.Interaction) -> None:

category = nextcord.utils.get(inter.guild.categories, id=TICKET_CATEGORY)
new_channel = await category.create_text_channel(
name=f"ticket-{inter.user.name}",
reason=f"Created ticket for {inter.user.id} - {inter.user.name}",
name=f"ticket-{self.person.user.name}",
reason=f"Created ticket for {self.person.user.id} - {self.person.user.name}",
topic=self.person.user.id,
)
await inter.response.send_message(
Expand All @@ -101,13 +120,16 @@ async def callback(self, inter: nextcord.Interaction) -> None:
# em.set_author(icon_url=marlow.user.avatar, name=marlow.user.name)
em.add_field(name="**CONTACT REQUEST ACCEPTED**", value="", inline=False)
em.add_field(name="**message**", value=self.details.value, inline=False)
em.set_footer(text=f"{inter.user.id}{get_date()}{get_time()}")
em.set_footer(text=f"{self.person.user.id}{get_date()}{get_time()}")

await new_channel.send(
content=f"<@{inter.user.id}>",
content=f"<@{self.person.user.id}>",
embed=em,
view=CloseView(),
)
await new_channel.set_permissions(
self.person.user, send_messages=False, read_messages=True
)


class RequestView(nextcord.ui.View):
Expand Down Expand Up @@ -150,17 +172,6 @@ async def quickresponse(self, btn: nextcord.ui.Button, inter: nextcord.Interacti
await inter.response.send_modal(QuickResponse(self.person))


class CloseView(nextcord.ui.View):
def __init__(self) -> None:
super().__init__(timeout=None)

@nextcord.ui.button(
label="Close", style=nextcord.ButtonStyle.red, custom_id="ticket:close"
)
async def close(self, btn: nextcord.ui.Button, inter: nextcord.Interaction):
await inter.channel.delete()


class AdView(nextcord.ui.View):
def __init__(self) -> None:
super().__init__(timeout=None)
Expand All @@ -171,6 +182,12 @@ def __init__(self) -> None:
async def paid(self, btn: nextcord.ui.Button, inter: nextcord.Interaction):
category = nextcord.utils.get(inter.guild.categories, id=PAID_CATEGORY)
await inter.channel.edit(category=category)
em = nextcord.Embed()
em.color = EMBED_SUCCESS
em.title = ":checkmark: Payment Received"
em.description = """Thank you for your purchase!\nIf you haven't already, please send your advertisement message and ensure if you are using any custom/nitro-accessed Emojis that they are present within the Discord you are advertising (emojis from our server are fine, too).\n\nIf another advertisement was recently posted, out of courtesy it will be given a reasonable amount of uptime before yours is posted."""
em.set_footer(text=f"{inter.user.id}{get_date()}{get_time()}")
await inter.response.send_message(embed=em)


class AdForm(nextcord.ui.Modal):
Expand Down Expand Up @@ -214,9 +231,11 @@ async def callback(self, inter: nextcord.Interaction) -> None:
embed=em,
view=AdView(),
)
await new_channel.send(
content="""--------------------------------------------\n__**ADVERTISEMENT SERVICES**__\n\n🔔 $40 = Ping @ everyone with ad message/links\n\n🎁 $45 = Hosted Nitro Giveaway Ad with @ everyone ping (Nitro must be supplied by the customer)\n\n*These prices apply to the Vanilla PvP Community/Tier List*\n--------------------------------------------"""
)
emb = nextcord.Embed()
emb.color = 0xE67E22
emb.title = "__**Advertisement Services**__"
emb.description = """:bell: $40 = Ping @ everyone with ad message/links\n\n:gift: $45 = Hosted Nitro Giveaway Ad with @ everyone ping (Nitro must be supplied by the customer)\n\n*These prices apply to the Vanilla PvP Community/Tier List*"""
await new_channel.send(embed=emb)


class QuestionForm(nextcord.ui.Modal):
Expand Down
59 changes: 59 additions & 0 deletions cogs/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,45 @@
from nextcord.ext.commands import Bot, Cog
import nextcord

CLOSED_CATEGORY = 1182473403303723128

with open("config.json", "r", encoding="utf-8") as conf:
config = json.load(conf)


class CloseRequest(nextcord.ui.View):
def __init__(self, inter: nextcord.Interaction):
super().__init__(timeout=60)
self.inter = inter

@nextcord.ui.button(label="☑️ Accept & Close", style=nextcord.ButtonStyle.green)
async def accept(self, button: nextcord.ui.Button, inter: nextcord.Interaction):
await self.inter.channel.send("Closing ticket...")
await self.inter.channel.edit(category=CLOSED_CATEGORY)
await self.inter.channel.set_permissions(
self.inter.author, read_messages=False, send_messages=False
)
await self.inter.channel.send("Ticket closed!")

@nextcord.ui.button(label="❌ Deny & Keep Open", style=nextcord.ButtonStyle.gray)
async def deny(self, button: nextcord.ui.Button, inter: nextcord.Interaction):
await inter.channel.send("Request denied!")


class CloseView(nextcord.ui.View):
def __init__(self, inter: nextcord.Interaction):
super().__init__(timeout=60)
self.inter = inter

@nextcord.ui.button(label="Acknowledge", style=nextcord.ButtonStyle.blurple)
async def accept(self, button: nextcord.ui.Button, inter: nextcord.Interaction):
await self.inter.channel.send("Closing ticket...")
await self.inter.channel.edit(category=CLOSED_CATEGORY)
await self.inter.channel.set_permissions(
self.inter.author, read_messages=False, send_messages=False
)


class Ticket(Cog):
def __init__(self, bot: Bot) -> None:
self.bot = bot
Expand Down Expand Up @@ -37,6 +72,30 @@ async def set_log_channel(
ephemeral=True,
)

@slash_command(name="close", description="close a ticket")
async def close_ticket(self, inter: nextcord.Interaction):
if inter.channel.category_id == CLOSED_CATEGORY:
await inter.send("This channel is already closed!", ephemeral=True)
return
em = nextcord.Embed()
em.title = "Ticket Closed"
em.description = f"<@{inter.user.id}> has closed this ticket.\n\nPlease acknowledge this closure using the button below."

await inter.channel.send(embed=em, view=CloseView(inter=inter))

@slash_command(name="closereq", description="request to close ticket")
async def close_request(self, inter: nextcord.Interaction):
if inter.channel.category_id == CLOSED_CATEGORY:
await inter.send("This channel is already closed!", ephemeral=True)
return

em = nextcord.Embed()
em.color = 0x3498DB
em.title = "Ticket Close Request"
em.description = f"<@{inter.user.id}> has requested to close this ticket.\n\nPlease accept or deny this request using the buttons below."

await inter.channel.send(embed=em, view=CloseRequest(inter=inter))


def setup(bot: Bot) -> None:
bot.add_cog(Ticket(bot))

0 comments on commit 222f49a

Please sign in to comment.