Added leave pretend to be blank to disable

This commit is contained in:
Paillat
2022-12-10 17:51:36 +01:00
parent 4ed74758ce
commit a496fa1889

View File

@@ -127,7 +127,7 @@ class Settings (discord.Cog) :
#when someone mentions the bot, check if the guild is in the database and if the bot is enabled. If it is, send a message answering the mention #when someone mentions the bot, check if the guild is in the database and if the bot is enabled. If it is, send a message answering the mention
@discord.slash_command(name="pretend", description="Make the bot pretend to be someone else") @discord.slash_command(name="pretend", description="Make the bot pretend to be someone else")
@discord.option(name="pretend to be...", description="The person/thing you want the bot to pretend to be", required=True) @discord.option(name="pretend to be...", description="The person/thing you want the bot to pretend to be. Leave blank to disable pretend mode", required=False)
async def pretend(self, ctx: discord.ApplicationContext, pretend_to_be: str): async def pretend(self, ctx: discord.ApplicationContext, pretend_to_be: str):
debug(f"The user {ctx.author} ran the pretend command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}") debug(f"The user {ctx.author} ran the pretend command in the channel {ctx.channel} of the guild {ctx.guild}, named {ctx.guild.name}")
#check if the guild is in the database #check if the guild is in the database
@@ -140,23 +140,22 @@ class Settings (discord.Cog) :
if c.fetchone()[3] == 0: if c.fetchone()[3] == 0:
await ctx.respond("The bot is disabled", ephemeral=True) await ctx.respond("The bot is disabled", ephemeral=True)
return return
#enable pretend if it is not enabled, and disable it if it is if pretend_to_be is None:
c.execute("SELECT pretend_enabled FROM data WHERE guild_id = ?", (ctx.guild.id,)) pretend_to_be = ""
if c.fetchone()[0] == 1:
c.execute("UPDATE data SET pretend_enabled = 0 WHERE guild_id = ?", (ctx.guild.id,)) c.execute("UPDATE data SET pretend_enabled = 0 WHERE guild_id = ?", (ctx.guild.id,))
conn.commit() conn.commit()
await ctx.respond("Pretend mode disabled", ephemeral=True) await ctx.respond("Pretend mode disabled", ephemeral=True)
botuser = await self.bot.fetch_user(self.bot.user.id)
await ctx.guild.me.edit(nick=None) await ctx.guild.me.edit(nick=None)
return
else: else:
c.execute("UPDATE data SET pretend_enabled = 1 WHERE guild_id = ?", (ctx.guild.id,)) c.execute("UPDATE data SET pretend_enabled = 1 WHERE guild_id = ?", (ctx.guild.id,))
conn.commit() conn.commit()
await ctx.respond("Pretend mode enabled", ephemeral=True) await ctx.respond("Pretend mode enabled", ephemeral=True)
#change the bots name on the server wit ctx.guild.me.edit(nick=pretend_to_be) #change the bots name on the server wit ctx.guild.me.edit(nick=pretend_to_be)
await ctx.guild.me.edit(nick=pretend_to_be) ctx.guild.me.edit(nick=pretend_to_be)
#save the pretend_to_be value c.execute("UPDATE data SET pretend_to_be = ? WHERE guild_id = ?", (pretend_to_be, ctx.guild.id))
c.execute("UPDATE data SET pretend_to_be = ? WHERE guild_id = ?", (pretend_to_be, ctx.guild.id)) conn.commit()
conn.commit() return
@discord.slash_command(name="enable_tts", description="Enable TTS when chatting") @discord.slash_command(name="enable_tts", description="Enable TTS when chatting")
async def enable_tts(self, ctx: discord.ApplicationContext): async def enable_tts(self, ctx: discord.ApplicationContext):