From 709ffe6b7cf7645ed05ec05e73819a72fd07b1c2 Mon Sep 17 00:00:00 2001 From: DigiDuncan Date: Tue, 5 Dec 2023 16:10:02 -0500 Subject: [PATCH] new quake --- sizebot/cogs/quake.py | 64 +++++++++++++++++++++++++++++++++++++++++-- sizebot/lib/quake.py | 4 +++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/sizebot/cogs/quake.py b/sizebot/cogs/quake.py index b7689161..f2e4d12f 100644 --- a/sizebot/cogs/quake.py +++ b/sizebot/cogs/quake.py @@ -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.""" @@ -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) @@ -73,6 +78,61 @@ async def earthquake(self, ctx, quake_type: typing.Optional[QuakeType] = "step", await ctx.send(embed = e) + @commands.command(aliases = [], + usage = " [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 = "", + 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)) diff --git a/sizebot/lib/quake.py b/sizebot/lib/quake.py index 891da38a..51f98cb2 100644 --- a/sizebot/lib/quake.py +++ b/sizebot/lib/quake.py @@ -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. @@ -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)