Made ChristmasBot case insensitive
This commit is contained in:
@@ -257,7 +257,7 @@ class ChristmasBot:
|
||||
first_line = body_lines[0]
|
||||
|
||||
if self.username_pattern.match(first_line):
|
||||
target_user = first_line[2:]
|
||||
target_user = first_line[2:].lower()
|
||||
wish_content = '\n'.join(body_lines[1:])
|
||||
return target_user, wish_content
|
||||
|
||||
@@ -302,7 +302,7 @@ class ChristmasBot:
|
||||
|
||||
# ERROR: Empty Body
|
||||
if not wish_content:
|
||||
message.reply(f"You didn't write a message for u/{target_user}! Please try again with text in the body.")
|
||||
message.reply(f"You didn't write a message for u/{target_user.lower()}! Please try again with text in the body.")
|
||||
return
|
||||
|
||||
# SAFETY CHECK
|
||||
@@ -314,16 +314,16 @@ class ChristmasBot:
|
||||
return
|
||||
|
||||
# ERROR: No Flair
|
||||
if not self.verify_user_flair(target_user):
|
||||
message.reply(f"Sorry, u/{target_user} does not have a User Flair in r/{config.subreddit_name}.\n"
|
||||
if not self.verify_user_flair(target_user.lower()):
|
||||
message.reply(f"Sorry, u/{target_user.lower()} does not have a User Flair in r/{config.subreddit_name}.\n"
|
||||
"We only allow wishes for active, flaired community members.")
|
||||
return
|
||||
|
||||
# CHECK: Existing Wish
|
||||
existing_msg = self.db.check_existing_wish(sender, target_user)
|
||||
existing_msg = self.db.check_existing_wish(sender, target_user.lower())
|
||||
|
||||
if existing_msg:
|
||||
self.db.set_conversation_state(sender, "CONFIRM_REPLACE", target_user, wish_content)
|
||||
self.db.set_conversation_state(sender, "CONFIRM_REPLACE", target_user.lower(), wish_content)
|
||||
reply = (f"⚠️ **You already sent a wish to u/{target_user}.**\n\n"
|
||||
f"**Old Message:** {existing_msg[:100]}...\n\n"
|
||||
f"**Do you want to REPLACE it with:**\n"
|
||||
@@ -331,9 +331,9 @@ class ChristmasBot:
|
||||
f"Reply **YES** to confirm or **NO** to cancel.")
|
||||
message.reply(reply)
|
||||
else:
|
||||
self.db.set_conversation_state(sender, "CONFIRM_NEW", target_user, wish_content)
|
||||
self.db.set_conversation_state(sender, "CONFIRM_NEW", target_user.lower(), wish_content)
|
||||
reply = (f"🎄 **Christmas Confirmation** 🎄\n\n"
|
||||
f"I extracted that you want to send a wish to **u/{target_user}**.\n\n"
|
||||
f"I extracted that you want to send a wish to **u/{target_user.lower()}**.\n\n"
|
||||
f"**Message:**\n"
|
||||
f"> {wish_content}\n\n"
|
||||
f"Is this correct? Reply **YES** to save or **NO** to cancel.")
|
||||
@@ -350,16 +350,16 @@ class ChristmasBot:
|
||||
return
|
||||
|
||||
if self.yes_pattern.match(user_response):
|
||||
self.db.save_wish(sender, target, content)
|
||||
self.db.save_wish(sender, target.lower(), content)
|
||||
self.db.clear_conversation(sender)
|
||||
|
||||
print(f"💾 Wish saved for {target}")
|
||||
print(f"💾 Wish saved for {target.lower()}")
|
||||
if state == "CONFIRM_REPLACE":
|
||||
message.reply(f"✅ Your wish for u/{target} has been **updated**! 🎄")
|
||||
print(f"{sender} has updated their wish for u/{target} to **{content}**.")
|
||||
message.reply(f"✅ Your wish for u/{target.lower()} has been **updated**! 🎄")
|
||||
print(f"{sender} has updated their wish for u/{target.lower()} to **{content}**.")
|
||||
else:
|
||||
message.reply(f"✅ Your wish for u/{target} has been **saved**! 🎄")
|
||||
print(f"{sender} has saved their wish for u/{target}: **{content}**.")
|
||||
message.reply(f"✅ Your wish for u/{target.lower()} has been **saved**! 🎄")
|
||||
print(f"{sender} has saved their wish for u/{target.lower()}: **{content}**.")
|
||||
|
||||
elif self.no_pattern.match(user_response):
|
||||
self.db.clear_conversation(sender)
|
||||
@@ -400,10 +400,10 @@ class ChristmasBot:
|
||||
print(f"🎅 HO HO HO! It's Christmas! Distributing gifts to {len(recipients)} users...")
|
||||
|
||||
for username in recipients:
|
||||
wishes = self.db.get_user_wishes(username)
|
||||
wishes = self.db.get_user_wishes(username.lower())
|
||||
if not wishes: continue
|
||||
|
||||
print(f"🎁 Preparing gifts for u/{username}...")
|
||||
print(f"🎁 Preparing gifts for u/{username.lower()}...")
|
||||
|
||||
# --- PAGINATION LOGIC ---
|
||||
messages_to_send = []
|
||||
@@ -411,7 +411,7 @@ class ChristmasBot:
|
||||
current_part_num = 1
|
||||
|
||||
# Header for first message
|
||||
header = f"Merry Christmas u/{username}!\n\nThe wait is over. Here are your wishes:\n\n---\n\n"
|
||||
header = f"Merry Christmas u/{username.lower()}!\n\nThe wait is over. Here are your wishes:\n\n---\n\n"
|
||||
current_part_content += header
|
||||
|
||||
for sender, message_text in wishes:
|
||||
@@ -446,12 +446,12 @@ class ChristmasBot:
|
||||
# Small sleep between parts to ensure order and avoid spam trigger
|
||||
time.sleep(2)
|
||||
|
||||
self.db.mark_delivered(username)
|
||||
print(f"✅ Delivered {len(messages_to_send)} part(s) to u/{username}")
|
||||
self.db.mark_delivered(username.lower())
|
||||
print(f"✅ Delivered {len(messages_to_send)} part(s) to u/{username.lower()}")
|
||||
time.sleep(5) # Delay between USERS
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Failed to send to u/{username}: {e}")
|
||||
print(f"❌ Failed to send to u/{username.lower()}: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user