None fix, more likely
This commit is contained in:
parent
1100294a20
commit
5ee1a6a84b
@ -3,7 +3,8 @@ from redbot.core import data_manager
|
|||||||
from .planttycoon import PlantTycoon
|
from .planttycoon import PlantTycoon
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
async def setup(bot):
|
||||||
tycoon = PlantTycoon(bot)
|
tycoon = PlantTycoon(bot)
|
||||||
data_manager.load_bundled_data(tycoon, __file__)
|
data_manager.load_bundled_data(tycoon, __file__)
|
||||||
|
await tycoon._load_plants_products() # I can access protected members if I want, linter!!
|
||||||
bot.add_cog(tycoon)
|
bot.add_cog(tycoon)
|
||||||
|
@ -39,7 +39,7 @@ class Gardener:
|
|||||||
self.user, self.badges, self.points, self.products, self.current
|
self.user, self.badges, self.points, self.products, self.current
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _load_config(self):
|
async def load_config(self):
|
||||||
self.badges = await self.config.user(self.user).badges()
|
self.badges = await self.config.user(self.user).badges()
|
||||||
self.points = await self.config.user(self.user).points()
|
self.points = await self.config.user(self.user).points()
|
||||||
self.products = await self.config.user(self.user).products()
|
self.products = await self.config.user(self.user).products()
|
||||||
@ -52,6 +52,7 @@ class Gardener:
|
|||||||
await self.config.user(self.user).current.set(self.current)
|
await self.config.user(self.user).current.set(self.current)
|
||||||
|
|
||||||
async def is_complete(self, now):
|
async def is_complete(self, now):
|
||||||
|
|
||||||
message = None
|
message = None
|
||||||
if self.current:
|
if self.current:
|
||||||
then = self.current["timestamp"]
|
then = self.current["timestamp"]
|
||||||
@ -71,7 +72,11 @@ class Gardener:
|
|||||||
)
|
)
|
||||||
if health < 0:
|
if health < 0:
|
||||||
message = "Your plant died!"
|
message = "Your plant died!"
|
||||||
return message
|
|
||||||
|
if message is not None:
|
||||||
|
self.current = {}
|
||||||
|
await self.save_gardener()
|
||||||
|
await self.user.send(message)
|
||||||
|
|
||||||
|
|
||||||
async def _die_in(gardener, degradation):
|
async def _die_in(gardener, degradation):
|
||||||
@ -184,6 +189,9 @@ class PlantTycoon(Cog):
|
|||||||
with product_path.open() as json_data:
|
with product_path.open() as json_data:
|
||||||
self.products = json.load(json_data)
|
self.products = json.load(json_data)
|
||||||
|
|
||||||
|
for product in self.products:
|
||||||
|
print("Loaded {}".format(product))
|
||||||
|
|
||||||
async def _gardener(self, user: discord.User) -> Gardener:
|
async def _gardener(self, user: discord.User) -> Gardener:
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -191,7 +199,7 @@ class PlantTycoon(Cog):
|
|||||||
#
|
#
|
||||||
|
|
||||||
g = Gardener(user, self.config)
|
g = Gardener(user, self.config)
|
||||||
await g._load_config()
|
await g.load_config()
|
||||||
return g
|
return g
|
||||||
|
|
||||||
async def _degradation(self, gardener: Gardener):
|
async def _degradation(self, gardener: Gardener):
|
||||||
@ -442,13 +450,13 @@ class PlantTycoon(Cog):
|
|||||||
em.add_field(name="**Products**", value="None")
|
em.add_field(name="**Products**", value="None")
|
||||||
else:
|
else:
|
||||||
products = ""
|
products = ""
|
||||||
for product in gardener.products:
|
for product_name, product_data in gardener.products.items():
|
||||||
if products is None:
|
if self.products[product_name] is None:
|
||||||
continue
|
continue
|
||||||
products += "{} ({}) {}\n".format(
|
products += "{} ({}) {}\n".format(
|
||||||
product.capitalize(),
|
product_name.capitalize(),
|
||||||
gardener.products[product] / self.products[product.lower()]["uses"],
|
product_data / self.products[product_name]["uses"],
|
||||||
self.products[product]["modifier"],
|
self.products[product_name]["modifier"],
|
||||||
)
|
)
|
||||||
em.add_field(name="**Products**", value=products)
|
em.add_field(name="**Products**", value=products)
|
||||||
if gardener.current:
|
if gardener.current:
|
||||||
@ -721,7 +729,7 @@ class PlantTycoon(Cog):
|
|||||||
gardener.current["degrade_count"] += degradation_count
|
gardener.current["degrade_count"] += degradation_count
|
||||||
await gardener.save_gardener()
|
await gardener.save_gardener()
|
||||||
|
|
||||||
await self.check_completion(gardener, now, gardener.user)
|
await gardener.is_complete(now)
|
||||||
|
|
||||||
async def check_completion_loop(self):
|
async def check_completion_loop(self):
|
||||||
while "PlantTycoon" in self.bot.cogs:
|
while "PlantTycoon" in self.bot.cogs:
|
||||||
@ -738,13 +746,6 @@ class PlantTycoon(Cog):
|
|||||||
pass
|
pass
|
||||||
await asyncio.sleep(self.defaults["timers"]["completion"] * 60)
|
await asyncio.sleep(self.defaults["timers"]["completion"] * 60)
|
||||||
|
|
||||||
async def check_completion(self, gardener, now, user):
|
|
||||||
message = await gardener.is_complete(now)
|
|
||||||
if message is not None:
|
|
||||||
gardener.current = {}
|
|
||||||
await gardener.save_gardener()
|
|
||||||
await user.send(message)
|
|
||||||
|
|
||||||
async def send_notification(self):
|
async def send_notification(self):
|
||||||
while "PlantTycoon" in self.bot.cogs:
|
while "PlantTycoon" in self.bot.cogs:
|
||||||
users = await self.config.all_users()
|
users = await self.config.all_users()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user