From 2c23b8e5e658c8abe1ec74090d12da8d35b8a1e0 Mon Sep 17 00:00:00 2001 From: Yuki Joou Date: Sun, 26 Feb 2023 02:16:25 +0100 Subject: [PATCH] main+interaction_views: Moved interaction views to a separate file --- interaction_views.py | 47 +++++++++++++++++++++++++++++++++++++++ main.py | 52 ++++---------------------------------------- 2 files changed, 51 insertions(+), 48 deletions(-) create mode 100644 interaction_views.py diff --git a/interaction_views.py b/interaction_views.py new file mode 100644 index 0000000..9b2e8f6 --- /dev/null +++ b/interaction_views.py @@ -0,0 +1,47 @@ +import discord + + +class MariageConfirmationView(discord.ui.View): + def __init__(self, target: discord.Member): + super().__init__() + self.timeout = None + self.marriage_accepted: bool | None = None + self.target = target + + @discord.ui.button(label="Accept", style=discord.ButtonStyle.green, row=1) + async def accept(self, _: discord.ui.Button, interaction: discord.Interaction): + if interaction.user != self.target: + print(interaction.user, self.target) + await interaction.response.send_message( + "ur not the one getting married, silly :3" + ) + return + + user_who_replied = interaction.user + mention = user_who_replied.mention \ + if user_who_replied is not None else "" + await interaction.response.send_message( + f"{mention} accepted the proposal :3 lovely" + ) + + self.marriage_accepted = True + self.stop() + + @discord.ui.button(label="Deny", style=discord.ButtonStyle.red, row=1) + async def deny(self, _: discord.ui.Button, interaction: discord.Interaction): + if interaction.user != self.target: + await interaction.response.send_message( + "ur not the one getting married, silly :3" + ) + return + + user_who_replied = interaction.user + mention = user_who_replied.mention \ + if user_who_replied is not None else "" + + await interaction.response.send_message( + f"{mention} didn't wanna get married yet..." + ) + + self.marriage_accepted = False + self.stop() diff --git a/main.py b/main.py index 4cb0f63..0760a07 100755 --- a/main.py +++ b/main.py @@ -5,6 +5,7 @@ import json import random import data_manager +import interaction_views intents = discord.Intents.default() intents.message_content = True @@ -56,53 +57,6 @@ def __find_mariage_for_member_id(member_id: int) -> list[int]: return [] -# Interraction views - - -class MariageConfirmationView(discord.ui.View): - def __init__(self, target: discord.Member): - super().__init__() - self.timeout = None - self.marriage_accepted: bool | None = None - self.target = target - - @discord.ui.button(label="Accept", style=discord.ButtonStyle.green, row=1) - async def accept(self, _: discord.ui.Button, interaction: discord.Interaction): - if interaction.user != self.target: - print(interaction.user, self.target) - await interaction.response.send_message( - "ur not the one getting married, silly :3" - ) - return - - user_who_replied = interaction.user - mention = user_who_replied.mention \ - if user_who_replied is not None else "" - await interaction.response.send_message( - f"{mention} accepted the proposal :3 lovely" - ) - - self.marriage_accepted = True - self.stop() - - @discord.ui.button(label="Deny", style=discord.ButtonStyle.red, row=1) - async def deny(self, _: discord.ui.Button, interaction: discord.Interaction): - if interaction.user != self.target: - await interaction.response.send_message( - "ur not the one getting married, silly :3" - ) - return - - user_who_replied = interaction.user - mention = user_who_replied.mention \ - if user_who_replied is not None else "" - - await interaction.response.send_message( - f"{mention} didn't wanna get married yet..." - ) - - self.marriage_accepted = False - self.stop() # Slash commands @@ -123,7 +77,9 @@ async def marry( await context.respond("ow :/ something went wonky wonky, try again!") return - marriage_confirmation = MariageConfirmationView(member_to_marry) + marriage_confirmation = interaction_views.MariageConfirmationView( + member_to_marry + ) await context.respond( f"{member_to_marry.mention}, would you like to marry" + f" {marriage_asker.mention}?", view=marriage_confirmation)