Compare commits

...

10 commits

Author SHA1 Message Date
e617a04d81 main: Added divorce command
because its better to be good friends than angry lovers :3
2023-08-09 18:28:20 +02:00
2217afffed main: Made marriage display more readable 2023-08-09 18:28:20 +02:00
64d13998cf main: Disable view items when the views aren't needed anymore 2023-08-09 18:28:20 +02:00
c16962a7c7 main: Fixup marriage denial not stopping marriage 2023-08-09 18:28:20 +02:00
57695654d9 main: Added marriage checking command 2023-08-09 18:28:20 +02:00
fb1fabea0a main: Made /marry target required 2023-08-09 18:28:20 +02:00
b2eceb0edc main: Added support for poly marriage
This commit also adds a PolyculeMemberJoinConfirmationView for
consenting with other polycule members
2023-08-09 18:28:20 +02:00
2ad16a8234 main: Fixed a typo/bug in /marry 2023-08-09 18:28:20 +02:00
56d93e6d11 interaction_views: Added timeout for marriage confirmation 2023-08-09 18:28:20 +02:00
7ccebd1c1c main: Check for marriage before trying to marry people 2023-08-09 18:28:20 +02:00
2 changed files with 160 additions and 12 deletions

View file

@ -50,7 +50,7 @@ class ConfirmationView(discord.ui.View):
class MariageConfirmationView(ConfirmationView):
def __init__(self, target: discord.Member):
super().__init__(timeout=None)
super().__init__(timeout=15*60) # 15 minues timeout
self.target = target
def _user_can_respond(self, user: discord.User | discord.Member):
@ -70,3 +70,27 @@ class MariageConfirmationView(ConfirmationView):
await interaction.response.send_message(
f"{replyer.mention} isn't ready yet..."
)
class PolyculeMemberJoinConfirmationView(ConfirmationView):
def __init__(self, target: discord.User):
super().__init__(timeout=15*60)
self.target = target
def _user_can_respond(self, user: discord.User | discord.Member):
return user == self.target
async def _on_wrong_user(self, interaction: discord.Interaction):
await interaction.response.send_message(
"ur not the one getting married, silly :3", ephemeral=True, delete_after=10
)
async def _on_accept(self, interaction: discord.Interaction, replyer: discord.User | discord.Member):
await interaction.response.send_message(
f"{replyer.mention} is okay for extending the polycule :3 kawaii desune~"
)
async def _on_deny(self, interaction: discord.Interaction, replyer: discord.User | discord.Member):
await interaction.response.send_message(
f"{replyer.mention} isn't ready yet..."
)

146
main.py
View file

