Skip to content

Commit

Permalink
Merge pull request #117 from riazufila/optimize-code
Browse files Browse the repository at this point in the history
Optimize code
  • Loading branch information
riazufila authored May 11, 2021
2 parents 21d5455 + 7c4eab1 commit d5dce6b
Show file tree
Hide file tree
Showing 5 changed files with 1,022 additions and 1,378 deletions.
21 changes: 14 additions & 7 deletions cogs/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,20 @@ async def on_command_error(self, ctx, error):
else:
await self.notifyOwner(ctx, error)

await ctx.send(
"I encountered a bug. Don't worry. "
+ "I've logged the bug. However, "
+ "if it still happens, you might "
+ "wanna send a feedback with "
+ "the `feedback` command."
)
if str(ctx.command) in ["rich", "rank"]:
await ctx.send(
"Its a bug for ranking command isn't it? The dev "
+ "is aware. And he's trying to find a workaround "
+ "for it. Hope you'll be patient. Thanks!"
)
else:
await ctx.send(
"I encountered a bug. Don't worry. "
+ "I've logged the bug. However, "
+ "if it still happens, you might "
+ "wanna send a feedback with "
+ "the `feedback` command."
)

# Check bot's latency
@commands.command(
Expand Down
24 changes: 15 additions & 9 deletions cogs/currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ async def rich(self, ctx, scope="server"):

if scope.lower() in ["server"]:
logical_whereabouts = ctx.guild.name
async for member in ctx.guild.fetch_members(limit=None):
for member in ctx.guild.members:
if db_ailie.is_initialized(member.id):
gems = db_ailie.get_gems(member.id)
level = db_ailie.get_user_level(member.id)
Expand All @@ -309,7 +309,7 @@ async def rich(self, ctx, scope="server"):
)
logical_whereabouts = "Global"
for guild in self.bot.guilds:
async for member in guild.fetch_members(limit=None):
for member in guild.members:
if db_ailie.is_initialized(member.id):
gems = db_ailie.get_gems(member.id)
level = db_ailie.get_user_level(member.id)
Expand All @@ -323,6 +323,12 @@ async def rich(self, ctx, scope="server"):
+ "or `global`."
)

# If no one has gems
if not guardian_with_gems:
await ctx.send("No one has gems.")
db_ailie.disconnect()
return

# Display richest user in discord server
guardian_with_gems_sorted = sorted(guardian_with_gems)[::-1]
guardian_with_gems = guardian_with_gems_sorted[:10]
Expand Down Expand Up @@ -394,12 +400,12 @@ async def gems(self, ctx, mention: discord.Member = None):
db_ailie.disconnect()
embed = discord.Embed(
description=(
f"**Current Gems**: `{gems}`"
+ f"\n**Gems Spent**: `{gems_spent}`"
+ f"\n**Gems Gambled**: `{gems_gambled}`"
+ f"\n**Gems Gambled Won**: `{win_gamble_gems}`"
+ f"\n**Gems Gambled Lost**: `{lose_gamble_gems}`"
+ f"\n**Overall Gems Gained**: `{gems_gained}`"
f"**Current Gems**: `{gems:,d}`"
+ f"\n**Gems Spent**: `{gems_spent:,d}`"
+ f"\n**Gems Gambled**: `{gems_gambled:,d}`"
+ f"\n**Gems Gambled Won**: `{win_gamble_gems:,d}`"
+ f"\n**Gems Gambled Lost**: `{lose_gamble_gems:,d}`"
+ f"\n**Overall Gems Gained**: `{gems_gained:,d}`"
),
color=discord.Color.purple()
)
Expand Down Expand Up @@ -466,7 +472,7 @@ async def daily(self, ctx):
db_ailie.store_gained_gems(ctx.author.id, gems)
db_ailie.update_user_exp(ctx.author.id, 5)
await ctx.send(
f"Daily gems claimed for {count} time(s). "
f"Daily gems claimed for {count} time(s) already. "
+ f"You obtained {gems:,d} 💎, <@{ctx.author.id}>!"
)
else:
Expand Down
8 changes: 5 additions & 3 deletions cogs/guardian.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ class Guardian(commands.Cog):
def __init__(self, bot):
self.bot = bot

def heroStatsLevel(self, stats, level, user_level):
def heroStatsLevel(self, stats, hero_level, user_level):
# Increase overall stats
for stat in stats:
if stat in ["attack", "hp", "def"]:
stats[stat] = round(
stats[stat] * ((100 + level + user_level - 1) / 100)
stats[stat]
+ (200 * (((hero_level - 1) / 100) * 2))
+ (200 * (((user_level - 1) / 100) * 2))
)

return stats

def translateToReadableFormat(self, non_readable_format):
print(non_readable_format)
buffer_for_res = non_readable_format[::-1]
if buffer_for_res[3:4] == "_":
buffer_list = []
Expand Down
Loading

0 comments on commit d5dce6b

Please sign in to comment.