forked from kemonomimi/nyabot
main+interaction_views: Moved interaction views to a separate file
This commit is contained in:
parent
95139026e5
commit
2c23b8e5e6
2 changed files with 51 additions and 48 deletions
47
interaction_views.py
Normal file
47
interaction_views.py
Normal file
|
@ -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 "<something went wrong :‹>"
|
||||||
|
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 "<something went wrong :‹>"
|
||||||
|
|
||||||
|
await interaction.response.send_message(
|
||||||
|
f"{mention} didn't wanna get married yet..."
|
||||||
|
)
|
||||||
|
|
||||||
|
self.marriage_accepted = False
|
||||||
|
self.stop()
|
52
main.py
52
main.py
|
@ -5,6 +5,7 @@ import json
|
||||||
import random
|
import random
|
||||||
|
|
||||||
import data_manager
|
import data_manager
|
||||||
|
import interaction_views
|
||||||
|
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
intents.message_content = True
|
intents.message_content = True
|
||||||
|
@ -56,53 +57,6 @@ def __find_mariage_for_member_id(member_id: int) -> list[int]:
|
||||||
|
|
||||||
return []
|
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 "<something went wrong :‹>"
|
|
||||||
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 "<something went wrong :‹>"
|
|
||||||
|
|
||||||
await interaction.response.send_message(
|
|
||||||
f"{mention} didn't wanna get married yet..."
|
|
||||||
)
|
|
||||||
|
|
||||||
self.marriage_accepted = False
|
|
||||||
self.stop()
|
|
||||||
|
|
||||||
# Slash commands
|
# Slash commands
|
||||||
|
|
||||||
|
@ -123,7 +77,9 @@ async def marry(
|
||||||
await context.respond("ow :/ something went wonky wonky, try again!")
|
await context.respond("ow :/ something went wonky wonky, try again!")
|
||||||
return
|
return
|
||||||
|
|
||||||
marriage_confirmation = MariageConfirmationView(member_to_marry)
|
marriage_confirmation = interaction_views.MariageConfirmationView(
|
||||||
|
member_to_marry
|
||||||
|
)
|
||||||
await context.respond(
|
await context.respond(
|
||||||
f"{member_to_marry.mention}, would you like to marry"
|
f"{member_to_marry.mention}, would you like to marry"
|
||||||
+ f" {marriage_asker.mention}?", view=marriage_confirmation)
|
+ f" {marriage_asker.mention}?", view=marriage_confirmation)
|
||||||
|
|
Loading…
Reference in a new issue