Skip to content

Commit

Permalink
Implement core tickets system (#20)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Suggested by Mir, created by Noelle
  • Loading branch information
No767 authored Jan 5, 2024
1 parent 8082e64 commit 92f2972
Show file tree
Hide file tree
Showing 16 changed files with 1,234 additions and 43 deletions.
42 changes: 33 additions & 9 deletions bot/cogs/config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from typing import Optional
from __future__ import annotations

from typing import TYPE_CHECKING, Optional

import asyncpg
import discord
import msgspec
from async_lru import alru_cache
from discord.ext import commands
from libs.utils import RoboContext, is_manager
from rodhaj import Rodhaj

if TYPE_CHECKING:
from rodhaj import Rodhaj

UNKNOWN_ERROR_MESSAGE = (
"An unknown error happened. Please contact the dev team for assistance"
Expand All @@ -21,6 +25,7 @@ class GuildConfig(msgspec.Struct):
ticket_channel_id: int
logging_channel_id: int
logging_broadcast_url: str
ticket_broadcast_url: str
locked: bool = False

@property
Expand Down Expand Up @@ -54,10 +59,18 @@ async def get_webhook(self) -> Optional[discord.Webhook]:
url=conf.logging_broadcast_url, session=self.session
)

async def get_ticket_webhook(self) -> Optional[discord.Webhook]:
conf = await self.get_config()
if conf is None:
return None
return discord.Webhook.from_url(
url=conf.ticket_broadcast_url, session=self.session
)

@alru_cache()
async def get_config(self) -> Optional[GuildConfig]:
query = """
SELECT id, category_id, ticket_channel_id, logging_channel_id, logging_broadcast_url, locked
SELECT id, category_id, ticket_channel_id, logging_channel_id, logging_broadcast_url, ticket_broadcast_url, locked
FROM guild_config
WHERE id = $1;
"""
Expand Down Expand Up @@ -184,17 +197,24 @@ async def setup(self, ctx: RoboContext, *, flags: SetupFlags) -> None:
forum_description = "\n".join(forum_description_content)
forum_tags = [
discord.ForumTag(
name="Question", emoji=discord.PartialEmoji(name="\U00002753")
name="Question",
emoji=discord.PartialEmoji(
name="\U00002753"
), # U+2753 Black Question Mark Ornament
),
discord.ForumTag(
name="Serious", emoji=discord.PartialEmoji(name="\U0001f610")
name="Serious",
emoji=discord.PartialEmoji(name="\U0001f610"), # U+1F610 Neutral Face
),
discord.ForumTag(
name="Private", emoji=discord.PartialEmoji(name="\U0001f512")
name="Private",
emoji=discord.PartialEmoji(name="\U0001f512"), # U+1F512 Lock
),
discord.ForumTag(
name="Resolved",
emoji=discord.PartialEmoji(name="\U00002705"),
emoji=discord.PartialEmoji(
name="\U00002705"
), # U+2705 White Heavy Check Mark
moderated=True,
),
]
Expand Down Expand Up @@ -222,6 +242,9 @@ async def setup(self, ctx: RoboContext, *, flags: SetupFlags) -> None:
default_layout=discord.ForumLayoutType.list_view,
available_tags=forum_tags,
)
tc_webhook = await ticket_channel.create_webhook(
name="Rodhaj User Proxy Webhook", avatar=avatar_bytes
)
except discord.Forbidden:
await ctx.send(
"\N{NO ENTRY SIGN} Rodhaj is missing permissions: Manage Channels and Manage Webhooks"
Expand All @@ -232,8 +255,8 @@ async def setup(self, ctx: RoboContext, *, flags: SetupFlags) -> None:
return

query = """
INSERT INTO guild_config (id, category_id, ticket_channel_id, logging_channel_id, logging_broadcast_url)
VALUES ($1, $2, $3, $4, $5);
INSERT INTO guild_config (id, category_id, ticket_channel_id, logging_channel_id, logging_broadcast_url, ticket_broadcast_url)
VALUES ($1, $2, $3, $4, $5, $6);
"""
try:
await self.pool.execute(
Expand All @@ -243,6 +266,7 @@ async def setup(self, ctx: RoboContext, *, flags: SetupFlags) -> None:
ticket_channel.id,
logging_channel.id,
lgc_webhook.url,
tc_webhook.url,
)
except asyncpg.UniqueViolationError:
await ticket_channel.delete(reason=delete_reason)
Expand Down
Loading

0 comments on commit 92f2972

Please sign in to comment.