Skip to content

Commit

Permalink
cleaned up quake.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nfearnley committed May 21, 2024
1 parent e609be5 commit 9843c0f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions sizebot/cogs/quake.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Literal, NamedTuple

from decimal import Decimal

from discord import Embed
import discord
from discord.ext import commands
Expand All @@ -27,7 +28,7 @@ class QuakeData(NamedTuple):
print_rad: str


def quake_data(userdata: userdb.User, quake_type: QuakeType, scale_rad: Decimal = 1) -> QuakeData:
def _quake_data(userdata: userdb.User, quake_type: QuakeType, scale_rad: Decimal = 1) -> QuakeData:
if quake_type == "step":
verb = " stepping"
joules = step_joules(userdata)
Expand Down Expand Up @@ -68,8 +69,8 @@ def quake_data(userdata: userdb.User, quake_type: QuakeType, scale_rad: Decimal
return qd


def quake_embed(userdata: userdb.User, quake_type: QuakeType, scale_rad: Decimal = 1) -> discord.Embed:
qd = quake_data(userdata, quake_type, scale_rad)
def _quake_embed(userdata: userdb.User, quake_type: QuakeType, scale_rad: Decimal = 1) -> discord.Embed:
qd = _quake_data(userdata, quake_type, scale_rad)
e = Embed(
title=f"Earthquake generated by {userdata.nickname}{qd.verb}",
description=f"{userdata.nickname} is {userdata.height:,.3mu} tall, and weighs {userdata.weight:,.3mu}.",
Expand All @@ -82,14 +83,14 @@ def quake_embed(userdata: userdb.User, quake_type: QuakeType, scale_rad: Decimal
return e


def quake_stats_embed(userdata: userdb.User, scale_rad: Decimal = 1) -> discord.Embed:
def _quake_stats_embed(userdata: userdb.User, scale_rad: Decimal = 1) -> discord.Embed:
e = Embed(
title=f"Earthquakes generated by {userdata.nickname}",
description=f"{userdata.nickname} is {userdata.height:,.3mu} tall, and weighs {userdata.weight:,.3mu}.",
color=colors.cyan
)
for qt in ["step", "stomp", "jump", "poke", "breath", "heartbeat", "type"]:
qd = quake_data(userdata, qt, scale_rad)
qd = _quake_data(userdata, qt, scale_rad)
if qt == "step" or qd.print_mag != "0.0":
e.add_field(name = f"{userdata.nickname}{qd.verb}", value = f"{qd.print_joules}J (Mag {qd.print_mag}, {qd.e_type})")

Expand All @@ -111,7 +112,7 @@ async def earthquake(self, ctx: BotContext, quake_type: QuakeType | None = "step
if user is None:
user = ctx.author
userdata = load_or_fake(user)
e = quake_embed(userdata, quake_type)
e = _quake_embed(userdata, quake_type)
await ctx.send(embed = e)

@commands.command(
Expand All @@ -123,7 +124,7 @@ async def earthquakestats(self, ctx: BotContext, user: MemberOrFakeOrSize | None
if user is None:
user = ctx.author
userdata = load_or_fake(user)
e = quake_stats_embed(userdata)
e = _quake_stats_embed(userdata)
await ctx.send(embed = e)

@commands.command(
Expand All @@ -135,7 +136,7 @@ async def quakecompare(self, ctx: BotContext, user: MemberOrFakeOrSize, quake_ty
self_user = load_or_fake(ctx.author)
userdata = load_or_fake(user)
userdata.scale *= self_user.viewscale
e = quake_embed(userdata, quake_type, scale_rad = userdata.viewscale)
e = _quake_embed(userdata, quake_type, scale_rad = userdata.viewscale)
e.title = e.title + f" as seen by {self_user.nickname}"
e.description = f"To {self_user.nickname}, " + e.description
await ctx.send(embed = e)
Expand Down

0 comments on commit 9843c0f

Please sign in to comment.