diff --git a/src/cogs/tickets.py b/src/cogs/tickets.py index f3b18278..67c55de6 100644 --- a/src/cogs/tickets.py +++ b/src/cogs/tickets.py @@ -17,22 +17,16 @@ 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", 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/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: diff --git a/src/func/Union.py b/src/func/Union.py index 34011093..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, @@ -152,8 +154,7 @@ async def sync(self, ctx, name: str, tag: str = None, is_fs=False): return embed - async def register(self, ctx, name, reference): - await ctx.defer() + async def register(self, ctx, name): # 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, reference): 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(): 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, diff --git a/src/utils/referral_utils.py b/src/utils/referral_utils.py index ea7ab017..547ecd26 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 @@ -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." @@ -51,26 +51,27 @@ 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 round(50 * (1 - exp(-gexp / 500000))) + elif gexp >= member_req: + return 1 + return 0 + + +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 = {} 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)] @@ -101,14 +102,14 @@ 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') if winner_invites else 0}` > 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*''' +*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) 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]) +