Skip to content

Commit

Permalink
Adds rank thumbail. Resolves #12. Starting work on #23.
Browse files Browse the repository at this point in the history
  • Loading branch information
LevBernstein committed Nov 22, 2021
1 parent 913d5b1 commit 898a45d
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 133 deletions.
29 changes: 16 additions & 13 deletions Bot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
""" Beardless Bot """
__version__ = "Full Release 1.6.12"
__version__ = "Full Release 1.6.13"

import asyncio
from random import choice, randint
Expand Down Expand Up @@ -403,7 +403,7 @@ async def cmdAnimal(ctx, breed=None, *args):
if species == "moose" or (breed and breed.lower() == "moose"):
await ctx.send(
file=discord.File(
f"resources/images/moose/moose{randint(1, 72)}.jpg"
f"resources/images/moose/moose{randint(1, 75)}.jpg"
)
)
return
Expand Down Expand Up @@ -512,13 +512,11 @@ async def cmdMute(ctx, target=None, duration=None, *args):
report = "Muted " + target.mention
report += (" for " + duration + mString + ".") if mTime else "."
emb = misc.bbEmbed("Beardless Bot Mute", report).set_author(
name=str(ctx.author), icon_url=ctx.author.avatar_url
name=ctx.author, icon_url=ctx.author.avatar_url
)
if args:
emb.add_field(
name="Mute Reason:",
value=" ".join(args),
inline=False
name="Mute Reason:", value=" ".join(args), inline=False
)
await ctx.send(embed=emb)
# Iterate through channels, make Muted unable to send msgs
Expand Down Expand Up @@ -585,11 +583,10 @@ async def cmdPurge(ctx, num=None, *args):
try:
mNum = int(num)
except ValueError:
await ctx.send(
embed=misc.bbEmbed(
"Beardless Bot Purge", "Invalid message number!"
)
emb = misc.bbEmbed(
"Beardless Bot Purge", "Invalid message number!"
)
await ctx.send(embed=emb)
else:
await ctx.channel.purge(
limit=mNum + 1, check=lambda msg: not msg.pinned
Expand Down Expand Up @@ -743,7 +740,9 @@ async def cmdBrawlclaim(ctx, profUrl="None", *args):
else:
report = "Invalid profile URL/Brawlhalla ID! " if profUrl else ""
report += brawl.badClaim
await ctx.send(embed=misc.bbEmbed("Beardless Bot Brawlhalla Rank", report))
await ctx.send(
embed=misc.bbEmbed("Beardless Bot Brawlhalla Rank", report)
)


@bot.command(name="brawlrank")
Expand All @@ -762,7 +761,9 @@ async def cmdBrawlrank(ctx, target=None, *args):
except Exception as err:
print(err)
report = brawl.reqLimit
await ctx.send(embed=misc.bbEmbed("Beardless Bot Brawlhalla Rank", report))
await ctx.send(
embed=misc.bbEmbed("Beardless Bot Brawlhalla Rank", report)
)


@bot.command(name="brawlstats")
Expand Down Expand Up @@ -802,7 +803,9 @@ async def cmdBrawlclan(ctx, target=None, *args):
except Exception as err:
print(err)
report = brawl.reqLimit
await ctx.send(embed=misc.bbEmbed("Beardless Bot Brawlhalla Clan", report))
await ctx.send(
embed=misc.bbEmbed("Beardless Bot Brawlhalla Clan", report)
)


@bot.command(name="brawllegend")
Expand Down
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Beardless Bot

### Full Release 1.6.12
### Full Release 1.6.13

A Discord bot supporting gambling (coin flips and blackjack),
a currency system, fun facts, and more.
Expand Down
7 changes: 1 addition & 6 deletions bb_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ def test_dice():
sideRoll = misc.roll(message)
assert 1 <= sideRoll and sideRoll <= sideNum
assert (
misc.rollReport(message, user)
.description
.startswith("You got")
misc.rollReport(message, user).description.startswith("You got")
)
sideRoll = misc.roll("d20-4")
assert -3 <= sideRoll and sideRoll <= 16
Expand Down Expand Up @@ -560,16 +558,13 @@ def test_animal():
"b'\\xff\\xd8\\xff\\xe1\\tPh"
)
for animalName in misc.animalList[:-4]:
print(animalName)
r = requests.get(misc.animal(animalName))
assert r.ok and r.headers["content-type"] in imageTypes

for animalName in misc.animalList[-4:]:
print(animalName)
# Koala, Bird, Raccoon, Kangaroo APIs lack a content-type field;
# check if URL points to an image instead
r = requests.get(misc.animal(animalName))
print(str(r.content)[:30])
assert r.ok and any(
str(r.content).startswith(signature) for signature in imageSigs
)
Expand Down
59 changes: 32 additions & 27 deletions brawl.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@
"eu": 0
}

thumbBase = (
"https://static.wikia.nocookie.net/brawlhalla_gamepedia/images/"
"{}/Banner_Rank_{}.png/revision/latest/scale-to-width-down/{}"
)

