251 lines
9.3 KiB
Python
251 lines
9.3 KiB
Python
import discord
|
|
import sqlite3
|
|
from discord import app_commands
|
|
from BlackJack import BlackJack
|
|
from display import Display
|
|
|
|
|
|
botIntents = discord.Intents.all()
|
|
|
|
client = discord.Client(intents=botIntents)
|
|
tree = app_commands.CommandTree(client)
|
|
blackJack = BlackJack()
|
|
|
|
@client.event
|
|
async def on_ready():
|
|
await tree.sync()
|
|
print('Itsa me Mario!')
|
|
|
|
# @client.event
|
|
# async def on_message_delete(message: discord.Message):
|
|
# channel = client.get_channel(message.channel.id)
|
|
# await channel.send(f"{message.author} deleted a message! @everyone, get him!")
|
|
# dmessage = await channel.send(f"Here's the message they deleted! \"{message.content}\". What a sick fuck")
|
|
# await dmessage.delete()
|
|
|
|
"""
|
|
#### Test ####
|
|
"""
|
|
class Buttons(discord.ui.View):
|
|
def __init__(self, *, timeout=180):
|
|
super().__init__(timeout=timeout)
|
|
|
|
@discord.ui.button(label="Pay $5", style=discord.ButtonStyle.green)
|
|
async def green_button(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
print(f"{interaction.user} pressed the green button")
|
|
button.disabled = True
|
|
button.label = "No Refunds!"
|
|
for child in self.children:
|
|
child.disabled = True
|
|
await interaction.response.edit_message(content=f"Mario Moment Achieved", view=self)
|
|
|
|
@discord.ui.button(label="Punch AcryBot", style=discord.ButtonStyle.red)
|
|
async def red_button(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
print(f"{interaction.user} pressed the red button")
|
|
button.disabled = True
|
|
button.label = f"fuck you {interaction.user}"
|
|
for child in self.children:
|
|
child.disabled = True
|
|
await interaction.response.edit_message(content=f"Ouch!", view=self)
|
|
|
|
@tree.command(description="Lmao")
|
|
async def test(interaction:discord.Interaction):
|
|
print(f"{interaction.user} used command! Woohoo!")
|
|
try:
|
|
await interaction.response.send_message("Pay $5 for a Mario Moment", view=Buttons())
|
|
except discord.app_commands.errors.CommandInvokeError:
|
|
print("Uh oh! It failed!")
|
|
|
|
"""
|
|
#### Black Jack ####
|
|
"""
|
|
class HitOrStand(discord.ui.View):
|
|
def __init__(self, *, timeout=180):
|
|
super().__init__(timeout=timeout)
|
|
self.content = None
|
|
|
|
@discord.ui.button(label="Hit", style=discord.ButtonStyle.green)
|
|
async def hit(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
self.content = "h"
|
|
for child in self.children:
|
|
child.disabled = True
|
|
await interaction.response.edit_message(content="You Hit!", view=self)
|
|
self.stop()
|
|
|
|
@discord.ui.button(label="Stand", style=discord.ButtonStyle.red)
|
|
async def stand(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
self.content = "s"
|
|
for child in self.children:
|
|
child.disabled = True
|
|
await interaction.response.edit_message(content="You stood!", view=self)
|
|
self.stop()
|
|
|
|
@tree.command(description="Play Black Jack!")
|
|
async def bj(interaction: discord.Interaction):
|
|
discinput = lambda m: discordInput(interaction, m)
|
|
discoutput = lambda m: discordOutput(interaction, m)
|
|
await interaction.response.send_message("Let's play Black Jack!")
|
|
await blackJack.play_game(interaction.user.id, 100, discinput, discoutput)
|
|
|
|
async def discordInput(interaction: discord.Interaction, message:str):
|
|
response = HitOrStand()
|
|
await interaction.followup.send(message, view=response)
|
|
await response.wait()
|
|
return response.content
|
|
|
|
async def discordOutput(interaction: discord.Interaction, message):
|
|
await interaction.followup.send(message)
|
|
|
|
@tree.command(description="Find your Balance")
|
|
async def bal(interaction: discord.Interaction):
|
|
conn = sqlite3.connect("ledger.db")
|
|
cur = conn.cursor()
|
|
ID = interaction.user.id
|
|
data = cur.execute("SELECT * FROM ledger WHERE USERID = ?", (ID,))
|
|
await interaction.response.send_message(data)
|
|
|
|
"""
|
|
#### Calculator ####
|
|
"""
|
|
class Calculator(discord.ui.View):
|
|
def __init__(self, *, timeout=180):
|
|
super().__init__(timeout=timeout)
|
|
self.numDigs = 0
|
|
self.MAXIMUMBARSIZE = 30
|
|
m = 0
|
|
self.inputOne = 0
|
|
self.inputTwo = None
|
|
self.expression = None
|
|
self.output = None
|
|
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)
|
|
async def power(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
await self.operator(interaction, self.exponent)
|
|
|
|
@discord.ui.button(label="0", style=discord.ButtonStyle.blurple,row=4)
|
|
async def zero(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
await self.number(interaction, 0)
|
|
|
|
@discord.ui.button(label="1", style=discord.ButtonStyle.blurple, row=1)
|
|
async def one(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
await self.number(interaction, 1)
|
|
|
|
@discord.ui.button(label="2", style=discord.ButtonStyle.blurple, row=1)
|
|
async def two(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
await self.number(interaction, 2)
|
|
|
|
@discord.ui.button(label="3", style=discord.ButtonStyle.blurple, row=1)
|
|
async def three(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
await self.number(interaction, 3)
|
|
|
|
@discord.ui.button(label="4", style=discord.ButtonStyle.blurple, row=2)
|
|
async def four(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
await self.number(interaction, 4)
|
|
|
|
@discord.ui.button(label="5", style=discord.ButtonStyle.blurple, row=2)
|
|
async def five(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
await self.number(interaction, 5)
|
|
|
|
@discord.ui.button(label="6", style=discord.ButtonStyle.blurple, row=2)
|
|
async def six(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
await self.number(interaction, 6)
|
|
|
|
@discord.ui.button(label="7", style=discord.ButtonStyle.blurple, row=3)
|
|
async def seven(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
await self.number(interaction, 7)
|
|
|
|
@discord.ui.button(label="8", style=discord.ButtonStyle.blurple, row=3)
|
|
async def eight(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
await self.number(interaction, 8)
|
|
|
|
@discord.ui.button(label="9", style=discord.ButtonStyle.blurple, row=3)
|
|
async def nine(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
await self.number(interaction, 9)
|
|
|
|
@discord.ui.button(label="+", style=discord.ButtonStyle.red, row=1)
|
|
async def plus(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
await self.operator(interaction, self.addition)
|
|
|
|
@discord.ui.button(label="*", style=discord.ButtonStyle.red, row=2)
|
|
async def mult(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
await self.operator(interaction, self.multiplication)
|
|
|
|
@discord.ui.button(label="-", style=discord.ButtonStyle.red, row=3)
|
|
async def minus(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
await self.operator(interaction, self.subtraction)
|
|
|
|
@discord.ui.button(label="=", style=discord.ButtonStyle.green, row=4)
|
|
async def equals(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
self.output = self.expression(self.inputTwo, self.inputOne)
|
|
await interaction.response.edit_message(
|
|
content=self.display(),
|
|
view=self)
|
|
|
|
@discord.ui.button(label="/", style=discord.ButtonStyle.red, row=4)
|
|
async def divide(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
await self.operator(interaction, self.division)
|
|
|
|
@tree.command(description="Do Meth")
|
|
async def calculator(interaction: discord.Interaction):
|
|
await interaction.response.defer()
|
|
calculator = Calculator()
|
|
await interaction.followup.send(content="`" + " " * calculator.MAXIMUMBARSIZE + "0`", view=calculator)
|
|
|
|
|
|
|
|
|
|
"""
|
|
#### Fin ####
|
|
"""
|
|
|
|
client.run('NzgwNzg4NDIwMjkzMDM0MDA0.GEKkUB.Bbl09D3lWMGea_mcIESPMLUyGlkW-6N53BPFjI') |