@ -39,6 +39,7 @@ Slash commands:
```
/help - Shows this message
/marry - Marries someone
/marriage - Shows marriage information
```
"""
@ -60,23 +61,90 @@ def __find_mariage_for_member_id(member_id: int) -> list[int]:
# Slash commands
@bot.slash_command()
@discord.guild_only()
async def divorce(context: discord.ApplicationContext):
if context.user is None:
await context.respond("error uwu", ephemeral=True)
return
user_marriage = __find_mariage_for_member_id(context.user.id)
if len(user_marriage) <= 0:
await context.respond("you can't divorce if you're not married, silly :3")
return
data = data_manager.get_data()
if len(user_marriage) <= 2:
data["marriages"].remove(user_marriage)
with data_manager.DataWriter() as writer:
writer.set_data(data)
await context.respond(f"things didn't work out, and {context.user.mention} choose to divorce")
return
# Is polycule
new_polycule = user_marriage.copy()
new_polycule.remove(context.user.id)
data["marriages"].remove(user_marriage)
data["marriages"].append(new_polycule)
with data_manager.DataWriter() as writer:
writer.set_data(data)
await context.respond(f"{context.user.mention} has taken the decision to step away from the polycule")
@bot.slash_command()
@discord.guild_only()
@discord.option(
"target", type=discord.Member,
description="User whos marraige you want to check",
required=False,
)
async def marriage(
context: discord.ApplicationContext, target: discord.Member | None
):
who_to_check = target if target is not None else context.user
if who_to_check is None:
await context.respond("failed to get target!", ephemeral=True)
return
marriage = __find_mariage_for_member_id(who_to_check.id)
if len(marriage) <= 0:
await context.respond(f"{who_to_check.mention} is not married yet :(")
return
marriage_formatted = ' 💞 '.join(
[f"<@{user}>" for user in marriage]
)
await context.respond(marriage_formatted)
@bot.slash_command()
@discord.guild_only()
@discord.option(
"target", type=discord.Member,
description="Which user to marry",
required=False,
required=True,
)
async def marry(
context: discord.ApplicationContext, member_to_marry: discord.Member
):
# TODO: Refactor marriage system
# This function is massive, it should be split up, and probably in another file!
# Check if the person asked in mariage is interested
marriage_asker = context.author
if marriage_asker is None:
await context.respond("ow :/ something went wonky wonky, try again!")
return
askers_marriage = __find_mariage_for_member_id(marriage_asker.id)
askees_marriage = __find_mariage_for_member_id(member_to_marry.id)
if member_to_marry.id in askers_marriage: # Already married
await context.respond(f"u are already married to {member_to_marry.mention}, silly!")
return
marriage_confirmation = interaction_views.MariageConfirmationView(
member_to_marry
)
@ -85,6 +153,9 @@ async def marry(
+ f" {marriage_asker.mention}?", view=marriage_confirmation)
await marriage_confirmation.wait()
marriage_confirmation.disable_all_items()
if marriage_confirmation.user_accepted is None:
await context.respond("silly little bug going on :3 try again l8er :3")
return
@ -93,13 +164,11 @@ async def marry(
await context.respond(
"no consent == no marriage! consent is key to a happy life :3"
)
return
# Marriage was accepted, yay :3!
askers_marriage = __find_mariage_for_member_id(marriage_asker.id)
askees_marriage = __find_mariage_for_member_id(member_to_marry.id)
# Now check for polycules
if len(askees_marriage) == 0 and len(askers_marriage) == 0:
if len(askers_marriage) == 0 and len(askees_marriage) == 0:
# No polycules, just update the records to marry the two :3
data = data_manager.get_data()
data["marriages"].append([marriage_asker.id, member_to_marry.id])
@ -109,14 +178,69 @@ async def marry(
await context.respond(
f"{marriage_asker.mention} married {member_to_marry.mention}"
)
return
await context.respond(
"ooh looks like you're trying to do a ploly marriage..." +
" unfortunately, that's still a work in progress," +
" come back later to register it :3"
)
users_who_confirmed_the_marriage = [marriage_asker.id, member_to_marry.id]
users_who_need_to_allow_marriage = askees_marriage
users_who_need_to_allow_marriage += askers_marriage
for user_to_ask in users_who_need_to_allow_marriage:
if user_to_ask in users_who_confirmed_the_marriage:
continue
user_to_ask_as_member = await bot.fetch_user(user_to_ask)
polycule_confirmation_view = interaction_views.PolyculeMemberJoinConfirmationView(
user_to_ask_as_member)
member_to_add_to_polycule = member_to_marry if member_to_marry.id not in __find_mariage_for_member_id(
user_to_ask) else marriage_asker
await context.respond(
f"{user_to_ask_as_member.mention}, do you agree to adding "
+ f"{member_to_add_to_polycule.mention} to the polycule?",
view=polycule_confirmation_view
)
await polycule_confirmation_view.wait()
polycule_confirmation_view.disable_all_items()
if polycule_confirmation_view.user_accepted is None:
await context.respond("you hit a bug owo. nothing i can do, try again!")
return
if polycule_confirmation_view.user_accepted == False:
await context.respond(f"seems like {user_to_ask_as_member} doesn't want " +
"to take new people in the polycule yet... can't proceed with mariage")
return
users_who_confirmed_the_marriage.append(user_to_ask)
# Everyone agrees, let's register the marriage
data = data_manager.get_data()
# Disband existing marriages with members of the new polycule to avoid issues
id_of_marriages_to_disband = []
for index, marriage in enumerate(data["marriages"]):
for user in users_who_confirmed_the_marriage:
if user in marriage:
id_of_marriages_to_disband.append(index)
for i in id_of_marriages_to_disband:
if len(data["marriages"]) <= 0:
# No marriages left, so nothing to disband!
break
data["marriages"].pop(i)
# Register the new marriage
data["marriages"].append(users_who_confirmed_the_marriage)
with data_manager.DataWriter() as writer:
writer.set_data(data)
formated_polycule_list = '\n'.join(
[f"- <@{user_id}>" for user_id in users_who_confirmed_the_marriage])
await context.respond(f"woo! a new polycule was formed! members:\n{formated_polycule_list}")
@bot.slash_command()