Skip to content

Commit

Permalink
new quake
Browse files Browse the repository at this point in the history
  • Loading branch information
DigiDuncan committed Dec 5, 2023
1 parent d6949c0 commit 709ffe6
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
64 changes: 62 additions & 2 deletions sizebot/cogs/quake.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
from discord import Embed
import discord
from discord.ext import commands
from sizebot.lib import proportions
from sizebot.lib import userdb

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

EARTH_RAD = Decimal(10_018_570)
UNI_RAD = Decimal(4.4E26)
QuakeType = typing.Literal["step", "stomp", "jump", "poke", "breath", "breathe", "heartbeat"]
QuakeType = typing.Literal["step", "stomp", "jump", "poke", "breath", "breathe", "heartbeat", "type", "typing"]

class QuakeCog(commands.Cog):
"""Quake commands."""
Expand Down Expand Up @@ -47,6 +49,9 @@ async def earthquake(self, ctx, quake_type: typing.Optional[QuakeType] = "step",
elif quake_type == "heartbeat":
verb = "'s heart beating"
joules = heartbeat_joules(userdata)
elif quake_type == "type" or quake_type == "typing":
verb = " typing one letter"
joules = type_joules(userdata)
else:
raise UserMessedUpException(f"{quake_type} is not a valid quake type.")
mag = joules_to_mag(joules)
Expand All @@ -73,6 +78,61 @@ async def earthquake(self, ctx, quake_type: typing.Optional[QuakeType] = "step",

await ctx.send(embed = e)

@commands.command(aliases = [],
usage = "<dist> [user/height]",
category = "stats")
async def quakewalk(self, ctx, dist: SV, user: typing.Union[discord.Member, FakePlayer, SV] = None):
"""Walk a distance and cause some quakes."""
if user is None:
user = ctx.author
userdata = load_or_fake(user)
stats = proportions.PersonStats(userdata)
steps: int = int(dist / stats.walksteplength)

small_j = step_joules(userdata)
small_mag = joules_to_mag(small_j)
small_type = mag_to_name(small_mag)

big_j = step_joules(userdata) * steps
big_mag = joules_to_mag(big_j)
big_type = mag_to_name(big_mag)

return_string = (
f"{userdata.nickname} is {userdata.height:,.3mu} tall, and weighs {userdata.weight:,.3mu}.\n"
f"Walking {dist:,.1mu}, they would take **{steps} steps**, each causing a **Magnitude {small_mag} earthquake.** ({small_type})\n"
f"That's equivalent to **one Magnitude {big_mag} earthquake**. ({big_type})\n"
)

await ctx.send(return_string)

@commands.command(aliases = [],
usage = "<string>",
category = "stats")
async def quaketype(self, ctx, s: str):
"""Walk a distance and cause some quakes."""
guildid = ctx.guild.id
userid = ctx.author.id

userdata = userdb.load(guildid, userid)

steps: int = len(s)

small_j = step_joules(userdata)
small_mag = joules_to_mag(small_j)
small_type = mag_to_name(small_mag)

big_j = step_joules(userdata) * steps
big_mag = joules_to_mag(big_j)
big_type = mag_to_name(big_mag)

return_string = (
f"{userdata.nickname} is {userdata.height:,.3mu} tall, and weighs {userdata.weight:,.3mu}.\n"
f"Typing {steps} characters, {userdata.nickname}, caused {steps} **Magnitude {small_mag} earthquakes.** ({small_type})\n"
f"That's equivalent to **one Magnitude {big_mag} earthquake**. ({big_type})\n"
)

await ctx.send(return_string)


async def setup(bot):
await bot.add_cog(QuakeCog(bot))
4 changes: 4 additions & 0 deletions sizebot/lib/quake.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
BREATH_JOULES = 0.025
POKE_JOULES = 8
HEARTBEAT_JOULES = 5.38E-9
TYPE_JOULES = 2.5E-3

def joules_to_mag(joules: float) -> Decimal:
# This might not be super accurate.
Expand Down Expand Up @@ -76,3 +77,6 @@ def poke_joules(user: User) -> Decimal:

def heartbeat_joules(user: User) -> Decimal:
return Decimal(HEARTBEAT_JOULES) * (user.scale ** 3)

def type_joules(user: User) -> Decimal:
return Decimal(TYPE_JOULES) * (user.scale ** 3)

0 comments on commit 709ffe6

Please sign in to comment.