Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entry system redo #149

Merged
merged 12 commits into from
Oct 20, 2023
12 changes: 3 additions & 9 deletions src/cogs/tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion src/func/String.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 20 additions & 7 deletions src/func/Union.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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!"
Expand All @@ -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")


Expand Down Expand Up @@ -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():
Expand Down
5 changes: 3 additions & 2 deletions src/utils/discord_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
35 changes: 18 additions & 17 deletions src/utils/referral_utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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."
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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)
7 changes: 6 additions & 1 deletion src/utils/ui_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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])

Loading