Skip to content

Commit

Permalink
added support system
Browse files Browse the repository at this point in the history
  • Loading branch information
Timpe Hoerig authored and Timpe Hoerig committed Jul 10, 2023
1 parent ed575de commit 6ee926d
Show file tree
Hide file tree
Showing 2 changed files with 223 additions and 2 deletions.
123 changes: 122 additions & 1 deletion src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@
OffTopicChannelRequestDeclineInput,
accept_offtopic_channel_send,
decline_offtopic_channel_send,
SupportRequestInput,
support_request_button,
support_embed,
support_view,
create_support_request_accept_embed,
accept_support_request_send,
support_request_accepted,
accept_support_send,
SupportRequestDeclineInput,
decline_support_send,
)
from .env import env

Expand Down Expand Up @@ -182,9 +192,34 @@ async def on_request(

await message.edit(content="", embed=channel_embed, view=channel_view())

async def support(self):
# get channels channel
message = await last_or_new_channel_message(channel_by_name(self, "support"))

# opens the request modal
async def support_request_modal(interaction: Interaction):
support_request_input = SupportRequestInput()
support_request_input.on_submit = MethodType(
on_request, support_request_input
)
await interaction.response.send_modal(support_request_input)

# sends the request to admin channel
async def on_request(
input: SupportRequestInput,
interaction: Interaction,
):
await forward_support_request(input, interaction)

support_request_button.callback = support_request_modal

await message.edit(content="", embed=support_embed, view=support_view())


async def voice(self, member: Member, before: VoiceState, after: VoiceState):
create = utils.get(member.guild.voice_channels, name="create")
category = utils.get(member.guild.categories, name="voice")
category_support = utils.get(member.guild.categories, name="support")

# user joined #create
if before.channel != after.channel and after.channel == create:
Expand Down Expand Up @@ -232,7 +267,7 @@ async def voice(self, member: Member, before: VoiceState, after: VoiceState):
await member.move_to(channel)
if (
before.channel != after.channel
and before.channel.category == category
and (before.channel.category == category or before.channel.category == category_support)
and not before.channel.members
and before.channel.id != int(env.create_voice_channel_id)
):
Expand Down Expand Up @@ -478,6 +513,92 @@ async def on_decline(
request_interaction.response, accept_channel_request_send
)

## Support ##############################################################################


async def forward_support_request(
input: SupportRequestInput, request_interaction: Interaction
):
async def on_accept(
accept_interaction: Interaction,
):
await accept_interaction.user.guild.create_voice_channel(
name=f"{request_interaction.user.nick}'s support",
overwrites={
utils.get(
accept_interaction.user.guild.roles, name="@everyone"
): PermissionOverwrite(
view_channel=False,
),
utils.get(
accept_interaction.user.guild.roles, name="Authenticated"
): PermissionOverwrite(
add_reactions=True,
attach_files=True,
connect=True,
create_instant_invite=True,
create_public_threads=True,
embed_links=True,
external_emojis=True,
external_stickers=True,
read_message_history=True,
read_messages=True,
send_messages=True,
send_messages_in_threads=True,
send_voice_messages=True,
speak=True,
stream=True,
use_application_commands=True,
use_embedded_activities=True,
use_external_emojis=True,
use_external_sounds=True,
use_external_stickers=True,
use_soundboard=True,
use_voice_activation=True,
),
},
category=utils.get(
accept_interaction.user.guild.categories, name="support"
)
)
embed = accept_interaction.message.embeds[0]
embed = embed.set_footer(text=f"Accepted by {accept_interaction.user.nick}")
await accept_interaction.user.move_to(channel)
if request_interaction.user.is_connected():
request_interaction.user.move_to(channel)
else:
await request_interaction.user.send(
support_request_accepted(request_interaction.user.nick)
)
await accept_interaction.message.edit(embed=embed, view=None)
await send_decaying_response_message(
accept_interaction.response, accept_support_send
)

async def on_decline(
support_request_decline_input: SupportRequestDeclineInput,
decline_interaction: Interaction,
):
decline_message = support_request_decline_input.declined_massage.value
await request_interaction.user.send(decline_message)

embed = decline_interaction.message.embeds[0]
embed = embed.set_footer(text=f"Declined by {decline_interaction.user.nick}")
await decline_interaction.message.edit(embed=embed, view=None)
await send_decaying_response_message(
decline_interaction.response, decline_support_send
)

view, embed = create_support_request_accept_embed(
input, request_interaction, on_accept, on_decline
)

channel = utils.get(request_interaction.user.guild.channels, name="accept")
await channel.send(embed=embed, view=view)

await send_decaying_response_message(
request_interaction.response, accept_support_request_send
)

## Utils ################################################################################

Expand Down
102 changes: 101 additions & 1 deletion src/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ async def channel_request_decline_modal(modal_interaction: Interaction):
colour=Colour.blurple(),
timestamp=datetime.now(),
)
# Fehler liegt hier
accept_channel_request_embed.add_field(
name="Name of Lecture",
value=input.name_of_lecture.value,
Expand Down Expand Up @@ -357,3 +356,104 @@ async def offtopic_channel_request_decline_modal(modal_interaction: Interaction)
)

