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

Backend redo #183

Merged
merged 8 commits into from
Apr 5, 2024
9 changes: 9 additions & 0 deletions src/cogs/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ async def callback(self, interaction: discord.Interaction):

await ctx.send_modal(modal=ModalCreator())

@commands.slash_command()
@option(
name="Member",
description="The discord user whose minecraft ign you'd like to find",
required=True,
input_type=discord.Member
)
async def whois(self, ctx, member: discord.Member):
await ctx.respond(embed=await Union(member).whois())

def setup(bot):
bot.add_cog(General(bot))
5 changes: 2 additions & 3 deletions src/func/General.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def rolecheck(ctx, send_ping: bool):
"gexp": sum(player["expHistory"].values())}

await ctx.send("If you see the bot is stuck on a member along with an error message, "
"forcesync member the bot is stuck on.")
"forcesync member the bot is stuck on.")
bot.admin_ids = [member.id for member in bot.admin.members]
for discord_member in discord_members:
# Do not check admins and bots
Expand All @@ -122,8 +122,7 @@ async def rolecheck(ctx, send_ping: bool):
elif weekly_exp < active_req and bot.active_role in discord_member.roles: # Doesn't meet active req
await discord_member.remove_roles(bot.active_role)

if (nick != username and bot.active_role not in discord_member.roles) or (
nick != username and not has_tag_permission):
if nick != username and not has_tag_permission:
await discord_member.edit(nick=username)

# Edit roles
Expand Down
15 changes: 13 additions & 2 deletions src/func/Union.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
pos_color, registration_channel_id,
staff_impersonation_embed, ticket_categories,
unknown_ign_embed, join_request_embed)
from src.utils.db_utils import update_member, insert_new_member
from src.utils.db_utils import update_member, insert_new_member, get_db_uuid_username_from_discord_id
from src.utils.discord_utils import (create_ticket, has_tag_perms,
is_linked_discord)
from src.utils.request_utils import (get_gtag, get_hypixel_player,
Expand Down Expand Up @@ -85,7 +85,6 @@ async def sync(self, ctx, name: str, tag: str = None, is_fs=False):
if not ign:
return unknown_ign_embed


# Initialize vars for storing changes
roles_to_add = []
roles_to_remove = [bot.processing]
Expand Down Expand Up @@ -288,3 +287,15 @@ async def avatar(self):
embed = discord.Embed(
title=f"{self.user}'s avatar:", color=neutral_color)
return embed.set_image(url=self.user.avatar)

async def whois(self):
uuid, username = await get_db_uuid_username_from_discord_id(self.user.id)
embed = discord.Embed(
title=username,
description=f"Discord Username: {self.user.name}\n"
f"Discord Nick: {self.user.nick}",
color=neutral_color
)
embed.set_thumbnail(url=f'https://minotar.net/helm/{uuid}/512.png')
embed.set_footer(text=f"UUID: {uuid}")
return embed
23 changes: 21 additions & 2 deletions src/utils/discord_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from src.utils.consts import (config, log_channel_id, neutral_color, ticket_categories,
guild_handle)
from src.utils.db_utils import check_uuid_in_db
from src.utils.request_utils import get_mojang_profile
from src.utils.ticket_utils import *
from src.utils.ticket_utils.tickets import name_grabber
Expand Down Expand Up @@ -139,6 +140,23 @@ async def has_tag_perms(user: discord.User):
return any(role in user.roles for role in bot.tag_allowed_roles)


async def update_recruiter_role(uuid: str, invites: int):
user_id = await check_uuid_in_db(uuid)
if not user_id:
return
member_ids = [x.id for x in bot.guild.members]
if user_id not in member_ids:
return
user = bot.guild.get_member(user_id)
if invites > 5:
await user.add_roles(bot.recruiter)
else:
await user.remove_roles(bot.recruiter)
return




@tasks.loop(count=1)
async def after_cache_ready():
# Set owner id(s) and guild
Expand All @@ -158,12 +176,13 @@ async def after_cache_ready():
bot.active_role = discord.utils.get(bot.guild.roles, name="Active")
bot.ally = discord.utils.get(bot.guild.roles, name="Ally")
bot.server_booster = discord.utils.get(bot.guild.roles, name="Server Booster")
bot.rich_kid = discord.utils.get(bot.guild.roles, name="Rich Kid")
bot.rich_kid = discord.utils.get(bot.guild.roles, name="Event Sponsor")
bot.gvg = discord.utils.get(bot.guild.roles, name="GvG Team")
bot.giveaways_events = discord.utils.get(bot.guild.roles, name="Giveaways/Events")
bot.veteran = discord.utils.get(bot.guild.roles, name="Veteran")
bot.recruiter = discord.utils.get(bot.guild.roles, name="Recruiter")
bot.tag_allowed_roles = (bot.active_role, bot.staff, bot.former_staff,
bot.server_booster, bot.rich_kid, bot.gvg, bot.veteran)
bot.server_booster, bot.rich_kid, bot.gvg, bot.veteran, bot.recruiter)

from src.utils.discord_utils import name_grabber
bot.staff_names = [(await get_mojang_profile(await name_grabber(member)))[0] for member in bot.staff.members]
Expand Down
2 changes: 2 additions & 0 deletions src/utils/loop_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from src.func.Integer import Integer
from src.utils.consts import weekly_lb_channel, daily_lb_channel
from src.utils.db_utils import (connect_db, select_all)
from src.utils.discord_utils import update_recruiter_role
from src.utils.giveaway_utils import roll_giveaway
from src.utils.referral_utils import check_invitation_validity, generate_rank_upgrade

Expand Down Expand Up @@ -70,6 +71,7 @@ async def update_invites():
valid_invites = await check_invitation_validity(weekly_uuids)
weekly_invitations.append((inviter_uuid, valid_invites))
total_valid_invites = total_valid_invites + len(valid_invites)
await update_recruiter_role(inviter_uuid, len(valid_invites))
await bot.db.execute(
"UPDATE invites SET total_invites = (?), total_valid_invites = (?), current_invitee_uuids = '' WHERE inviter_uuid = (?)",
(total_invites, total_valid_invites, inviter_uuid))
Expand Down
Loading