From a10c337b3de9426ca5389c85edd7a27f37c1ad53 Mon Sep 17 00:00:00 2001 From: Birger Moell Date: Tue, 13 Dec 2022 23:51:14 +0100 Subject: [PATCH] Lint fixes --- bot/bot.py | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index 1515273b..f3cd1acf 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -52,27 +52,32 @@ intents = discord.Intents.default() intents.message_content = True client = OpenChatGPTClient(intents=intents) + class LikeButton(discord.ui.Button): def __init__(self, label, channel, username, prompt): super().__init__(label=label, style=discord.ButtonStyle.green, emoji="👍") self.channel = channel self.username = username self.prompt = prompt + async def callback(self, interaction): # interaction holds the interaction object - #await interaction.response.defer() + # await interaction.response.defer() await interaction.response.send_message("Thanks for your feedback. You liked this 👍 ") + class NeutralButton(discord.ui.Button): def __init__(self, label, channel, username, prompt): super().__init__(label=label, style=discord.ButtonStyle.green, emoji="😐") self.channel = channel self.username = username self.prompt = prompt + async def callback(self, interaction): # interaction holds the interaction object - #await interaction.response.defer() - await interaction.response.send_message("Thanks for your feedback. You thought this was neutral 😐 ") + # await interaction.response.defer() + await interaction.response.send_message("Thanks for your feedback. You thought this was neutral 😐 ") + class DislikeButton(discord.ui.Button): def __init__(self, label, channel, username, prompt): @@ -80,12 +85,14 @@ class DislikeButton(discord.ui.Button): self.channel = channel self.username = username self.prompt = prompt + async def callback(self, interaction): # interaction holds the interaction object - #await interaction.response.defer() + # await interaction.response.defer() # send the feedback to the backend # await interaction.response.send_message("Thanks for your feedback. You disliked this 👎 ") + @client.tree.command() async def register(interaction: discord.Interaction): """Registers the user for submissions.""" @@ -114,14 +121,14 @@ async def list_participants(interaction: discord.Interaction): async def send_propmt_with_response_and_buttons(channel, username, prompt, response): - await channel.send(f'What do you think about the following interaction: \nprompt: {prompt} \nresponse: {response}') - #await channel.send(f'Please click on the button that best describes your reaction to the response:') + await channel.send(f"What do you think about the following interaction: \nprompt: {prompt} \nresponse: {response}") + # await channel.send(f'Please click on the button that best describes your reaction to the response:') # add buttons view = discord.ui.View() - like=LikeButton(label="Like", channel=channel, username=username, prompt=prompt) - neutral=NeutralButton(label="Neutral", channel=channel, username=username, prompt=prompt) - dislike=DislikeButton(label="Dislike", channel=channel, username=username, prompt=prompt) + like = LikeButton(label="Like", channel=channel, username=username, prompt=prompt) + neutral = NeutralButton(label="Neutral", channel=channel, username=username, prompt=prompt) + dislike = DislikeButton(label="Dislike", channel=channel, username=username, prompt=prompt) view.add_item(item=like) view.add_item(item=neutral) @@ -138,12 +145,13 @@ async def review_prompts(interaction: discord.Interaction, number_of_prompts: in prompts = response.json() print("the responses are", prompts) for prompt in prompts: - await send_propmt_with_response_and_buttons(interaction.channel, interaction.user.name, prompt['prompt'], prompt["response"]) + await send_propmt_with_response_and_buttons( + interaction.channel, interaction.user.name, prompt["prompt"], prompt["response"] + ) else: await interaction.response.send_message("Failed to get prompts for review") - @client.tree.command() async def add_prompt(interaction: discord.Interaction, prompt: str, response: str, language: str = "en"): """Uploads a single prompt to the server.""" @@ -156,9 +164,11 @@ async def add_prompt(interaction: discord.Interaction, prompt: str, response: st } response = requests.post(prompts_url, headers=headers, json=prompt) if response.status_code == 200: - await send_propmt_with_response_and_buttons(interaction.channel, interaction.user.name, prompt['prompt'], prompt["response"]) + await send_propmt_with_response_and_buttons( + interaction.channel, interaction.user.name, prompt["prompt"], prompt["response"] + ) # send the prompt back with buttons for the user to click on - #await interaction.response.send_message("Added your prompt") + # await interaction.response.send_message("Added your prompt") else: await interaction.response.send_message("Failed to add the prompt")