7
7
import msgspec
8
8
from async_lru import alru_cache
9
9
from discord .ext import commands
10
- from libs .utils import RoboContext , is_manager
10
+ from libs .utils import GuildContext , is_manager
11
11
12
12
if TYPE_CHECKING :
13
13
from rodhaj import Rodhaj
@@ -83,12 +83,12 @@ async def get_config(self) -> Optional[GuildConfig]:
83
83
84
84
85
85
class SetupFlags (commands .FlagConverter ):
86
- ticket_name : str = commands .flag (
86
+ ticket_name : Optional [ str ] = commands .flag (
87
87
name = "ticket_name" ,
88
88
default = "tickets" ,
89
89
description = "The name of the ticket forum. Defaults to tickets" ,
90
90
)
91
- log_name : str = commands .flag (
91
+ log_name : Optional [ str ] = commands .flag (
92
92
name = "log_name" ,
93
93
default = "rodhaj-logs" ,
94
94
description = "The name of the logging channel. Defaults to rodhaj-logs" ,
@@ -112,7 +112,7 @@ async def get_guild_config(self, guild_id: int) -> Optional[GuildConfig]:
112
112
# Since I don't want to write out every single column to select,
113
113
# we are going to use the star
114
114
# The guild config roughly maps to it as well
115
- query = "SELECT * FROM guild_config WHERE guild_id = $1;"
115
+ query = "SELECT * FROM guild_config WHERE id = $1;"
116
116
rows = await self .pool .fetchrow (query , guild_id )
117
117
if rows is None :
118
118
return None
@@ -122,21 +122,18 @@ async def get_guild_config(self, guild_id: int) -> Optional[GuildConfig]:
122
122
@is_manager ()
123
123
@commands .guild_only ()
124
124
@commands .hybrid_group (name = "config" )
125
- async def config (self , ctx : RoboContext ) -> None :
125
+ async def config (self , ctx : GuildContext ) -> None :
126
126
"""Commands to configure, setup, or delete Rodhaj"""
127
127
if ctx .invoked_subcommand is None :
128
128
await ctx .send_help (ctx .command )
129
129
130
- @config .command (name = "setup" )
131
- async def setup (self , ctx : RoboContext , * , flags : SetupFlags ) -> None :
130
+ @config .command (name = "setup" , usage = "ticket_name: <str> log_name: <str>" )
131
+ async def setup (self , ctx : GuildContext , * , flags : SetupFlags ) -> None :
132
132
"""First-time setup for Rodhaj
133
133
134
134
You only need to run this once
135
135
"""
136
- if ctx .guild is None :
137
- await ctx .send ("Really? You can't set this up in DMs" )
138
- return
139
-
136
+ await ctx .defer ()
140
137
guild_id = ctx .guild .id
141
138
142
139
dispatcher = GuildWebhookDispatcher (self .bot , guild_id )
@@ -227,13 +224,13 @@ async def setup(self, ctx: RoboContext, *, flags: SetupFlags) -> None:
227
224
name = "rodhaj" , overwrites = rodhaj_overwrites , position = 0
228
225
)
229
226
logging_channel = await rodhaj_category .create_text_channel (
230
- name = flags .log_name , reason = lgc_reason , position = 0
227
+ name = flags .log_name or "rodhaj-logs" , reason = lgc_reason , position = 0
231
228
)
232
229
lgc_webhook = await logging_channel .create_webhook (
233
230
name = "Rodhaj Ticket Logs" , avatar = avatar_bytes
234
231
)
235
232
ticket_channel = await rodhaj_category .create_forum (
236
- name = flags .ticket_name ,
233
+ name = flags .ticket_name or "tickets" ,
237
234
topic = forum_description ,
238
235
position = 1 ,
239
236
reason = forums_reason ,
@@ -282,19 +279,16 @@ async def setup(self, ctx: RoboContext, *, flags: SetupFlags) -> None:
282
279
await ctx .send (msg )
283
280
284
281
@config .command (name = "delete" )
285
- async def delete (self , ctx : RoboContext ) -> None :
282
+ async def delete (self , ctx : GuildContext ) -> None :
286
283
"""Permanently deletes Rodhaj channels and tickets."""
287
- if ctx .guild is None :
288
- await ctx .send ("Really... This module is meant to be ran in a server" )
289
- return
290
-
284
+ await ctx .defer ()
291
285
guild_id = ctx .guild .id
292
286
293
287
dispatcher = GuildWebhookDispatcher (self .bot , guild_id )
294
288
guild_config = await self .get_guild_config (guild_id )
295
289
296
290
msg = "Are you really sure that you want to delete the Rodhaj channels?"
297
- confirm = await ctx .prompt (msg , timeout = 300.0 )
291
+ confirm = await ctx .prompt (msg , timeout = 300.0 , delete_after = True )
298
292
if confirm :
299
293
if guild_config is None :
300
294
msg = (
@@ -324,11 +318,11 @@ async def delete(self, ctx: RoboContext) -> None:
324
318
return
325
319
326
320
query = """
327
- DELETE FROM guild_config WHERE guild_id = $1;
321
+ DELETE FROM guild_config WHERE id = $1;
328
322
"""
329
323
await self .pool .execute (query , guild_id )
330
324
dispatcher .get_config .cache_invalidate ()
331
- self .get_guild_config .cache_invalidate ()
325
+ self .get_guild_config .cache_invalidate (guild_id )
332
326
await ctx .send ("Successfully deleted channels" )
333
327
elif confirm is None :
334
328
await ctx .send ("Not removing Rodhaj channels. Canceling." )
0 commit comments