Skip to content

Commit

Permalink
can we please do a pass where we make everything snake_case
Browse files Browse the repository at this point in the history
Natalie I know you're a JS developer but this hurts me
  • Loading branch information
DigiDuncan committed Dec 6, 2023
1 parent 523986f commit bd6ba58
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions sizebot/cogs/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ async def objstats(self, ctx, *, what: typing.Union[DigiObject, str]):
usage = "[@User]"
)
# TODO: Bad name.
async def stackup(self, ctx, amount: typing.Optional[int] = None, who: typing.Union[discord.Member, FakePlayer] = None):
async def stackup(self, ctx, amount: typing.Optional[int] = None, *, who: typing.Union[discord.Member, FakePlayer] = None):
"""How do you stack up against objects?
Example:
Expand Down Expand Up @@ -429,7 +429,7 @@ async def tags(self, ctx):
)
async def scaled(self, ctx, *, obj: DigiObject):
userdata = load_or_fake(ctx.author)
await ctx.send(f"{obj.article.capitalize()} {obj.name} scaled for {userdata.nickname} is {obj.getStatsSentence(userdata.scale, userdata.unitsystem)}")
await ctx.send(f"{obj.article.capitalize()} {obj.name} scaled for {userdata.nickname} is {obj.get_stats_sentence(userdata.scale, userdata.unitsystem)}")

async def setup(bot):
await bot.add_cog(ObjectsCog(bot))
4 changes: 2 additions & 2 deletions sizebot/lib/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ def load():
engine.defnoun(s, p)


def getPlural(noun):
def get_plural(noun):
overrides = {}
if noun in overrides:
return overrides[noun]
return engine.plural_noun(noun)


def getIndefiniteArticle(noun):
def get_indefinite_article(noun):
return engine.a(noun)
46 changes: 23 additions & 23 deletions sizebot/lib/objs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from sizebot.lib import errors
from sizebot.lib.constants import emojis
from sizebot.lib.digidecimal import Decimal
from sizebot.lib.language import getPlural, getIndefiniteArticle
from sizebot.lib.language import get_plural, get_indefinite_article
from sizebot.lib.units import SV, WV, Unit, SystemUnit
from sizebot.lib.utils import removeprefix, sentence_join

Expand All @@ -29,14 +29,14 @@ def __init__(self, name, dimension, aliases=[], tags=[], symbol = None, height =

self.name = name
self.dimension = dimension
self.namePlural = getPlural(name)
self.namePlural = get_plural(name)
self.singularNames = aliases + [self.name]
self.aliases = aliases + [getPlural(a) for a in aliases]
self.aliases = aliases + [get_plural(a) for a in aliases]
self.aliases = self.aliases + [a.replace("™", "").replace("®", "") for a in self.aliases + [self.name]] # Remove ®, ™
self.aliases = list(set(self.aliases)) # Remove duplicates
self._tags = tags
self.tags = tags + [getPlural(t) for t in self._tags]
self.article = getIndefiniteArticle(self.name).split(" ")[0]
self.tags = tags + [get_plural(t) for t in self._tags]
self.article = get_indefinite_article(self.name).split(" ")[0]
self.symbol = symbol or None
self.note = note or None

Expand Down Expand Up @@ -66,7 +66,7 @@ def image(self):
# TODO: See issue #153.
return None

def addToUnits(self):
def add_to_units(self):
if self.unitlength is not None:
SV.addUnit(Unit(factor=self.unitlength, name=self.name, namePlural=self.namePlural,
names=self.aliases, symbol = self.symbol))
Expand All @@ -77,7 +77,7 @@ def addToUnits(self):
names=self.aliases, symbol = self.symbol))
WV.addSystemUnit("o", SystemUnit(self.name))

def getStats(self, multiplier = 1):
def get_stats(self, multiplier = 1):
returnstr = ""
if self.height:
returnstr += f"{emojis.blank}**{SV(self.height * multiplier):,.3mu}** tall\n"
Expand All @@ -98,7 +98,7 @@ def getStats(self, multiplier = 1):
returnstr += f"{emojis.blank}**{WV(self.weight * (multiplier ** 3)):,.3mu}**"
return returnstr

def getStatsSentence(self, multiplier = 1, system: Literal["m", "u"] = "m"):
def get_stats_sentence(self, multiplier = 1, system: Literal["m", "u"] = "m"):
statsstrings = []
if self.height:
statsstrings.append(f"**{SV(self.height * multiplier):,.3{system}}** tall")
Expand All @@ -121,7 +121,7 @@ def getStatsSentence(self, multiplier = 1, system: Literal["m", "u"] = "m"):

return returnstr

def getStatsEmbed(self, multiplier = 1):
def get_stats_embed(self, multiplier = 1):
embed = Embed()
embed.set_author(name = f"SizeBot {__version__}")

Expand Down Expand Up @@ -156,26 +156,26 @@ def getStatsEmbed(self, multiplier = 1):
return embed

def stats(self):
return f"{self.article.capitalize()} {self.name} is...\n" + self.getStats()
return f"{self.article.capitalize()} {self.name} is...\n" + self.get_stats()

def statsembed(self):
embed = self.getStatsEmbed()
embed = self.get_stats_embed()
embed.title = self.name
embed.description = f"*{self.note}*" if self.note else None
return embed

def relativestats(self, userdata):
return (f"__{userdata.nickname} is {userdata.height:,.3mu} tall.__\n"
f"To {userdata.nickname}, {self.article} {self.name} looks...\n") \
+ self.getStats(userdata.viewscale)
+ self.get_stats(userdata.viewscale)

def relativestatssentence(self, userdata):
return (f"{userdata.nickname} is {userdata.height:,.3{userdata.unitsystem}} tall."
f" To them, {self.article} {self.name} looks ") \
+ self.getStatsSentence(userdata.viewscale, userdata.unitsystem)
+ self.get_stats_sentence(userdata.viewscale, userdata.unitsystem)

def relativestatsembed(self, userdata):
embed = self.getStatsEmbed(userdata.viewscale)
embed = self.get_stats_embed(userdata.viewscale)
embed.title = self.name + " *[relative]*"
embed.description = (f"__{userdata.nickname} is {userdata.height:,.3mu} tall.__\n"
f"To {userdata.nickname}, {self.article} {self.name} looks...\n")
Expand All @@ -197,7 +197,7 @@ def __lt__(self, other):
return self.unitlength < other

@classmethod
def findByName(cls, name):
def find_by_name(cls, name):
lowerName = name.lower()
for o in objects:
if o == lowerName:
Expand All @@ -209,12 +209,12 @@ def findByName(cls, name):
return None

@classmethod
def fromJson(cls, objJson):
def from_JSON(cls, objJson):
return cls(**objJson)

@classmethod
async def convert(cls, ctx, argument):
obj = cls.findByName(argument)
obj = cls.find_by_name(argument)
if obj is None:
raise errors.InvalidObject(argument)
return obj
Expand All @@ -226,29 +226,29 @@ def __repr__(self) -> str:
return str(self)


def loadObjFile(filename):
def load_obj_file(filename):
try:
fileJson = json.loads(pkg_resources.read_text(sizebot.data.objects, filename))
except FileNotFoundError:
fileJson = None
loadObjJson(fileJson)
load_obj_JSON(fileJson)


def loadObjJson(fileJson):
def load_obj_JSON(fileJson):
for objJson in fileJson:
objects.append(DigiObject.fromJson(objJson))
objects.append(DigiObject.from_JSON(objJson))


def init():
global objects, food, land, tags

for filename in pkg_resources.contents(sizebot.data.objects):
if filename.endswith(".json"):
loadObjFile(filename)
load_obj_file(filename)

objects.sort()
for o in objects:
o.addToUnits()
o.add_to_units()

# cached values
food = [o for o in objects if "food" in o.tags]
Expand Down

0 comments on commit bd6ba58

Please sign in to comment.