return accept_offtopic_channel_request_view, accept_offtopic_channel_request_embed

# offtopic channel request #############################################################################


support_request_send = "Request sent successfully"
support_request_accepted = (
lambda nick: f"A moderator is now ready to help you in the {nick}'s support channel."
)


support_embed_description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer vehicula pulvinar urna quis hendrerit. In hendrerit odio ac molestie sagittis. In fermentum nulla ac fringilla finibus. Fusce non mi porta, cursus urna id, tempor nibh. Morbi vitae turpis iaculis, imperdiet ex vitae, rhoncus ex. Phasellus congue odio eget pellentesque sagittis. Donec metus enim, molestie sit amet rutrum quis, vehicula eget diam."


class SupportRequestInput(Modal, title="Support request"):
topic = TextInput(label="Topic", placeholder="eg. Authenticate")
description = TextInput(
label="Description", placeholder="eg. My generated token isn't valid."
)


support_request_button = Button(label="Request Support", style=ButtonStyle.danger)

support_view = lambda: (
View(timeout=None)
.add_item(support_request_button)
)

support_embed = Embed(
type="rich",
title="Support",
colour=Colour.blurple(),
timestamp=datetime.now(),
description=support_embed_description,
)

support_embed.set_footer(text="Powered by Laurel")

## #accept support #############################################################################

accept_support_send = "Accepted channel request"
decline_support_send = "Declined channel request"

accept_support_request_send = "Request submitted"


class SupportRequestDeclineInput(Modal, title="Decline Support Request"):
declined_massage = TextInput(label="Reason")


def create_support_request_accept_embed(
input: SupportRequestInput,
interaction: Interaction,
on_accept: Callable[[Interaction], None],
on_decline: Callable[[SupportRequestDeclineInput, Interaction], None],
) -> tuple[View, Embed]:
async def support_request_decline_modal(modal_interaction: Interaction):
support_request_decline_input = SupportRequestDeclineInput()

support_request_decline_input.declined_massage.default = (
"There is already a forum post for this topic."
)

support_request_decline_input.on_submit = MethodType(
on_decline, support_request_decline_input
)

await modal_interaction.response.send_modal(support_request_decline_input)

accept_support_request_button = Button(label="Accept", style=ButtonStyle.green)
decline_support_request_button = Button(label="Decline", style=ButtonStyle.danger)

accept_support_request_button.callback = on_accept
decline_support_request_button.callback = support_request_decline_modal

accept_support_request_view = (
View(timeout=None)
.add_item(accept_support_request_button)
.add_item(decline_support_request_button)
)

accept_support_request_embed = Embed(
type="rich",
title="Support Request",
colour=Colour.green(),
timestamp=datetime.now(),
)
accept_support_request_embed.add_field(
name="Topic",
value=input.topic.value,
inline=False
)
accept_support_request_embed.add_field(
name="Description",
value=input.description.value,
inline=False
)
accept_support_request_embed.set_author(
name=interaction.user.nick, icon_url=interaction.user.avatar.url
)

return accept_support_request_view, accept_support_request_embed

0 comments on commit 6ee926d

Please sign in to comment.