From 9c1b274c6f3d8f7966d1ac81bb635ac84c21652f Mon Sep 17 00:00:00 2001 From: Amogh Date: Fri, 20 Oct 2023 08:01:08 -0500 Subject: [PATCH 01/12] fix: /invites now throws an appropriate error message if a non-guild member uses the command --- src/func/String.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/func/String.py b/src/func/String.py index e2d210fb..b4d47a54 100644 --- a/src/func/String.py +++ b/src/func/String.py @@ -285,8 +285,9 @@ async def invites(self): return unknown_ign_embed guild = await get_player_guild(uuid) - if guild["name"] != guild_handle: + if ("name" not in guild) or (guild["name"] != guild_handle): return missing_permissions_embed + invites = await get_invites(uuid) invites_text = "" if not invites: From 569d2b289b3babe497fa4a61bb98e3614c5a54c8 Mon Sep 17 00:00:00 2001 From: Amogh Date: Fri, 20 Oct 2023 08:02:47 -0500 Subject: [PATCH 02/12] feat: removed "reference" as an argument for /register --- src/cogs/tickets.py | 10 ++-------- src/func/Union.py | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/cogs/tickets.py b/src/cogs/tickets.py index f3b18278..61b164dd 100644 --- a/src/cogs/tickets.py +++ b/src/cogs/tickets.py @@ -24,15 +24,9 @@ def __init__(self, bot): required=True, input_type=str ) - @option( - name="reference", - description="MEMBERS OF MISC: The name of the person who invited you to Miscellaneous", - required=False, - input_type=str - ) - async def register(self, ctx, name: str, reference: str = None): + async def register(self, ctx, name: str): """Register with your IGN to sync your roles!""" - res = await Union(user=ctx.author).register(ctx, name, reference) + res = await Union(user=ctx.author).register(ctx, name) if isinstance(res, discord.Embed): await ctx.respond(embed=res) if isinstance(res, String): diff --git a/src/func/Union.py b/src/func/Union.py index 34011093..159bb701 100644 --- a/src/func/Union.py +++ b/src/func/Union.py @@ -152,7 +152,7 @@ async def sync(self, ctx, name: str, tag: str = None, is_fs=False): return embed - async def register(self, ctx, name, reference): + 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: From 5618fe829d82ba826340963a5d9a92bbffc7c933 Mon Sep 17 00:00:00 2001 From: Amogh Date: Fri, 20 Oct 2023 11:04:16 -0500 Subject: [PATCH 03/12] refactor: fixed a typo --- src/utils/discord_utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils/discord_utils.py b/src/utils/discord_utils.py index f0fa6a7f..3c81710d 100644 --- a/src/utils/discord_utils.py +++ b/src/utils/discord_utils.py @@ -112,14 +112,15 @@ async def callback(self, interaction: discord.Interaction): ["What was the username of the accused", "", discord.InputTextStyle.short, "Username of the accused"], ["What was the offense?", "", discord.InputTextStyle.short, "Offense"], - ["When did this happen?", "", discord.InputTextStyle.short, "TIme of Offense"], + ["When did this happen?", "", discord.InputTextStyle.short, "Time of Offense"], ["Provide a brief description of what happened.", "Answer the question in no more than 100 words.", discord.InputTextStyle.long, "Description"] ] embed = discord.Embed(title="Player Report", color=neutral_color) await interaction.response.send_modal( - modal=uiutils.ModalCreator(embed=embed, fields=fields, ign=ign, title="Player Report")) + modal=uiutils.ModalCreator(embed=embed, fields=fields, ign=ign, uuid=uuid, title="Player Report")) + if option == "Query/Problem": await ticket.edit(name=f"general-{ign}", topic=f"{interaction.user.id}|", category=discord.utils.get(interaction.guild.categories, From 5214e24cba6f0607c01c40d3af971ec0f291a306 Mon Sep 17 00:00:00 2001 From: Amogh Date: Fri, 20 Oct 2023 11:04:38 -0500 Subject: [PATCH 04/12] feat: wrote a new function that returns the number entries --- src/utils/referral_utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/utils/referral_utils.py b/src/utils/referral_utils.py index ea7ab017..2c8a77c1 100644 --- a/src/utils/referral_utils.py +++ b/src/utils/referral_utils.py @@ -51,7 +51,14 @@ async def check_invitation_validity(invitations: list): return weekly_valid_invites -async def generate_rank_upgrade(weekly_invites: list): +async def get_entries(gexp): + if gexp < active_req: + return 1 + else: + return round(50 * (1 - exp(-gexp / 500000))) + + +async def generate_rank_upgrade(weekly_invites : list): guild_data = await get_guild_by_name(guild_handle) members = await get_gexp_sorted(guild_data) entries = {} From 39a686cfd83910a6e4b22655c989c01c6204462d Mon Sep 17 00:00:00 2001 From: Amogh Date: Fri, 20 Oct 2023 11:05:59 -0500 Subject: [PATCH 05/12] refactor: removed unused parameter --- src/utils/referral_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/referral_utils.py b/src/utils/referral_utils.py index 2c8a77c1..5439618b 100644 --- a/src/utils/referral_utils.py +++ b/src/utils/referral_utils.py @@ -9,7 +9,7 @@ from src.utils.request_utils import get_mojang_profile, get_player_guild, get_guild_by_name, get_name_by_uuid -async def validate_reference(ctx, invitee_uuid, inviter_ign): +async def validate_reference(invitee_uuid, inviter_ign): inviter_ign, inviter_uuid = await get_mojang_profile(inviter_ign) if inviter_ign else (None, None) if not inviter_uuid: return f"{inviter_ign} is not a valid minecraft username.\nThis reference will not count." From c8c5c667e04feb9a944fe575a3fadbf1e8d6305f Mon Sep 17 00:00:00 2001 From: Amogh Date: Fri, 20 Oct 2023 11:06:48 -0500 Subject: [PATCH 06/12] feat: ModalCreator now accepts and calls a function feild. --- src/utils/ui_utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/utils/ui_utils.py b/src/utils/ui_utils.py index ab74e07a..72a91bc9 100644 --- a/src/utils/ui_utils.py +++ b/src/utils/ui_utils.py @@ -316,13 +316,15 @@ async def callback(self, interaction: discord.Interaction): class ModalCreator(discord.ui.Modal): - def __init__(self, embed: discord.Embed, fields: list, title: str, ign: str) -> None: + def __init__(self, embed: discord.Embed, fields: list, title: str, ign: str, uuid: str,function = None) -> None: # fields = ["LABEL", "PLACEHOLDER", STYLE] super().__init__(title=title) self.embed = embed self.ign = ign + self.uuid = uuid self.fields = fields self.title = title + self.function = function for field in fields: self.add_item(discord.ui.InputText(label=field[0], placeholder=field[1], @@ -334,6 +336,9 @@ async def callback(self, interaction: discord.Interaction): self.embed.add_field(name=field[3], value=self.children[count].value, inline=False) + if self.function: + await self.function(self.uuid, self.children[count].value) count += 1 await interaction.response.send_message(embeds=[self.embed]) + From 93b301859c16ebea7879a7a78a0250a0c1d02ed1 Mon Sep 17 00:00:00 2001 From: Amogh Date: Fri, 20 Oct 2023 11:07:35 -0500 Subject: [PATCH 07/12] feat: /register now initiates a modal asking for a reference if the player is a member of msicellaneous --- src/func/Union.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/func/Union.py b/src/func/Union.py index 159bb701..f2c1ad89 100644 --- a/src/func/Union.py +++ b/src/func/Union.py @@ -5,6 +5,8 @@ from typing import Union import discord +import src.utils.ui_utils as uiutils + from src.utils.consts import (active_req, allies, discord_not_linked_embed, guild_handle, neg_color, neutral_color, pos_color, registration_channel_id, @@ -153,7 +155,6 @@ async def sync(self, ctx, name: str, tag: str = None, is_fs=False): return embed 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!" @@ -172,10 +173,13 @@ async def register(self, ctx, name): guild_name = "Guildless" if not guild_data else guild_data["name"] - reference_message = None + + + + getReference = False # User is a member if guild_name == guild_handle: - reference_message = await validate_reference(ctx, uuid, reference) if reference else None + getReference = True await ctx.author.add_roles(bot.member_role, reason="Registration - Member") @@ -254,9 +258,18 @@ async def callback(self, interaction: discord.Interaction): embed = discord.Embed( title="Registration successful!", color=neutral_color) embed.set_thumbnail(url=f'https://minotar.net/helm/{uuid}/512.png') - if reference_message: - embed.set_footer(text=reference_message) - return embed.add_field(name=ign, value=f"Member of {guild_name}") + + embed.add_field(name=ign, value=f"Member of {guild_name}") + if getReference: + + fields = [ + ["Who invited you to Miscellaneous on Hypixel?", "Enter NONE if you joined on your own.", discord.InputTextStyle.short, + "Invited by:"] + ] + await ctx.response.send_modal( + modal=uiutils.ModalCreator(embed=embed, fields=fields, ign=ign, uuid=uuid,title="Player Reference", function=validate_reference)) + else: + return embed async def add(self, ctx): if ctx.channel.category.name not in ticket_categories.values(): From bcd2070cc597dc8194c002189c1d1e94ac9a3274 Mon Sep 17 00:00:00 2001 From: Amogh Date: Fri, 20 Oct 2023 11:08:01 -0500 Subject: [PATCH 08/12] feat: /register is now slash-command only. --- src/cogs/tickets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cogs/tickets.py b/src/cogs/tickets.py index 61b164dd..67c55de6 100644 --- a/src/cogs/tickets.py +++ b/src/cogs/tickets.py @@ -17,7 +17,7 @@ class Tickets(commands.Cog, name="tickets"): def __init__(self, bot): self.bot = bot - @bridge.bridge_command(aliases=["reg", "verify"]) + @commands.slash_command() @option( name="name", description="Your Minecraft username", From 0075bb3d99cde903f1e7d6c16d398ab5653a69a4 Mon Sep 17 00:00:00 2001 From: Amogh Date: Fri, 20 Oct 2023 11:08:51 -0500 Subject: [PATCH 09/12] feat: redid the entry system --- src/utils/referral_utils.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/utils/referral_utils.py b/src/utils/referral_utils.py index 5439618b..372e1ecc 100644 --- a/src/utils/referral_utils.py +++ b/src/utils/referral_utils.py @@ -1,6 +1,6 @@ from __main__ import bot from datetime import datetime, timedelta -from math import ceil +from math import exp from random import shuffle, choice from src.utils.consts import guild_handle, member_req, active_req, rank_upgrade_channel @@ -64,20 +64,13 @@ async def generate_rank_upgrade(weekly_invites : list): entries = {} total_gexp = sum([gexp for uuid, gexp in members]) - # 1) Active req is subtracted from the player's weekly guild experience - # 2) The difference is divided by 50,000 and rounded up - # 3) The quotient is multiplied by 10 and added to the player's entries - for uuid, gexp in members[:10]: - if gexp < active_req: - break - gexp = gexp - active_req - entry_multiplier = ceil(gexp / 50000) - entries[uuid] = 10 * entry_multiplier + for uuid, gexp in members: + entries[uuid] = await get_entries(gexp) - # A player gets 1 entry for every valid invite they have made + # A player gets 7 entries for every valid invite they have made total_invitations = 0 for uuid, invitations in weekly_invites: - entries[uuid] = entries[uuid] + len(invitations) if uuid in entries else len(invitations) + entries[uuid] = entries[uuid] + (len(invitations)*7) total_invitations += len(invitations) weighted_entries = [uuid for uuid, weight in entries.items() for _ in range(weight)] @@ -108,13 +101,13 @@ async def generate_rank_upgrade(weekly_invites : list): **The winner is....** ## {winner} > Total Guild Experience:- `{format(winner_gexp, ',d')}` -> Invites:- `{format(len(winner_invites), ',d')}` +> Valid Invites:- `{format(len(winner_invites), ',d')}` > Total Entries:- `{format(entries[winner_uuid], ',d') if winner_uuid in entries else 0}` ### Here are some statistics for the past week - Total unscaled guild experience earned - `{format(total_gexp, ',d')}` -- Total players invited - `{format(total_invitations, ',d')}` +- Total players invited (valid) - `{format(total_invitations, ',d')}` *To know how the winner is picked, go here https://discord.com/channels/522586672148381726/1152480866585554994/1152521488356872222*''' From 3edaa7f1c745b4f4c484df0eb6dfe934050c3ff9 Mon Sep 17 00:00:00 2001 From: Amogh Date: Fri, 20 Oct 2023 11:19:48 -0500 Subject: [PATCH 10/12] feat: set a basecase and reorganized the get_entries() function. --- src/utils/referral_utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils/referral_utils.py b/src/utils/referral_utils.py index 372e1ecc..69ddf3ad 100644 --- a/src/utils/referral_utils.py +++ b/src/utils/referral_utils.py @@ -52,10 +52,11 @@ async def check_invitation_validity(invitations: list): async def get_entries(gexp): - if gexp < active_req: - return 1 - else: + if gexp >= active_req: return round(50 * (1 - exp(-gexp / 500000))) + elif gexp >= member_req: + return 1 + return 0 async def generate_rank_upgrade(weekly_invites : list): From 5c03998508393d3e7a6f8628c075ec271d0dd121 Mon Sep 17 00:00:00 2001 From: Amogh Date: Fri, 20 Oct 2023 11:20:09 -0500 Subject: [PATCH 11/12] fix: typo fix --- src/utils/referral_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/referral_utils.py b/src/utils/referral_utils.py index 69ddf3ad..697cbb87 100644 --- a/src/utils/referral_utils.py +++ b/src/utils/referral_utils.py @@ -102,7 +102,7 @@ async def generate_rank_upgrade(weekly_invites : list): **The winner is....** ## {winner} > Total Guild Experience:- `{format(winner_gexp, ',d')}` -> Valid Invites:- `{format(len(winner_invites), ',d')}` +> Valid Invites:- `{format(len(winner_invites), ',d') if winner_invites else 0}` > Total Entries:- `{format(entries[winner_uuid], ',d') if winner_uuid in entries else 0}` From b5550c85b7c38a2d970cd7870993bb73b7ffea46 Mon Sep 17 00:00:00 2001 From: Amogh Date: Fri, 20 Oct 2023 11:26:03 -0500 Subject: [PATCH 12/12] feat: updated link --- src/utils/referral_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/referral_utils.py b/src/utils/referral_utils.py index 697cbb87..547ecd26 100644 --- a/src/utils/referral_utils.py +++ b/src/utils/referral_utils.py @@ -110,6 +110,6 @@ async def generate_rank_upgrade(weekly_invites : list): - Total unscaled guild experience earned - `{format(total_gexp, ',d')}` - Total players invited (valid) - `{format(total_invitations, ',d')}` -*To know how the winner is picked, go here https://discord.com/channels/522586672148381726/1152480866585554994/1152521488356872222*''' +*To know how the winner is picked, go here https://discord.com/channels/522586672148381726/1152480866585554994/1164962591198683146*''' await bot.get_channel(rank_upgrade_channel).send(announcement)