diff --git a/cogs/edgegpt.py b/cogs/edgegpt.py index 9d9eabf..287b138 100644 --- a/cogs/edgegpt.py +++ b/cogs/edgegpt.py @@ -5,6 +5,7 @@ from core.classes import Cog_Extension from src.log import setup_logger from src.user_chatbot import set_chatbot, get_users_chatbot +from src.check_channel import check_channel from dotenv import load_dotenv load_dotenv() @@ -20,10 +21,9 @@ class EdgeGPT(Cog_Extension): @cookies_group.command(name="setting", description="can set personal Copilot cookies, no mandatory setting.") async def cookies_setting(self, interaction: discord.Interaction, *, cookies_file: discord.Attachment): await interaction.response.defer(thinking=True) - allowed_channel_id = os.getenv("COOKIES_SETTING_CHANNEL_ID") - if allowed_channel_id and int(allowed_channel_id) != interaction.channel_id: - await interaction.followup.send(f"> **Command can only used on <#{allowed_channel_id}>**") + if not await check_channel(interaction, "COOKIES_SETTING_CHANNEL_ID"): return + user_id = interaction.user.id try: if "json" in cookies_file.content_type or "text" in cookies_file.content_type: @@ -48,10 +48,9 @@ async def cookies_setting(self, interaction: discord.Interaction, *, cookies_fil @dalle3_group.command(name="setting", description="Set unofficial DALLE-3 api key") async def dalle3_setting(self, interaction: discord.Interaction, api_key: str): await interaction.response.defer(thinking=True, ephemeral=True) - allowed_channel_id = os.getenv("DALLE3_SETTING_CHANNEL_ID") - if allowed_channel_id and int(allowed_channel_id) != interaction.channel_id: - await interaction.followup.send(f"> **Command can only used on <#{allowed_channel_id}>**") + if not await check_channel(interaction, "DALLE3_SETTING_CHANNEL_ID"): return + await set_chatbot(interaction.user.id, dalle3_apikey=api_key) await interaction.followup.send("> **Setting success!**") @@ -64,10 +63,9 @@ async def dalle3_setting(self, interaction: discord.Interaction, api_key: str): async def chat(self, interaction: discord.Interaction, version: app_commands.Choice[str], style: app_commands.Choice[str], type: app_commands.Choice[str], plugin: app_commands.Choice[str]=None): await interaction.response.defer(thinking=True) - allowed_channel_id = os.getenv("CHAT_CHANNEL_ID") - if allowed_channel_id and int(allowed_channel_id) != interaction.channel_id: - await interaction.followup.send(f"> **Command can only used on <#{allowed_channel_id}>**") + if not await check_channel(interaction, "CHAT_CHANNEL_ID"): return + if isinstance(interaction.channel, discord.Thread): await interaction.followup.send("> **This command is disabled in thread.**") return @@ -105,10 +103,9 @@ async def chat(self, interaction: discord.Interaction, version: app_commands.Cho @app_commands.choices(service=[app_commands.Choice(name="DALLE-3", value="dalle-3"), app_commands.Choice(name="Bing Image Creator", value="bing_image_creator")]) async def create_image(self, interaction: discord.Interaction, *, service: app_commands.Choice[str], prompt: str): await interaction.response.defer(thinking=True) - allowed_channel_id = os.getenv("CREATE_IMAGE_CHANNEL_ID") - if allowed_channel_id and int(allowed_channel_id) != interaction.channel_id: - await interaction.followup.send(f"> **Command can only used on <#{allowed_channel_id}>**") + if not await check_channel(interaction, "CREATE_IMAGE_CHANNEL_ID"): return + users_chatbot = get_users_chatbot() user_id = interaction.user.id if user_id not in users_chatbot: @@ -119,10 +116,9 @@ async def create_image(self, interaction: discord.Interaction, *, service: app_c @reset_group.command(name="conversation", description="Reset bing chatbot conversation.") async def reset_conversation(self, interaction: discord.Interaction): await interaction.response.defer(thinking=True) - allowed_channel_id = os.getenv("RESET_CHAT_CHANNEL_ID") - if allowed_channel_id and int(allowed_channel_id) != interaction.channel_id: - await interaction.followup.send(f"> **Command can only used on <#{allowed_channel_id}>**") + if not await check_channel(interaction, "RESET_CHAT_CHANNEL_ID"): return + users_chatbot = get_users_chatbot() user_id = interaction.user.id diff --git a/cogs/help.py b/cogs/help.py index 155dbbd..1d2f635 100644 --- a/cogs/help.py +++ b/cogs/help.py @@ -2,6 +2,7 @@ import os from core.classes import Cog_Extension from discord import app_commands +from src.check_channel import check_channel from dotenv import load_dotenv load_dotenv() @@ -9,10 +10,9 @@ class Help(Cog_Extension): @app_commands.command(name = "help", description = "Show how to use") async def help(self, interaction: discord.Interaction): - allowed_channel_id = os.getenv("HELP_CMD_CHANNEL_ID") - if allowed_channel_id and int(allowed_channel_id) != interaction.channel_id: - await interaction.response.send_message(f"> **Command can only used on <#{allowed_channel_id}>**", ephemeral=True) + if not await check_channel(interaction, "HELP_CMD_CHANNEL_ID"): return + embed=discord.Embed(description="[FuseFairy/DiscordBot-EdgeGPT](https://github.com/FuseFairy/DiscordBot-EdgeGPT/blob/main/README.md)\n***COMMANDS -***") embed.add_field(name="/cookies setting", value="Can upload own cookies.", inline=False) embed.add_field(name="/dalle3 setting", value="Can upload own api key, api key can get from https://dalle.feiyuyu.net/dashboard.", inline=False)