Skip to content

Commit bc30c18

Browse files
committed
Refactor some code points
1 parent 0df0f00 commit bc30c18

File tree

6 files changed

+66
-28
lines changed

6 files changed

+66
-28
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,6 @@ cython_debug/
162162
db.sqlite3-shm
163163
db.sqlite3-wal
164164

165-
test.*
165+
test.*
166+
167+
.env*

cogs/inventory.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async def format_page(self, menu: views.Paginator, page: List[InventoryItem]) ->
6565
if item.durability is not None:
6666
stats += f"Durability: {inv_item.durability}/{item.durability}"
6767

68-
embed.add_field(name=f"{item.emoji} {item.display_name}", value=stats, inline=True)
68+
embed.add_field(name=f"{item.name(bold=False)}", value=stats, inline=True)
6969

7070
return embed
7171

@@ -90,7 +90,7 @@ async def _use_item(self, inventory_item: InventoryItem, quantity: int, player:
9090
hp_gained = 8
9191

9292
await player.add_hp(hp_gained)
93-
return f"{cosmetics.EMOJI_HEALTH_HALF} Ate {quantity} **{data.emoji} {data.display_name}** to restore `{hp_gained}` HP."
93+
return f"{cosmetics.EMOJI_HEALTH_HALF} Ate {quantity} {data.name()} to restore `{hp_gained}` HP."
9494
else:
9595
return False
9696

@@ -124,7 +124,7 @@ async def info(self, interaction: discord.Interaction, item: str):
124124

125125
data = self.bot.items[item]
126126
embed = discord.Embed(
127-
title=f"{data.emoji} {data.display_name}",
127+
title=data.name(bold=False),
128128
description=data.description,
129129
color=discord.Color.dark_embed(),
130130
)
@@ -144,7 +144,7 @@ async def info(self, interaction: discord.Interaction, item: str):
144144
embed.add_field(
145145
name="Crafting Recipe",
146146
value=f"\n".join(
147-
f"{amount}x {self.bot.items[reqitem].emoji} {self.bot.items[reqitem].display_name}"
147+
f"{amount}x {self.bot.items[reqitem].name(bold=False)}"
148148
for reqitem, amount in data.crafting_recipe.items()
149149
),
150150
inline=False,
@@ -158,15 +158,15 @@ async def info(self, interaction: discord.Interaction, item: str):
158158
reqitem = self.bot.items[data.smelting_recipe]
159159
embed.add_field(
160160
name="Smelting Recipe",
161-
value=f"{reqitem.emoji} {reqitem.display_name}",
161+
value=reqitem.name(bold=False),
162162
inline=False,
163163
)
164164

165165
if data.smelting_product is not None:
166166
reqitem = self.bot.items[data.smelting_product]
167167
embed.add_field(
168168
name="Smelting Product",
169-
value=f"{reqitem.emoji} {reqitem.display_name}",
169+
value=reqitem.name(bold=False),
170170
inline=False,
171171
)
172172

@@ -210,12 +210,12 @@ async def discard(self, interaction: discord.Interaction, item: str, quantity: s
210210
amount = int(quantity)
211211

212212
if amount > data.quantity:
213-
raise checks.GenericError(f"You don't have this much quantity. You only have `{data.quantity}` **{item_data.emoji} {item_data.display_name}**.")
213+
raise checks.GenericError(f"You don't have this much quantity. You only have `{data.quantity}` {item_data.name()}.")
214214

215215
confirmation = views.Confirmation(user=interaction.user, timeout=30)
216216
embed = discord.Embed(
217217
title=f"{cosmetics.EMOJI_DANGER} Are you sure?",
218-
description=f"You are about to discard `{amount}` **{item_data.emoji} {item_data.display_name}**. After discarding, the item will be lost.",
218+
description=f"You are about to discard `{amount}` {item_data.name()}. After discarding, the item will be lost.",
219219
color=discord.Color.dark_embed(),
220220
)
221221

@@ -226,7 +226,7 @@ async def discard(self, interaction: discord.Interaction, item: str, quantity: s
226226

227227
if confirmation.confirmed:
228228
await data.remove(amount)
229-
message = f"Discarded `{amount}` **{item_data.emoji} {item_data.display_name}**"
229+
message = f"Discarded `{amount}` {item_data.name()}"
230230
else:
231231
message = f"Action canceled. No changes were made."
232232

@@ -267,13 +267,11 @@ async def craft(self, interaction: discord.Interaction, item: str, quantity: int
267267

268268
error_message = ""
269269
if required_item is None:
270-
error_message = f"{cosmetics.EMOJI_WARNING} You need `{crafting_quantity}` **{required_item_data.emoji} " \
271-
f"{required_item_data.display_name}**. You have none."
270+
error_message = f"{cosmetics.EMOJI_WARNING} You need `{crafting_quantity}` {required_item_data.name()}. You have none."
272271
else:
273272
required_quantity = crafting_quantity * quantity
274273
if required_quantity > required_item.quantity:
275-
error_message = f"{cosmetics.EMOJI_WARNING} You need `{required_quantity}` {required_item_data.emoji} " \
276-
f"{required_item_data.display_name}. You currently have `{required_item.quantity}` of it."
274+
error_message = f"{cosmetics.EMOJI_WARNING} You need `{required_quantity}` {required_item_data.name()}. You currently have `{required_item.quantity}` of it."
277275
else:
278276
await required_item.remove(required_quantity)
279277

@@ -284,7 +282,7 @@ async def craft(self, interaction: discord.Interaction, item: str, quantity: int
284282
# craft the given item so add it to inventory.
285283
quantity_crafted = quantity * item_data.crafting_quantity
286284
await InventoryItem.add(player=profile, item_id=item, quantity=quantity_crafted, durability=item_data.durability)
287-
await interaction.edit_original_response(content=f":carpentry_saw: Crafted `{quantity_crafted}` **{item_data.emoji} {item_data.display_name}**", embed=None)
285+
await interaction.edit_original_response(content=f":carpentry_saw: Crafted `{quantity_crafted}` {item_data.name()}", embed=None)
288286

289287
@app_commands.command()
290288
@checks.has_survival_profile()
@@ -320,7 +318,7 @@ async def smelt(self, interaction: discord.Interaction, item: str, quantity: int
320318
)
321319
if inv_item.quantity < quantity:
322320
return await interaction.edit_original_response(
323-
content=f"{cosmetics.EMOJI_WARNING} You only have `{inv_item.quantity}` **{data.emoji} {data.display_name}**.",
321+
content=f"{cosmetics.EMOJI_WARNING} You only have `{inv_item.quantity}` {data.name()}.",
324322
embed=None,
325323
)
326324

@@ -330,14 +328,14 @@ async def smelt(self, interaction: discord.Interaction, item: str, quantity: int
330328

331329
if coal is None:
332330
return await interaction.edit_original_response(
333-
content=f"{cosmetics.EMOJI_WARNING} You need **{coal_data.emoji} {coal_data.display_name}** to smelt items.",
331+
content=f"{cosmetics.EMOJI_WARNING} You need {data.name()} to smelt items.",
334332
embed=None,
335333
)
336334

337335
required_fuel = math.ceil(quantity / 4)
338336
if coal.quantity < required_fuel:
339-
message = f"{cosmetics.EMOJI_WARNING} You need `{required_fuel}` **{coal_data.emoji} {coal_data.display_name}** " \
340-
f"to smelt `{quantity}` **{data.emoji} {data.display_name}**. You only have `{coal.quantity}` of coal."
337+
message = f"{cosmetics.EMOJI_WARNING} You need `{required_fuel}` {coal_data.name()} " \
338+
f"to smelt `{quantity}` {data.name()}. You only have `{coal.quantity}` of coal."
341339

342340
return await interaction.edit_original_response(
343341
content=message,
@@ -351,11 +349,11 @@ async def smelt(self, interaction: discord.Interaction, item: str, quantity: int
351349
xp_gained = random.randint(1, 5)
352350
embed = discord.Embed(
353351
title=":wood: Smelting",
354-
description=f"Successfully smelted `{quantity}` **{data.emoji} {data.display_name}**",
352+
description=f"Successfully smelted `{quantity}` {data.name()}",
355353
color=discord.Color.dark_embed(),
356354
)
357-
embed.add_field(name="Product", value=f"{quantity}x **{item_formed.emoji} {item_formed.display_name}**")
358-
embed.add_field(name="Fuel Used", value=f"{required_fuel}x **{coal_data.emoji} {coal_data.display_name}**")
355+
embed.add_field(name="Product", value=f"{quantity}x {item_formed.name()}")
356+
embed.add_field(name="Fuel Used", value=f"{required_fuel}x {coal_data.name()}")
359357
embed.set_footer(text=f"+{xp_gained} XP")
360358

361359
await interaction.edit_original_response(embed=embed)

cogs/profile.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,38 @@ async def start(self, interaction: discord.Interaction):
5353
"Use various commands to collect valuable resources and use them " \
5454
"to improve your profile. As you get further, you will level up to " \
5555
"higher levels which also gives more amazing perks. Use `/profile view` " \
56-
"to view your profile and progress.\n\nGood Luck!",
56+
"to view your profile and progress. A few tips have been added for you below.\n\nGood Luck!",
5757
color=discord.Color.green(),
5858
)
59+
60+
embed.add_field(
61+
name="Profile",
62+
value="Manage your profile from `/profile` command group. View your statistics, " \
63+
"most importantly your health from `/profile view` command. **Don't forget to eat " \
64+
"to heal yourself otherwise dying resets your levels!**",
65+
inline=False,
66+
)
67+
embed.add_field(
68+
name="Inventory",
69+
value="Manage your inventory from `/inventory` command group. Craft and smelt items to " \
70+
"produce useful tools and items. Use `/inventory info` to get information about items " \
71+
"and `/inventory craft/smelt` to craft or smelt items. To use an item (e.g. eating food), use " \
72+
"`/inventory use`.",
73+
inline=False,
74+
)
75+
embed.add_field(
76+
name="Collecting Resources",
77+
value="`/explore` command is your first step towards collecting resources. You can " \
78+
"explore different biomes using this command with each biome having specific loot. " \
79+
"As you explore more, you'll discover more rarer biomes which will have even better loot. " \
80+
"Other commands for collecting resources are `/mine` and `/fish`.",
81+
inline=False,
82+
)
83+
embed.add_field(
84+
name="Learn More",
85+
value="To get info on how something works, use the [docs](https://github.com/izxxr/cobble-bot/tree/main/docs).",
86+
inline=False
87+
)
5988

6089
await interaction.response.send_message(embed=embed)
6190

cogs/survival.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def _generate_loot_embed(self, loot: ObtainedLootT, title: str, description: str
126126
)
127127

128128
embed.add_field(name="Collected Loot", value="\n".join(
129-
f"{x[1]}x {x[0].emoji} {x[0].display_name}"
129+
f"{x[1]}x {x[0].name(bold=False)}"
130130
for x in loot))
131131

132132
if xp_gained:
@@ -138,7 +138,7 @@ def _item_break_embed(self, item_id: str) -> discord.Embed:
138138
item = self.bot.items[item_id]
139139
embed = discord.Embed(
140140
title=":adhesive_bandage: Item Broken",
141-
description=f"Your **{item.emoji} {item.display_name}** just broke.",
141+
description=f"Your {item.name()} just broke.",
142142
color=discord.Color.red(),
143143
)
144144

@@ -196,7 +196,7 @@ async def explore(self, interaction: discord.Interaction):
196196
embed = self._generate_loot_embed(
197197
loot,
198198
title=":hiking_boot: Exploration",
199-
description=f"You explored the **{view.selected_biome.emoji} {view.selected_biome.display_name}**",
199+
description=f"You explored the {view.selected_biome.name()}",
200200
xp_gained=xp_gained,
201201
)
202202

@@ -226,7 +226,7 @@ async def explore(self, interaction: discord.Interaction):
226226
color=discord.Color.dark_embed(),
227227
)
228228

229-
embed.add_field(name="Biome", value=f"{discovered_biome.emoji} {discovered_biome.display_name}")
229+
embed.add_field(name="Biome", value=discovered_biome.name(bold=False))
230230
embed.add_field(name="Information", value=discovered_biome.description)
231231
embed.add_field(name="Rarity", value=discovered_biome.rarity.title())
232232
embed.set_image(url=discovered_biome.background)
@@ -248,7 +248,7 @@ async def fish(self, interaction: discord.Interaction):
248248
if invitem is None:
249249
fishing_rod = self.bot.items["fishing_rod"]
250250
return await interaction.edit_original_response(
251-
content=f"{cosmetics.EMOJI_WARNING} You need a **{fishing_rod.emoji} {fishing_rod.display_name}** to fish.",
251+
content=f"{cosmetics.EMOJI_WARNING} You need a {fishing_rod.name()} to fish.",
252252
embed=None,
253253
)
254254

core/datamodels/biome.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ def discovered(self, player: Player) -> bool:
5252
if val == 0:
5353
return True
5454
return (player.achievements & val) == val
55+
56+
def name(self, bold: bool = True) -> str:
57+
n = f"{self.emoji} {self.display_name}"
58+
return f"**{n}**" if bold else n

core/datamodels/item.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,8 @@ class Item:
4646
durability: Optional[int] = None
4747
crafting_quantity: int = 1
4848
food_hp_restored: Optional[float] = None
49+
50+
51+
def name(self, bold: bool = True) -> str:
52+
n = f"{self.emoji} {self.display_name}"
53+
return f"**{n}**" if bold else n

0 commit comments

Comments
 (0)