Skip to content

Commit

Permalink
mental math
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrastro committed Oct 20, 2023
1 parent 94d7af5 commit b946b67
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions sadbot/commands/mental_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

# Define mental math methods, notes, and rules for generating equations
mental_math_methods = {
"fuck_you": {
"notes": "what's the riemann integral from 0 to +infinity of sin(x)/x in dx?",
"generate_equation": lambda: ("pi/2")
},
"double_and_halve": {
"notes": "Halve one number (preferably even) and double the other, then multiply. Example: 24 x 5 = (12 x 2) x (5 x 2) = 12 x 10 = 120",
"generate_equation": lambda: (random.choice(range(10, 100, 2)), random.randint(10, 99))
Expand Down Expand Up @@ -79,6 +83,9 @@ def generate_random_equation():
elif method_key in ["double_and_divide"]:
answer = equation[0] / equation[1] # Adjusted for division
equation_str = f"{equation[0]} ÷ {equation[1]}" # Adjusted formatting for division
elif method_key in ["fuck_you"]:
answer = "pi/2"
equation_str = "what's the riemann integral from 0 to +infinity of sin(x)/x in dx?"
else:
answer = equation[0] + equation[1] # Default to addition if no other cases match
equation_str = f"{equation[0]} + {equation[1]}" # Default formatting for addition
Expand All @@ -105,10 +112,10 @@ def get_reply(self, message: Optional[Message] = None) -> Optional[List[BotActio
equation, answer, method_notes = generate_random_equation()
reply_text = (
f"Equation: {equation}\n"
f"Answer: {answer}\n"
f"Method Notes: {method_notes}"
f"Answer: <span class='tg-spoiler'>{answer}\n</span>"
f"Method Notes: <span class='tg-spoiler'>{method_notes}</span>"
)
return [BotAction(BOT_ACTION_TYPE_REPLY_TEXT, reply_text)]
return [BotAction(BOT_ACTION_TYPE_REPLY_TEXT, reply_text, reply_spoiler=True, reply_text_parse_mode="HTML")]

# Usage:
# equation, answer, method_notes = generate_random_equation()
Expand Down

0 comments on commit b946b67

Please sign in to comment.