Making marry command store information

Storing Married Users
Storing the time of the Marriage
Making divorce command
pull/8/head
sgoudham 4 years ago
parent 6270ceb6d4
commit f83aac8a54

@ -378,43 +378,128 @@ class Interactive(commands.Cog):
async def marry(self, ctx, member: Member): async def marry(self, ctx, member: Member):
"""Allows the bot to wed two young lovers together""" """Allows the bot to wed two young lovers together"""
# Get the guild Enso # Getting the guild of the user
guild = self.bot.get_guild(enso_guild_ID) guild = ctx.author.guild
# Make sure the guild is Enso
if guild.id != enso_guild_ID:
return
# Use database connection
with db.connection() as conn:
# Get the author's row from the Members Table
select_query = """SELECT * FROM members WHERE discordID = (?)"""
val = ctx.author.id,
cursor = conn.cursor()
# Execute the SQL Query
cursor.execute(select_query, val)
result = cursor.fetchone()
# Make sure that the user cannot marry themselves
if member.id == ctx.author.id:
await ctx.send("Senpaii! ˭̡̞(◞⁎˃ᆺ˂)◞*✰ You can't possibly marry yourself!")
return
# Make sure that the person is not already married to someone else within the server
elif result[2] is not None:
member = guild.get_member(int(result[2]))
await ctx.send(f"((╬◣﹏◢)) You're already married to {member.mention}!")
return
# Send a message to the channel mentioning the author and the person they want to wed.
await ctx.send(f"{ctx.author.mention} **Proposes To** {member.mention} **Do you accept??** "
f"\nRespond with [**Y**es/**N**o]")
# A check that makes sure that the reply is not from the author
# and that the reply is in the same channel as the proposal
def check(m):
return m.author == member and m.channel == ctx.channel
# Surround with try/except to catch any exceptions that may occur
try:
# Wait for the message from the mentioned user
msg = await self.bot.wait_for('message', check=check, timeout=30)
# if the person says yes
if msg.content.lower() in ['y', 'yes', 'yea']:
# Using connection to the database # Using connection to the database
with db.connection() as conn: with db.connection() as conn:
select_query = """SELECT * FROM marriages""" message_time = msg.created_at.strftime("%a, %b %d, %Y")
# Update the existing records in the database with the user that they are marrying along with the time of the accepted proposal
update_query = """UPDATE members SET married = (?), marriedDate = (?) WHERE discordID = (?)"""
proposer = member.id, message_time, ctx.author.id,
proposee = ctx.author.id, message_time, member.id,
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute(select_query) # Execute the SQL Query's
result = cursor.fetchall() cursor.execute(update_query, proposer)
cursor.execute(update_query, proposee)
conn.commit()
print(cursor.rowcount, "Records Updated in Members!")
for row in result: # Congratulate them!
if str(ctx.author.id) != row[1] or str(member.id) == row[2]: await ctx.send(
member = guild.get_member(int(row[2])) f"Congratulations! 。゚( ゚^∀^゚)゚。 {ctx.author.mention} and {member.mention} are now married to each other!")
author = guild.get_member(int(row[1]))
await ctx.send(f"Sorry! {member.mention} is already married to {author.mention}!")
if str(ctx.author.id) == row[1]: # if the person says no
member = guild.get_member(int(row[2])) elif msg.content.lower() in ['n', 'no', 'nah']:
await ctx.send(f"Sorry! You're currently married to {member.mention}")
# Try to console the person and wish them the best in their life
await ctx.send(f"{ctx.author.mention} It's okay King. Pick up your crown and move on (◕‿◕✿)")
else:
# Abort the process as the message sent did not make sense
await ctx.send("Senpaiiii! (。╯︵╰。) Speak English Please")
except asyncio.TimeoutError as ex:
print(ex)
# Send out an error message if the user waited too long
await ctx.send("(。T ω T。) They waited too long")
@command(name="divorce", aliases=["Divorce"])
@cooldown(1, 1, BucketType.user)
async def divorce(self, ctx, member: Member):
"""Allows the bot to divorce users"""
# Getting the guild of the user
guild = ctx.author.guild
# Make sure the guild is Enso
if guild.id != enso_guild_ID:
return return
elif str(ctx.author.id) == row[2]:
member = guild.get_member(int(row[1])) # Use database connection
await ctx.send(f"Sorry! You're currently married to {member.mention}") with db.connection() as conn:
# Get the author's row from the Members Table
select_query = """SELECT * FROM members WHERE discordID = (?)"""
val = ctx.author.id,
cursor = conn.cursor()
# Execute the SQL Query
cursor.execute(select_query, val)
result = cursor.fetchone()
# Make sure that the user cannot divorce themselves
if member.id == ctx.author.id:
await ctx.send("Senpaii! ˭̡̞(◞⁎˃ᆺ˂)◞*✰ You can't possibly divorce yourself!")
return return
elif str(member.id) == row[1]: # Make sure that the person trying to divorce is actually married to the user
member = guild.get_member(int(row[2])) elif result[2] is None:
await ctx.send(f"Sorry! You're currently married to {ctx.author.mention}") await ctx.send(f"((╬◣﹏◢)) You must be married in order to divorce someone! Baka!")
return return
elif str(member.id) == row[2]: # Make sure the person is married to the person that they're trying to divorce
member = guild.get_member(int(row[1])) elif result[2] != str(member.id):
await ctx.send(f"Sorry! You're currently married to {ctx.author.mention}") member = guild.get_member(int(result[2]))
await ctx.send(f"( ゜口゜) You can only divorce the person that you're married!"
f"\n That person is {member.mention}")
return return
conn.commit()
# Send a message to the channel mentioning the author and the person they want to wed. # Send a message to the channel mentioning the author and the person they want to wed.
await ctx.send(f"{ctx.author.mention} **Proposes To** {member.mention} **Do you accept??** " await ctx.send(
f"{ctx.author.mention} **Wishes to Divorce** {member.mention} **Are you willing to break this sacred bond??**"
f"\nRespond with [**Y**es/**N**o]") f"\nRespond with [**Y**es/**N**o]")
# A check that makes sure that the reply is not from the author # A check that makes sure that the reply is not from the author
@ -432,33 +517,71 @@ class Interactive(commands.Cog):
# Using connection to the database # Using connection to the database
with db.connection() as conn: with db.connection() as conn:
# Define the Insert Into Statement inserting into the database # Update the existing records in the database with the user that they are marrying along with the time of the accepted proposal
insert_query = """INSERT INTO marriages (proposerID, proposeeID) VALUES (?, ?)""" update_query = """UPDATE members SET married = null, marriedDate = null WHERE discordID = (?)"""
val = ctx.author.id, member.id divorcer = ctx.author.id,
divorcee = member.id,
cursor = conn.cursor() cursor = conn.cursor()
# Execute the SQL Query # Execute the SQL Query's
cursor.execute(insert_query, val) cursor.execute(update_query, divorcer)
cursor.execute(update_query, divorcee)
conn.commit() conn.commit()
print(cursor.rowcount, "Record inserted successfully into Marriage Logs") print(cursor.rowcount, "Records Updated in Members!")
# Congratulate them! # Congratulate them!
await ctx.send( await ctx.send(
f"Congratulations! ヽ(・∀・)ノ {ctx.author.mention} and {member.mention} are now married to each other!") f" ૮( ´⁰▱๋⁰ )ა {ctx.author.mention} and {member.mention} are now divorced. I hope you two can find happiness in life with other people")
# if the person says no # if the person says no
elif msg.content.lower() in ['n', 'no', 'nah']: elif msg.content.lower() in ['n', 'no', 'nah']:
# Try to console the person and wish them the best in their life # Try to console the person and wish them the best in their life
await ctx.send(f"Unlucky (T▽T), maybe another time! {ctx.author.mention}") await ctx.send(f"Sorry but you're gonna need {ctx.author.mention}'s consent to move forward with this!")
else: else:
# Abort the process as the message sent did not make sense # Abort the process as the message sent did not make sense
await ctx.send("Senpaiiii! Speak English Please ⋋_⋌") await ctx.send("Senpaiiii! (。╯︵╰。) Speak English Please")
except asyncio.TimeoutError as ex: except asyncio.TimeoutError as ex:
print(ex) print(ex)
# Send out an error message if the user waited too long # Send out an error message if the user waited too long
await ctx.send("Awww they waited too long (✖╭╮✖)") await ctx.send("(。T ω T。) They waited too long")
def setup(bot): def setup(bot):
bot.add_cog(Interactive(bot)) bot.add_cog(Interactive(bot))
"""
if str(ctx.author.id) == row[1] and str(member.id) == row[2]:
member = guild.get_member(int(row[2]))
await ctx.send(f"You and {member.mention} are married!")
return
elif str(ctx.author.id) != row[1] and str(member.id) == row[2]:
member = guild.get_member(int(row[2]))
author = guild.get_member(int(row[1]))
await ctx.send(f"Sorry! {member.mention} is already married to {author.mention}!")
elif str(ctx.author.id) != row[1] and str(member.id) == row[1]:
member = guild.get_member(int(row[2]))
author = guild.get_member(int(row[1]))
await ctx.send(f"Sorry! {author.mention} is already married to {member.mention}!")
return
elif str(ctx.author.id) == row[1]:
member = guild.get_member(int(row[2]))
await ctx.send(f"Sorry! You're currently married to {member.mention}")
return
elif str(ctx.author.id) == row[2]:
member = guild.get_member(int(row[1]))
await ctx.send(f"Sorry! You're currently married to {member.mention}")
return
elif str(member.id) == row[1]:
member = guild.get_member(int(row[2]))
await ctx.send(f"Sorry! You're currently married to {ctx.author.mention}")
return
elif str(member.id) == row[2]:
member = guild.get_member(int(row[1]))
await ctx.send(f"Sorry! You're currently married to {ctx.author.mention}")
return
"""

Loading…
Cancel
Save