Skip to content

Commit

Permalink
Merge pull request #28 from Nexus-AI-Bot/calculate-fix
Browse files Browse the repository at this point in the history
Fixed issue
  • Loading branch information
Fluffik3666 authored Oct 8, 2023
2 parents 88ca36e + c46e0de commit 20428a0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
21 changes: 13 additions & 8 deletions cool_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,19 @@ def password(msg):
except:
return 'Error, not a number'

def math(msg):
math = msg
try:
tree = ast.parse(math, mode='eval')
solution = ast.literal_eval(tree.body)
return solution
except Exception:
return "You wrote that wrong:("
def math(num1, num2, op):
if op == '+':
return num1 + num2
elif op == '-':
return num1 - num2
elif op == 'x':
return num1 * num2
elif op == '/':
if num2 == 0:
return "Division by zero is not allowed."
return num1 / num2
else:
return "Invalid operator."

def math_ran():
random_number = random.randint(1, 4)
Expand Down
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,15 @@ async def self(interaction: discord.Interaction):

@logger.log
@tree.command(name="calculate", description="Calculate a math problem")
async def self(interaction: discord.Interaction, math_problem: str):
async def self(interaction: discord.Interaction, num1: int, num2: int, operator: str):
id = interaction.guild.id
json = {
'guild_id':id,
'command_name': interaction.command.name
}
request = requests.post('https://nexus-ai.xyz/bot/command/query', json=json)
if request.text == 'True':
await interaction.response.send_message(f.math(math_problem))
await interaction.response.send_message(f.math(num1, num2, operator))
else:
await interaction.response.send_message('This command has been disabled')

Expand Down Expand Up @@ -929,7 +929,7 @@ async def drink_autocompletion(interaction: discord.Interaction, current: str) -
@logger.log
@tree.command(name="sell", description="Sell your pet")
@app_commands.autocomplete(pet=drink_autocompletion)
async def sell(interaction: discord.Interaction, pet: str):
async def self(interaction: discord.Interaction, pet: str):

id = interaction.guild.id
json = {
Expand Down

0 comments on commit 20428a0

Please sign in to comment.