Compare commits
10 commits
e0ce83c671
...
e617a04d81
Author | SHA1 | Date | |
---|---|---|---|
e617a04d81 | |||
2217afffed | |||
64d13998cf | |||
c16962a7c7 | |||
57695654d9 | |||
fb1fabea0a | |||
b2eceb0edc | |||
2ad16a8234 | |||
56d93e6d11 | |||
7ccebd1c1c |
2 changed files with 160 additions and 12 deletions
|
@ -50,7 +50,7 @@ class ConfirmationView(discord.ui.View):
|
||||||
|
|
||||||
class MariageConfirmationView(ConfirmationView):
|
class MariageConfirmationView(ConfirmationView):
|
||||||
def __init__(self, target: discord.Member):
|
def __init__(self, target: discord.Member):
|
||||||
super().__init__(timeout=None)
|
super().__init__(timeout=15*60) # 15 minues timeout
|
||||||
self.target = target
|
self.target = target
|
||||||
|
|
||||||
def _user_can_respond(self, user: discord.User | discord.Member):
|
def _user_can_respond(self, user: discord.User | discord.Member):
|
||||||
|
@ -70,3 +70,27 @@ class MariageConfirmationView(ConfirmationView):
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
f"{replyer.mention} isn't ready yet..."
|
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
146
main.py
|
@ -39,6 +39,7 @@ Slash commands:
|
||||||
```
|
```
|
||||||
/help - Shows this message
|
/help - Shows this message
|
||||||
/marry - Marries someone
|
/marry - Marries someone
|
||||||
|
/marriage - Shows marriage information
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -60,23 +61,90 @@ def __find_mariage_for_member_id(member_id: int) -> list[int]:
|
||||||
|
|
||||||
# Slash commands
|
# 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()
|
@bot.slash_command()
|
||||||
@discord.guild_only()
|
@discord.guild_only()
|
||||||
@discord.option(
|
@discord.option(
|
||||||
"target", type=discord.Member,
|
"target", type=discord.Member,
|
||||||
description="Which user to marry",
|
description="Which user to marry",
|
||||||
required=False,
|
required=True,
|
||||||
)
|
)
|
||||||
async def marry(
|
async def marry(
|
||||||
context: discord.ApplicationContext, member_to_marry: discord.Member
|
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
|
# Check if the person asked in mariage is interested
|
||||||
marriage_asker = context.author
|
marriage_asker = context.author
|
||||||
if marriage_asker is None:
|
if marriage_asker is None:
|
||||||
await context.respond("ow :/ something went wonky wonky, try again!")
|
await context.respond("ow :/ something went wonky wonky, try again!")
|
||||||
return
|
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(
|
marriage_confirmation = interaction_views.MariageConfirmationView(
|
||||||
member_to_marry
|
member_to_marry
|
||||||
)
|
)
|
||||||
|
@ -85,6 +153,9 @@ async def marry(
|
||||||
+ f" {marriage_asker.mention}?", view=marriage_confirmation)
|
+ f" {marriage_asker.mention}?", view=marriage_confirmation)
|
||||||
|
|
||||||
await marriage_confirmation.wait()
|
await marriage_confirmation.wait()
|
||||||
|
|
||||||
|
marriage_confirmation.disable_all_items()
|
||||||
|
|
||||||
if marriage_confirmation.user_accepted is None:
|
if marriage_confirmation.user_accepted is None:
|
||||||
await context.respond("silly little bug going on :3 try again l8er :3")
|
await context.respond("silly little bug going on :3 try again l8er :3")
|
||||||
return
|
return
|
||||||
|
@ -93,13 +164,11 @@ async def marry(
|
||||||
await context.respond(
|
await context.respond(
|
||||||
"no consent == no marriage! consent is key to a happy life :3"
|
"no consent == no marriage! consent is key to a happy life :3"
|
||||||
)
|
)
|
||||||
|
return
|
||||||
|
|
||||||
# Marriage was accepted, yay :3!
|
# 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
|
# 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
|
# No polycules, just update the records to marry the two :3
|
||||||
data = data_manager.get_data()
|
data = data_manager.get_data()
|
||||||
data["marriages"].append([marriage_asker.id, member_to_marry.id])
|
data["marriages"].append([marriage_asker.id, member_to_marry.id])
|
||||||
|
@ -109,14 +178,69 @@ async def marry(
|
||||||
await context.respond(
|
await context.respond(
|
||||||
f"{marriage_asker.mention} married {member_to_marry.mention}"
|
f"{marriage_asker.mention} married {member_to_marry.mention}"
|
||||||
)
|
)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
await context.respond(
|
users_who_confirmed_the_marriage = [marriage_asker.id, member_to_marry.id]
|
||||||
"ooh looks like you're trying to do a ploly marriage..." +
|
|
||||||
" unfortunately, that's still a work in progress," +
|
users_who_need_to_allow_marriage = askees_marriage
|
||||||
" come back later to register it :3"
|
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()
|
@bot.slash_command()
|
||||||
|
|
Loading…
Reference in a new issue