1
- from typing import Optional
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING , Optional
2
4
3
5
import asyncpg
4
6
import discord
5
7
import msgspec
6
8
from async_lru import alru_cache
7
9
from discord .ext import commands
8
10
from libs .utils import RoboContext , is_manager
9
- from rodhaj import Rodhaj
11
+
12
+ if TYPE_CHECKING :
13
+ from rodhaj import Rodhaj
10
14
11
15
UNKNOWN_ERROR_MESSAGE = (
12
16
"An unknown error happened. Please contact the dev team for assistance"
@@ -21,6 +25,7 @@ class GuildConfig(msgspec.Struct):
21
25
ticket_channel_id : int
22
26
logging_channel_id : int
23
27
logging_broadcast_url : str
28
+ ticket_broadcast_url : str
24
29
locked : bool = False
25
30
26
31
@property
@@ -54,10 +59,18 @@ async def get_webhook(self) -> Optional[discord.Webhook]:
54
59
url = conf .logging_broadcast_url , session = self .session
55
60
)
56
61
62
+ async def get_ticket_webhook (self ) -> Optional [discord .Webhook ]:
63
+ conf = await self .get_config ()
64
+ if conf is None :
65
+ return None
66
+ return discord .Webhook .from_url (
67
+ url = conf .ticket_broadcast_url , session = self .session
68
+ )
69
+
57
70
@alru_cache ()
58
71
async def get_config (self ) -> Optional [GuildConfig ]:
59
72
query = """
60
- SELECT id, category_id, ticket_channel_id, logging_channel_id, logging_broadcast_url, locked
73
+ SELECT id, category_id, ticket_channel_id, logging_channel_id, logging_broadcast_url, ticket_broadcast_url, locked
61
74
FROM guild_config
62
75
WHERE id = $1;
63
76
"""
@@ -184,17 +197,24 @@ async def setup(self, ctx: RoboContext, *, flags: SetupFlags) -> None:
184
197
forum_description = "\n " .join (forum_description_content )
185
198
forum_tags = [
186
199
discord .ForumTag (
187
- name = "Question" , emoji = discord .PartialEmoji (name = "\U00002753 " )
200
+ name = "Question" ,
201
+ emoji = discord .PartialEmoji (
202
+ name = "\U00002753 "
203
+ ), # U+2753 Black Question Mark Ornament
188
204
),
189
205
discord .ForumTag (
190
- name = "Serious" , emoji = discord .PartialEmoji (name = "\U0001f610 " )
206
+ name = "Serious" ,
207
+ emoji = discord .PartialEmoji (name = "\U0001f610 " ), # U+1F610 Neutral Face
191
208
),
192
209
discord .ForumTag (
193
- name = "Private" , emoji = discord .PartialEmoji (name = "\U0001f512 " )
210
+ name = "Private" ,
211
+ emoji = discord .PartialEmoji (name = "\U0001f512 " ), # U+1F512 Lock
194
212
),
195
213
discord .ForumTag (
196
214
name = "Resolved" ,
197
- emoji = discord .PartialEmoji (name = "\U00002705 " ),
215
+ emoji = discord .PartialEmoji (
216
+ name = "\U00002705 "
217
+ ), # U+2705 White Heavy Check Mark
198
218
moderated = True ,
199
219
),
200
220
]
@@ -222,6 +242,9 @@ async def setup(self, ctx: RoboContext, *, flags: SetupFlags) -> None:
222
242
default_layout = discord .ForumLayoutType .list_view ,
223
243
available_tags = forum_tags ,
224
244
)
245
+ tc_webhook = await ticket_channel .create_webhook (
246
+ name = "Rodhaj User Proxy Webhook" , avatar = avatar_bytes
247
+ )
225
248
except discord .Forbidden :
226
249
await ctx .send (
227
250
"\N{NO ENTRY SIGN} Rodhaj is missing permissions: Manage Channels and Manage Webhooks"
@@ -232,8 +255,8 @@ async def setup(self, ctx: RoboContext, *, flags: SetupFlags) -> None:
232
255
return
233
256
234
257
query = """
235
- INSERT INTO guild_config (id, category_id, ticket_channel_id, logging_channel_id, logging_broadcast_url)
236
- VALUES ($1, $2, $3, $4, $5);
258
+ INSERT INTO guild_config (id, category_id, ticket_channel_id, logging_channel_id, logging_broadcast_url, ticket_broadcast_url )
259
+ VALUES ($1, $2, $3, $4, $5, $6 );
237
260
"""
238
261
try :
239
262
await self .pool .execute (
@@ -243,6 +266,7 @@ async def setup(self, ctx: RoboContext, *, flags: SetupFlags) -> None:
243
266
ticket_channel .id ,
244
267
logging_channel .id ,
245
268
lgc_webhook .url ,
269
+ tc_webhook .url ,
246
270
)
247
271
except asyncpg .UniqueViolationError :
248
272
await ticket_channel .delete (reason = delete_reason )
0 commit comments