Skip to content

Commit

Permalink
Merge pull request #254 from lyon-esport/hotfix/slashcommand-defer
Browse files Browse the repository at this point in the history
Added defer() to every hybrid_command functions (Fix for #244)
  • Loading branch information
M0NsTeRRR authored Jun 10, 2023
2 parents 620fa9f + a0c9ecf commit 5d10995
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions les_louisdelatech/extensions/cats.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, bot):

@commands.hybrid_command(name="cat", help="Get cat")
async def get_cat(self, ctx: Context):
await ctx.defer()
async with httpx.AsyncClient() as client:
cat_data = await client.get("https://api.thecatapi.com/v1/images/search")

Expand Down
1 change: 1 addition & 0 deletions les_louisdelatech/extensions/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def __init__(self, bot):

@commands.hybrid_command(name="gteams", help="Get available teams")
async def get_teams(self, ctx):
await ctx.defer()
message = "Available roles :\n```"

for team in self.bot.config["teams"]:
Expand Down
1 change: 1 addition & 0 deletions les_louisdelatech/extensions/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ async def topic(
ctx,
description: str = commands.parameter(description="Topic description"),
):
await ctx.defer()
await ctx.channel.edit(topic=description)
await ctx.send("Channel topic updated")

Expand Down
4 changes: 4 additions & 0 deletions les_louisdelatech/extensions/otp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(self, bot):
@commands.guild_only()
@is_team_allowed
async def list_otp(self, ctx):
await ctx.defer()
try:
user = User(
search_user(self.bot.admin_sdk(), ctx.author.name, ctx.author.id)
Expand Down Expand Up @@ -50,6 +51,7 @@ async def list_otp(self, ctx):
async def get_otp(
self, ctx, name: str = commands.parameter(description="Otp name")
):
await ctx.defer()
try:
user = User(
search_user(self.bot.admin_sdk(), ctx.author.name, ctx.author.id)
Expand Down Expand Up @@ -87,6 +89,7 @@ async def create_otp(
digits: str = commands.parameter(description="Otp digits"),
secret: str = commands.parameter(description="Otp secret"),
):
await ctx.defer()
await ctx.message.delete()

try:
Expand Down Expand Up @@ -117,6 +120,7 @@ async def create_otp(
async def delete_otp(
self, ctx, name: str = commands.parameter(description="Otp name")
):
await ctx.defer()
try:
user = User(
search_user(self.bot.admin_sdk(), ctx.author.name, ctx.author.id)
Expand Down
7 changes: 7 additions & 0 deletions les_louisdelatech/extensions/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ async def provision(
[Google]
=> User will be created and added to team group
"""
await ctx.defer()
user_email = User.email_from_name(firstname, lastname)
user_team = self.bot.config["teams"].get(role_name, None)
password = generate_password()
Expand Down Expand Up @@ -165,6 +166,7 @@ async def deprovision(
[Google]
=> User will be suspended
"""
await ctx.defer()
try:
user = User(search_user(self.bot.admin_sdk(), member.name, member.id))
is_user_managed(
Expand Down Expand Up @@ -205,6 +207,7 @@ async def update_team(
=> User will be added to this new team
=> User signature will be updated
"""
await ctx.defer()
try:
user = User(search_user(self.bot.admin_sdk(), member.name, member.id))
is_user_managed(
Expand Down Expand Up @@ -292,6 +295,7 @@ async def update_pseudo(
[Google]
=> User pseudo will be renamed
"""
await ctx.defer()
try:
user = User(search_user(self.bot.admin_sdk(), member.name, member.id))
is_user_managed(
Expand Down Expand Up @@ -329,6 +333,7 @@ async def update_pseudo(
@commands.guild_only()
@is_gsuite_admin
async def update_signatures(self, ctx):
await ctx.defer()
user_updated = 0
try:
users = get_users(self.bot.admin_sdk())
Expand Down Expand Up @@ -382,6 +387,7 @@ async def urecovery(
member: discord.Member = commands.parameter(description="Discord user"),
backup_email: str = commands.parameter(description="User backup email"),
):
await ctx.defer()
try:
user = User(search_user(self.bot.admin_sdk(), member.name, member.id))
is_user_managed(
Expand Down Expand Up @@ -409,6 +415,7 @@ async def rpassword(
ctx,
member: discord.Member = commands.parameter(description="Discord user"),
):
await ctx.defer()
try:
user = User(search_user(self.bot.admin_sdk(), member.name, member.id))
is_user_managed(
Expand Down

0 comments on commit 5d10995

Please sign in to comment.