rankedThumbnails = {
"Diamond": ("4/46", "Diamond", "84?cb=20161110140154"),
"Platinum": ("6/6e", "Platinum", "102?cb=20161110140140"),
"Gold": ("6/69", "Gold", "109?cb=20161110140126"),
"Silver": ("5/5c", "Silver", "119?cb=20161110140055"),
"Bronze": ("a/a6", "Bronze", "112?cb=20161110140114"),
"Tin": ("e/e1", "Tin", "112?cb=20161110140036")
}


def pingMsg(target: discord.Member, h: int, m: int, s: int) -> str:
def plural(t):
Expand All @@ -57,8 +71,7 @@ def randomBrawl(ranType: str, key: str = None) -> discord.Embed:
if ranType in ("legend", "weapon"):
if ranType == "legend":
choices = tuple(
legend["legend_name_key"].title()
for legend in fetchLegends()
legend["legend_name_key"].title() for legend in fetchLegends()
)
else:
choices = (
Expand All @@ -82,8 +95,7 @@ def randomBrawl(ranType: str, key: str = None) -> discord.Embed:
f"Your {ranType} is {choice(choices)}."
)
return bbEmbed(
"Brawlhalla Randomizer",
"Please do !random legend or !random weapon."
"Brawlhalla Randomizer", "Please do !random legend or !random weapon."
)


Expand Down Expand Up @@ -118,7 +130,7 @@ def getBrawlID(brawlKey: str, profileURL: str) -> int:
.format(steamID, brawlKey)
)
return r.json()["brawlhalla_id"]
except Exception:
except KeyError:
return None


Expand Down Expand Up @@ -218,7 +230,7 @@ def getRank(target: discord.Member, brawlKey: str) -> discord.Embed:
emb = (
bbEmbed(f"{r['name']}, {r['region']}")
.set_footer(text=f"Brawl ID {brawlID}")
.set_author(name=str(target), icon_url=target.avatar_url)
.set_author(name=target, icon_url=target.avatar_url)
)
if "games" in r:
winRate = round(r["wins"] / r["games"] * 100, 1)
Expand All @@ -240,6 +252,9 @@ def getRank(target: discord.Member, brawlKey: str) -> discord.Embed:
for key, value in rankColors.items():
if key in r["tier"]:
emb.color = value
emb.set_thumbnail(
url=thumbBase.format(*rankedThumbnails[key])
)
break
if "2v2" in r:
twosTeam = None
Expand All @@ -251,25 +266,24 @@ def getRank(target: discord.Member, brawlKey: str) -> discord.Embed:
emb.add_field(
name="Ranked 2s",
value=(
"**{}\n{}** ({} / {} Peak)\n"
"{} W / {} L / {}% winrate"
).format(
twosTeam["teamname"],
twosTeam["tier"],
twosTeam["rating"],
twosTeam["peak_rating"],
twosTeam["wins"],
twosTeam["games"] - twosTeam["wins"],
round(twosTeam["wins"] / twosTeam["games"] * 100, 1)
f"**{twosTeam['teamname']}\n"
f"{twosTeam['tier']}** ({twosTeam['rating']} /"
f" {twosTeam['peak_rating']} Peak)\n{twosTeam['wins']}"
f" W / {twosTeam['games'] - twosTeam['wins']} L /"
f" {round(twosTeam['wins'] / twosTeam['games'] * 100, 1)}"
"% winrate"
)
)
if (
emb.color == discord.Color(0xFFF994)
emb.color.value == 0xFFF994
or twosTeam["rating"] > r["rating"]
):
for key, value in rankColors.items():
if key in twosTeam["tier"]:
emb.color = value
emb.set_thumbnail(
url=thumbBase.format(*rankedThumbnails[key])
)
break
return emb

Expand Down Expand Up @@ -299,7 +313,7 @@ def getStats(target: discord.Member, brawlKey: str) -> discord.Embed:
.set_footer(text=f"Brawl ID {brawlID}")
.add_field(name="Name", value=r["name"])
.add_field(name="Overall W/L", value=embVal)
.set_author(name=str(target), icon_url=target.avatar_url)
.set_author(name=target, icon_url=target.avatar_url)
)
if "legends" in r:
topUsed = topWinrate = topDPS = topTTK = None
Expand Down Expand Up @@ -382,15 +396,6 @@ def getClan(target: discord.Member, brawlKey: str) -> discord.Embed:
).set_footer(text=f"Clan ID {r['clan_id']}")
for i in range(min(len(r["clan"]), 9)):
member = r["clan"][i]
emb.add_field(
name=member["name"],
value="{} ({} xp)\nJoined {}"
.format(
member["rank"],
member["xp"],
str(datetime.fromtimestamp(member["join_date"]))[:-9]
)
)
emb.add_field(
name=member["name"],
value=(
Expand Down
Loading

0 comments on commit 898a45d

Please sign in to comment.