Skip to content

Commit

Permalink
improve quake
Browse files Browse the repository at this point in the history
  • Loading branch information
DigiDuncan committed Nov 10, 2023
1 parent 656b490 commit 97c4307
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions sizebot/cogs/quake.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

from sizebot.lib.constants import colors
from sizebot.lib.fakeplayer import FakePlayer
from sizebot.lib.quake import joules_to_mag, mag_to_name, mag_to_radius, step_joules
from sizebot.lib.quake import joules_to_mag, jump_joules, mag_to_name, mag_to_radius, step_joules, stomp_joules
from sizebot.lib.units import SV
from sizebot.lib.userdb import load_or_fake
from sizebot.lib.errors import UserMessedUpException

EARTH_RAD = 10_018_570
QuakeType = typing.Literal["step", "stomp", "jump"]

class QuakeCog(commands.Cog):
"""Quake commands."""
Expand All @@ -21,12 +23,22 @@ def __init__(self, bot):
@commands.command(aliases = ["quake"],
usage = "[user/height]",
category = "stats")
async def earthquake(self, ctx, user: typing.Union[discord.Member, FakePlayer, SV] = None):
async def earthquake(self, ctx, quake_type: typing.Optional[QuakeType] = "step", user: typing.Union[discord.Member, FakePlayer, SV] = None):
"""See what quakes would be caused by your steps."""
if user is None:
user = ctx.author
userdata = load_or_fake(user)
joules = step_joules(userdata)
if quake_type == "step":
verb = "stepping"
joules = step_joules(userdata)
elif quake_type == "stomp":
verb = "stomping"
joules = stomp_joules(userdata)
elif quake_type == "jump":
verb = "jumping"
joules = jump_joules(userdata)
else:
raise UserMessedUpException(f"{quake_type} is not a valid quake type.")
mag = joules_to_mag(joules)
e_type = mag_to_name(mag).title()
rad = mag_to_radius(mag)
Expand All @@ -37,7 +49,7 @@ async def earthquake(self, ctx, user: typing.Union[discord.Member, FakePlayer, S
e_rad = rad / EARTH_RAD
print_rad = f"{e_rad:,.2} 🌎"
e = Embed(
title=f"Earthquake generated by {userdata.nickname} stepping",
title=f"Earthquake generated by {userdata.nickname} {verb}",
description=f"{userdata.nickname} is {userdata.height:,.3mu} tall, and weighs {userdata.weight:,.3mu}.",
color=colors.cyan
)
Expand Down
2 changes: 1 addition & 1 deletion sizebot/lib/quake.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

STEP_FACTOR = 0.035
STOMP_FACTOR = 0.5
JUMP_FACTOR = 0.43
JUMP_FACTOR = 1

def joules_to_mag(joules: float) -> Decimal:
# This might not be super accurate.
Expand Down

0 comments on commit 97c4307

Please sign in to comment.