Skip to content

Commit db3f574

Browse files
authored
Fix broken config module (#37)
1 parent 92f2972 commit db3f574

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

bot/cogs/config.py

+15-21
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import msgspec
88
from async_lru import alru_cache
99
from discord.ext import commands
10-
from libs.utils import RoboContext, is_manager
10+
from libs.utils import GuildContext, is_manager
1111

1212
if TYPE_CHECKING:
1313
from rodhaj import Rodhaj
@@ -83,12 +83,12 @@ async def get_config(self) -> Optional[GuildConfig]:
8383

8484

8585
class SetupFlags(commands.FlagConverter):
86-
ticket_name: str = commands.flag(
86+
ticket_name: Optional[str] = commands.flag(
8787
name="ticket_name",
8888
default="tickets",
8989
description="The name of the ticket forum. Defaults to tickets",
9090
)
91-
log_name: str = commands.flag(
91+
log_name: Optional[str] = commands.flag(
9292
name="log_name",
9393
default="rodhaj-logs",
9494
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]:
112112
# Since I don't want to write out every single column to select,
113113
# we are going to use the star
114114
# 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;"
116116
rows = await self.pool.fetchrow(query, guild_id)
117117
if rows is None:
118118
return None
@@ -122,21 +122,18 @@ async def get_guild_config(self, guild_id: int) -> Optional[GuildConfig]:
122122
@is_manager()
123123
@commands.guild_only()
124124
@commands.hybrid_group(name="config")
125-
async def config(self, ctx: RoboContext) -> None:
125+
async def config(self, ctx: GuildContext) -> None:
126126
"""Commands to configure, setup, or delete Rodhaj"""
127127
if ctx.invoked_subcommand is None:
128128
await ctx.send_help(ctx.command)
129129

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:
132132
"""First-time setup for Rodhaj
133133
134134
You only need to run this once
135135
"""
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()
140137
guild_id = ctx.guild.id
141138

142139
dispatcher = GuildWebhookDispatcher(self.bot, guild_id)
@@ -227,13 +224,13 @@ async def setup(self, ctx: RoboContext, *, flags: SetupFlags) -> None:
227224
name="rodhaj", overwrites=rodhaj_overwrites, position=0
228225
)
229226
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
231228
)
232229
lgc_webhook = await logging_channel.create_webhook(
233230
name="Rodhaj Ticket Logs", avatar=avatar_bytes
234231
)
235232
ticket_channel = await rodhaj_category.create_forum(
236-
name=flags.ticket_name,
233+
name=flags.ticket_name or "tickets",
237234
topic=forum_description,
238235
position=1,
239236
reason=forums_reason,
@@ -282,19 +279,16 @@ async def setup(self, ctx: RoboContext, *, flags: SetupFlags) -> None:
282279
await ctx.send(msg)
283280

284281
@config.command(name="delete")
285-
async def delete(self, ctx: RoboContext) -> None:
282+
async def delete(self, ctx: GuildContext) -> None:
286283
"""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()
291285
guild_id = ctx.guild.id
292286

293287
dispatcher = GuildWebhookDispatcher(self.bot, guild_id)
294288
guild_config = await self.get_guild_config(guild_id)
295289

296290
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)
298292
if confirm:
299293
if guild_config is None:
300294
msg = (
@@ -324,11 +318,11 @@ async def delete(self, ctx: RoboContext) -> None:
324318
return
325319

326320
query = """
327-
DELETE FROM guild_config WHERE guild_id = $1;
321+
DELETE FROM guild_config WHERE id = $1;
328322
"""
329323
await self.pool.execute(query, guild_id)
330324
dispatcher.get_config.cache_invalidate()
331-
self.get_guild_config.cache_invalidate()
325+
self.get_guild_config.cache_invalidate(guild_id)
332326
await ctx.send("Successfully deleted channels")
333327
elif confirm is None:
334328
await ctx.send("Not removing Rodhaj channels. Canceling.")

bot/libs/utils/context.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,15 @@ def __init__(self, **kwargs):
6464
self.partial_config = self.bot.partial_config
6565

6666
async def prompt(
67-
self, message: str, *, timeout: float = 60.0, delete_after: bool = False
67+
self,
68+
message: str,
69+
*,
70+
timeout: float = 60.0,
71+
ephemeral: bool = False,
72+
delete_after: bool = False,
6873
) -> Optional[bool]:
6974
view = ConfirmationView(ctx=self, timeout=timeout, delete_after=delete_after)
70-
view.message = await self.send(message, view=view, ephemeral=delete_after)
75+
view.message = await self.send(message, view=view, ephemeral=ephemeral)
7176
await view.wait()
7277
return view.value
7378

0 commit comments

Comments
 (0)