Skip to content

Commit

Permalink
Merge pull request #185 from MiscGuild/backend-redo
Browse files Browse the repository at this point in the history
Backend redo
  • Loading branch information
Amxgh authored Apr 8, 2024
2 parents a79fc47 + 55063fc commit 86f4a49
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 68 deletions.
18 changes: 0 additions & 18 deletions src/cogs/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,5 @@ async def invites(self, ctx, name: str = None):
res = await String(string=name).invites()
await ctx.respond(embed=res)

@bridge.bridge_command(aliases=["validate"])
@option(
name="name",
description="The username of the player whose invites you'd like to validate",
required=False,
input_type=str
)
async def validate_invites(self, ctx, name: str = None):
"""View the given user's last week's invitation stats."""
await ctx.defer()
if not name:
uuid, username = await get_db_uuid_username_from_discord_id(ctx.author.id)
res = await String(uuid=uuid, username=username).validate_invites()
else:
res = await String(string=name).validate_invites()
await ctx.respond(embed=res)


def setup(bot):
bot.add_cog(Guild(bot))
2 changes: 1 addition & 1 deletion src/cogs/tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def register(self, ctx, name: str):
await ctx.respond(embed=res)
if guest_ticket:
await ctx.followup.send(f"Head on over to <#{guest_ticket.id}>!", ephemeral=True)
if isinstance(res, String):
elif isinstance(res, str):
await ctx.respond(res)

@bridge.bridge_command(aliases=["del"])
Expand Down
72 changes: 24 additions & 48 deletions src/func/String.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ async def qotd(self, ctx):
day_number = 473 + (datetime.utcnow() - datetime.strptime("2022/05/15", "%Y/%m/%d")).days
embed = discord.Embed(
title=f"**{self.string}\n**",
description=f"You can respond to this qotd in: <#{qotd_ans_channel_id}>", color=neutral_color)
description=f"Respond in: <#{qotd_ans_channel_id}>", color=neutral_color)
embed.set_author(
name=f"Day {day_number}: {datetime.utcnow().day} {months[datetime.utcnow().month]} {datetime.utcnow().year}")
embed.set_footer(text="- " + ctx.author.nick if ctx.author.nick else ctx.author.name)
Expand All @@ -299,60 +299,36 @@ async def invites(self):
invites_text = ""
if not invites:
weekly_invites, total_invites, total_valid_invites = None, "0", "0"
valid_invites = []
else:
weekly_invites, total_invites, total_valid_invites = invites
weekly_invites = weekly_invites.split()
weekly_invites = [await get_name_by_uuid(invitee) for invitee in weekly_invites]
valid_invites = await check_invitation_validity(weekly_invites)
weekly_invites_dict = {}
for invitee in weekly_invites:
invites_text += f"**▸** {invitee}\n"
weekly_invites_dict[invitee] = await get_name_by_uuid(invitee)

valid_invites = [weekly_invites_dict[invitee] for invitee in valid_invites]

for invitee in weekly_invites_dict.values():
if invitee in valid_invites:
invites_text += f"🟢 {invitee}\n"
else:
invites_text += f"🔴 {invitee}\n"
embed = discord.Embed(title=f"{name}'s Invites", color=neutral_color)
embed.add_field(name="Weekly Invites", value=None if not invites_text else invites_text, inline=False)
embed.add_field(name="Total Invites", value=total_invites, inline=True)
embed.add_field(name="This week's statistics", value=f"Total Valid Invites: {len(valid_invites)}\n"
f"Total Invites: {len(weekly_invites)}\n"
f"Success Rate: {round(len(valid_invites) * 100 / len(weekly_invites)) if len(weekly_invites) else 0}%",
inline=False)
embed.add_field(name="Total Valid Invites", value=total_valid_invites, inline=True)
embed.add_field(name="Total Invites", value=total_invites, inline=True)
embed.add_field(name="Total Success Rate",
value=f"{round(total_valid_invites * 100 / total_invites if total_invites else 0)}%",
inline=True)
embed.set_footer(text="Total invites and total valid invites do not include this week's invites. They are "
"updated at the end of the week.\nAn invite is considered valid if they earn "
f"2 * {format(member_req, ',d')} at the end of the week. "
"updated at the end of the week."
"\nAn invite is considered valid if they earn "
f"{format(2 * member_req, ',d')} guild experience at the end of the week. "
"If they joined in the middle of the week, their guild experience will be scaled up.")
return embed

async def validate_invites(self):
if self.uuid and self.username:
uuid = self.uuid
name = self.username
else:
name, uuid = await get_mojang_profile(self.string)
if not name:
return unknown_ign_embed
invites = await get_invites(uuid)
if not invites:
return discord.Embed(title=f"{name} has no invites.", color=neg_color)

weekly_invites, total_invites, total_valid_invites = invites
if not weekly_invites:
return discord.Embed(title=f"{name} has no invites this week.", color=neg_color).set_footer(
text=f"Total Invites: {total_invites}\n Total Valid Invites: {total_valid_invites}")
weekly_invitations = []
valid_invites_text, invalid_invites_text = "", ""
weekly_uuids = weekly_invites.split()

valid_invites = await check_invitation_validity(weekly_uuids)

weekly_invite_names = [await get_name_by_uuid(invitee) for invitee in weekly_uuids]
valid_invite_names = [await get_name_by_uuid(invitee) for invitee in valid_invites]

invalid_invite_names = list(set(weekly_invite_names) - set(valid_invite_names))

for invitee in valid_invite_names:
valid_invites_text += f"**▸** {invitee}\n"
for invitee in invalid_invite_names:
invalid_invites_text += f"{invitee}, "

embed = discord.Embed(title=f"{name}'s Valid Invites this week:",
description=f"{valid_invites_text}",
color=neutral_color)
embed.add_field(name="This Week's Statistics:",
value=f"Invites: {len(weekly_invite_names)}\n"
f"Valid Invites: {len(valid_invite_names)}\n"
f"Success Rate: {round(100 * len(valid_invite_names) / len(weekly_invite_names)) if len(weekly_invite_names) else 0}%")
embed.set_footer(text=f"Invalid Invites: {invalid_invites_text[:-2]}")
return embed
2 changes: 1 addition & 1 deletion src/func/Union.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async def register(self, ctx, name):
await ctx.defer()
# Make sure it is only used in registration channel
if ctx.channel.id != registration_channel_id:
return "This command can only be used in the registration channel!", None
return "This command can only be used in the registration channel!\nThe command you are looking for is `/sync`", None

ign, uuid = await get_mojang_profile(name)

Expand Down

0 comments on commit 86f4a49

Please sign in to comment.