calculator works
This commit is contained in:
146
Acronymbot.py
146
Acronymbot.py
@@ -2,6 +2,7 @@ import discord
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
from BlackJack import BlackJack
|
from BlackJack import BlackJack
|
||||||
|
from display import Display
|
||||||
|
|
||||||
|
|
||||||
botIntents = discord.Intents.all()
|
botIntents = discord.Intents.all()
|
||||||
@@ -109,137 +110,130 @@ async def bal(interaction: discord.Interaction):
|
|||||||
class Calculator(discord.ui.View):
|
class Calculator(discord.ui.View):
|
||||||
def __init__(self, *, timeout=180):
|
def __init__(self, *, timeout=180):
|
||||||
super().__init__(timeout=timeout)
|
super().__init__(timeout=timeout)
|
||||||
self.numDigits = 0
|
self.numDigs = 0
|
||||||
self.MAXIMUMBARSIZE = 30
|
self.MAXIMUMBARSIZE = 30
|
||||||
m = 0
|
m = 0
|
||||||
self.inputOne = 0
|
self.inputOne = 0
|
||||||
self.inputTwo = 0
|
self.inputTwo = None
|
||||||
self.expression = lambda x, y: x
|
self.expression = None
|
||||||
self.output = 0
|
self.output = None
|
||||||
self.digit = 1
|
self.digit = 1
|
||||||
|
self.addition = lambda x, y: x + y
|
||||||
|
self.subtraction = lambda x, y: x - y
|
||||||
|
self.multiplication = lambda x, y: x * y
|
||||||
|
self.division = lambda x, y: x / y
|
||||||
|
self.exponent = lambda x, y: x ** y
|
||||||
|
self.funckyDict = {
|
||||||
|
self.addition: "+",
|
||||||
|
self.subtraction: "-",
|
||||||
|
self.multiplication: "*",
|
||||||
|
self.division: "/",
|
||||||
|
self.exponent: "^"
|
||||||
|
}
|
||||||
|
|
||||||
|
def numDigits(self, integer):
|
||||||
|
numDigits = 0
|
||||||
|
while(integer):
|
||||||
|
numDigits += 1
|
||||||
|
integer = integer // 10
|
||||||
|
return numDigits
|
||||||
|
|
||||||
|
def display(self):
|
||||||
|
inputOneLength = self.numDigits(self.inputOne)
|
||||||
|
inputTwoLength = self.numDigits(self.inputTwo)
|
||||||
|
outputLength = self.numDigits(self.output)
|
||||||
|
if (self.inputTwo is None) and (self.output is None):
|
||||||
|
padding = self.MAXIMUMBARSIZE - inputOneLength - 1
|
||||||
|
displayOutput = " ".join(['`', ' ' * padding, f"{self.inputOne}", "`"])
|
||||||
|
elif (self.output is None):
|
||||||
|
padding = self.MAXIMUMBARSIZE - inputOneLength - inputTwoLength - 3
|
||||||
|
displayOutput = " ".join(['`', ' ' * padding, f"{self.inputTwo}", f"{self.funckyDict[self.expression]}", f"{self.inputOne}", "`"])
|
||||||
|
else:
|
||||||
|
padding = self.MAXIMUMBARSIZE - inputOneLength - inputTwoLength - outputLength - 4
|
||||||
|
displayOutput = " ".join(['`', ' ' * padding, f"{self.inputTwo}", f"{self.funckyDict[self.expression]}", f"{self.inputOne}", "=", f"{self.output}", "`"])
|
||||||
|
return displayOutput
|
||||||
|
|
||||||
|
async def number(self, interaction: discord.Interaction, number):
|
||||||
|
self.inputOne = self.inputOne * 10 + number
|
||||||
|
self.numDigs = self.numDigs + 1
|
||||||
|
await interaction.response.edit_message(
|
||||||
|
content=self.display(),
|
||||||
|
view=self)
|
||||||
|
|
||||||
|
async def operator(self, interaction: discord.Interaction, operation):
|
||||||
|
self.inputTwo = self.inputOne
|
||||||
|
self.inputOne = 0
|
||||||
|
self.expression = operation
|
||||||
|
await interaction.response.edit_message(
|
||||||
|
content=self.display(),
|
||||||
|
view=self)
|
||||||
|
|
||||||
@discord.ui.button(label="^", style=discord.ButtonStyle.red, row=4)
|
@discord.ui.button(label="^", style=discord.ButtonStyle.red, row=4)
|
||||||
async def power(self, interaction: discord.Interaction, button: discord.ui.Button):
|
async def power(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
self.inputTwo = self.inputOne
|
await self.operator(interaction, self.exponent)
|
||||||
self.inputOne = 0
|
|
||||||
self.expression = lambda x, y: x ** y
|
|
||||||
await interaction.response.edit_message(
|
|
||||||
content=f"` {self.inputTwo} ^ 0`",
|
|
||||||
view=self)
|
|
||||||
|
|
||||||
@discord.ui.button(label="0", style=discord.ButtonStyle.blurple,row=4)
|
@discord.ui.button(label="0", style=discord.ButtonStyle.blurple,row=4)
|
||||||
async def zero(self, interaction: discord.Interaction, button: discord.ui.Button):
|
async def zero(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
prevValue = self.inputOne
|
await self.number(interaction, 0)
|
||||||
self.inputOne = self.inputOne * 10 + 0
|
|
||||||
self.numDigits = self.numDigits + 1
|
|
||||||
await interaction.response.edit_message(content="`" + " " * (self.MAXIMUMBARSIZE - self.numDigits) + f"{self.inputOne}`")
|
|
||||||
|
|
||||||
@discord.ui.button(label="1", style=discord.ButtonStyle.blurple, row=1)
|
@discord.ui.button(label="1", style=discord.ButtonStyle.blurple, row=1)
|
||||||
async def one(self, interaction: discord.Interaction, button: discord.ui.Button):
|
async def one(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
prevValue = self.inputOne
|
await self.number(interaction, 1)
|
||||||
self.inputOne = self.inputOne * 10 + 1
|
|
||||||
self.numDigits = self.numDigits + 1
|
|
||||||
await interaction.response.edit_message(content="`" + " " * (self.MAXIMUMBARSIZE - self.numDigits) + f"{self.inputOne}`")
|
|
||||||
|
|
||||||
|
|
||||||
@discord.ui.button(label="2", style=discord.ButtonStyle.blurple, row=1)
|
@discord.ui.button(label="2", style=discord.ButtonStyle.blurple, row=1)
|
||||||
async def two(self, interaction: discord.Interaction, button: discord.ui.Button):
|
async def two(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
prevValue = self.inputOne
|
await self.number(interaction, 2)
|
||||||
self.inputOne = self.inputOne * 10 + 2
|
|
||||||
self.numDigits = self.numDigits + 1
|
|
||||||
await interaction.response.edit_message(content="`" + " " * (self.MAXIMUMBARSIZE - self.numDigits) + f"{self.inputOne}`")
|
|
||||||
|
|
||||||
@discord.ui.button(label="3", style=discord.ButtonStyle.blurple, row=1)
|
@discord.ui.button(label="3", style=discord.ButtonStyle.blurple, row=1)
|
||||||
async def three(self, interaction: discord.Interaction, button: discord.ui.Button):
|
async def three(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
prevValue = self.inputOne
|
await self.number(interaction, 3)
|
||||||
self.inputOne = self.inputOne * 10 + 3
|
|
||||||
self.numDigits = self.numDigits + 1
|
|
||||||
await interaction.response.edit_message(content="`" + " " * (self.MAXIMUMBARSIZE - self.numDigits) + f"{self.inputOne}`")
|
|
||||||
|
|
||||||
@discord.ui.button(label="4", style=discord.ButtonStyle.blurple, row=2)
|
@discord.ui.button(label="4", style=discord.ButtonStyle.blurple, row=2)
|
||||||
async def four(self, interaction: discord.Interaction, button: discord.ui.Button):
|
async def four(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
prevValue = self.inputOne
|
await self.number(interaction, 4)
|
||||||
self.inputOne = self.inputOne * 10 + 4
|
|
||||||
self.numDigits = self.numDigits + 1
|
|
||||||
await interaction.response.edit_message(content="`" + " " * (self.MAXIMUMBARSIZE - self.numDigits) + f"{self.inputOne}`")
|
|
||||||
|
|
||||||
@discord.ui.button(label="5", style=discord.ButtonStyle.blurple, row=2)
|
@discord.ui.button(label="5", style=discord.ButtonStyle.blurple, row=2)
|
||||||
async def five(self, interaction: discord.Interaction, button: discord.ui.Button):
|
async def five(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
prevValue = self.inputOne
|
await self.number(interaction, 5)
|
||||||
self.inputOne = self.inputOne * 10 + 5
|
|
||||||
self.numDigits = self.numDigits + 1
|
|
||||||
await interaction.response.edit_message(content="`" + " " * (self.MAXIMUMBARSIZE - self.numDigits) + f"{self.inputOne}`")
|
|
||||||
|
|
||||||
@discord.ui.button(label="6", style=discord.ButtonStyle.blurple, row=2)
|
@discord.ui.button(label="6", style=discord.ButtonStyle.blurple, row=2)
|
||||||
async def six(self, interaction: discord.Interaction, button: discord.ui.Button):
|
async def six(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
prevValue = self.inputOne
|
await self.number(interaction, 6)
|
||||||
self.inputOne = self.inputOne * 10 + 6
|
|
||||||
self.numDigits = self.numDigits + 1
|
|
||||||
await interaction.response.edit_message(content="`" + " " * (self.MAXIMUMBARSIZE - self.numDigits) + f"{self.inputOne}`")
|
|
||||||
|
|
||||||
@discord.ui.button(label="7", style=discord.ButtonStyle.blurple, row=3)
|
@discord.ui.button(label="7", style=discord.ButtonStyle.blurple, row=3)
|
||||||
async def seven(self, interaction: discord.Interaction, button: discord.ui.Button):
|
async def seven(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
prevValue = self.inputOne
|
await self.number(interaction, 7)
|
||||||
self.inputOne = self.inputOne * 10 + 7
|
|
||||||
self.numDigits = self.numDigits + 1
|
|
||||||
await interaction.response.edit_message(content="`" + " " * (self.MAXIMUMBARSIZE - self.numDigits) + f"{self.inputOne}`")
|
|
||||||
|
|
||||||
@discord.ui.button(label="8", style=discord.ButtonStyle.blurple, row=3)
|
@discord.ui.button(label="8", style=discord.ButtonStyle.blurple, row=3)
|
||||||
async def eight(self, interaction: discord.Interaction, button: discord.ui.Button):
|
async def eight(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
prevValue = self.inputOne
|
await self.number(interaction, 8)
|
||||||
self.inputOne = self.inputOne * 10 + 8
|
|
||||||
self.numDigits = self.numDigits + 1
|
|
||||||
await interaction.response.edit_message(content="`" + " " * (self.MAXIMUMBARSIZE - self.numDigits) + f"{self.inputOne}`")
|
|
||||||
|
|
||||||
@discord.ui.button(label="9", style=discord.ButtonStyle.blurple, row=3)
|
@discord.ui.button(label="9", style=discord.ButtonStyle.blurple, row=3)
|
||||||
async def nine(self, interaction: discord.Interaction, button: discord.ui.Button):
|
async def nine(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
prevValue = self.inputOne
|
await self.number(interaction, 9)
|
||||||
self.inputOne = self.inputOne * 10 + 9
|
|
||||||
self.numDigits = self.numDigits + 1
|
|
||||||
await interaction.response.edit_message(content="`" + " " * (self.MAXIMUMBARSIZE - self.numDigits) + f"{self.inputOne}`")
|
|
||||||
|
|
||||||
@discord.ui.button(label="+", style=discord.ButtonStyle.red, row=1)
|
@discord.ui.button(label="+", style=discord.ButtonStyle.red, row=1)
|
||||||
async def plus(self, interaction: discord.Interaction, button: discord.ui.Button):
|
async def plus(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
self.inputTwo = self.inputOne
|
await self.operator(interaction, self.addition)
|
||||||
self.inputOne = 0
|
|
||||||
self.expression = lambda x, y: x + y
|
|
||||||
await interaction.response.edit_message(
|
|
||||||
content=f"`" + " " * (self.MAXIMUMBARSIZE - self.numDigits) + f"{self.inputTwo} + 0`",
|
|
||||||
view=self)
|
|
||||||
|
|
||||||
@discord.ui.button(label="*", style=discord.ButtonStyle.red, row=2)
|
@discord.ui.button(label="*", style=discord.ButtonStyle.red, row=2)
|
||||||
async def mult(self, interaction: discord.Interaction, button: discord.ui.Button):
|
async def mult(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
self.inputTwo = self.inputOne
|
await self.operator(interaction, self.multiplication)
|
||||||
self.inputOne = 0
|
|
||||||
self.expression = lambda x, y: x * y
|
|
||||||
await interaction.response.edit_message(
|
|
||||||
content=f"` {self.inputTwo} * 0`",
|
|
||||||
view=self)
|
|
||||||
|
|
||||||
@discord.ui.button(label="-", style=discord.ButtonStyle.red, row=3)
|
@discord.ui.button(label="-", style=discord.ButtonStyle.red, row=3)
|
||||||
async def minus(self, interaction: discord.Interaction, button: discord.ui.Button):
|
async def minus(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
self.inputTwo = self.inputOne
|
await self.operator(interaction, self.subtraction)
|
||||||
self.inputOne = 0
|
|
||||||
self.expression = lambda x, y: x - y
|
|
||||||
await interaction.response.edit_message(
|
|
||||||
content=f"` {self.inputTwo} - 0`",
|
|
||||||
view=self)
|
|
||||||
|
|
||||||
@discord.ui.button(label="=", style=discord.ButtonStyle.green, row=4)
|
@discord.ui.button(label="=", style=discord.ButtonStyle.green, row=4)
|
||||||
async def equals(self, interaction: discord.Interaction, button: discord.ui.Button):
|
async def equals(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
self.output = self.expression(self.inputTwo, self.inputOne)
|
self.output = self.expression(self.inputTwo, self.inputOne)
|
||||||
await interaction.response.edit_message(
|
await interaction.response.edit_message(
|
||||||
content=f"` {self.output}`",
|
content=self.display(),
|
||||||
view=self)
|
view=self)
|
||||||
|
|
||||||
@discord.ui.button(label="/", style=discord.ButtonStyle.red, row=4)
|
@discord.ui.button(label="/", style=discord.ButtonStyle.red, row=4)
|
||||||
async def divide(self, interaction: discord.Interaction, button: discord.ui.Button):
|
async def divide(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
self.inputTwo = self.inputOne
|
await self.operator(interaction, self.division)
|
||||||
self.inputOne = 0
|
|
||||||
self.expression = lambda x, y: x / y
|
|
||||||
await interaction.response.edit_message(
|
|
||||||
content=f"` {self.inputTwo} / 0`",
|
|
||||||
view=self)
|
|
||||||
|
|
||||||
@tree.command(description="Do Meth")
|
@tree.command(description="Do Meth")
|
||||||
async def calculator(interaction: discord.Interaction):
|
async def calculator(interaction: discord.Interaction):
|
||||||
|
|||||||
Reference in New Issue
Block a user