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

Bugfixes+refactor #155

Merged
merged 16 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/func/General.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async def sem_task(task):
last_value = guild_division[0]

# Set nick
if not discord_member.nick or gtag not in discord_member.nick:
if not discord_member.nick or f" [{gtag}]" not in discord_member.nick:
await discord_member.edit(nick=username + f' [{gtag}]')

# Edit roles
Expand Down
13 changes: 6 additions & 7 deletions src/func/Union.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
from typing import Union

import discord
import src.utils.ui_utils as uiutils


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,
staff_impersonation_embed, ticket_categories,
Expand Down Expand Up @@ -126,7 +125,7 @@ async def sync(self, ctx, name: str, tag: str = None, is_fs=False):
# User is an ally
elif guild_name in allies:
if not can_tag:
new_nick += f" [{await get_gtag(guild_name)}]"
new_nick += f" {await get_gtag(guild_name)}"
roles_to_remove.extend([bot.new_member_role, bot.member_role])
roles_to_add.extend([bot.guest, bot.ally])

Expand Down Expand Up @@ -185,7 +184,8 @@ async def register(self, ctx, name):
discord.InputTextStyle.short,
"Invited by:"]
]
await ctx.response.send_modal(modal=uiutils.ModalCreator(embed=embed, fields=fields, ign=ign, uuid=uuid, title="Player Reference",
await ctx.response.send_modal(
modal=uiutils.ModalCreator(embed=embed, fields=fields, ign=ign, uuid=uuid, title="Player Reference",
function=validate_reference))
await ctx.author.add_roles(bot.member_role, reason="Registration - Member")
guest_ticket = None
Expand All @@ -212,6 +212,7 @@ async def register(self, ctx, name):
category=discord.utils.get(ctx.guild.categories,
name=ticket_categories["registrees"]))
guest_ticket = ticket

class Join_Misc_Buttons(discord.ui.Button):
def __init__(self, button: list):
"""
Expand All @@ -232,8 +233,6 @@ async def callback(self, interaction: discord.Interaction):
f"{interaction.user.mention} kindly leave your current guild so that"
f" we can can invite you to Miscellaneous.")



elif interaction.custom_id == "No":
await ticket.purge(limit=100)
await interaction.user.remove_roles(bot.processing, reason="Registration - Guest")
Expand Down Expand Up @@ -264,7 +263,7 @@ async def callback(self, interaction: discord.Interaction):
await ctx.author.remove_roles(bot.new_member_role, reason="Register")
await ctx.author.edit(nick=ign)

return embed, guest_ticket if guild_name != guild_handle else None, None
return (embed, guest_ticket) if guild_name != guild_handle else (None, None)

async def add(self, ctx):
if ctx.channel.category.name not in ticket_categories.values():
Expand Down
158 changes: 145 additions & 13 deletions src/utils/discord_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
from __main__ import bot
from datetime import datetime, timedelta
from io import BytesIO
Expand All @@ -11,9 +12,12 @@
from src.utils.consts import (config, dnkl_req,
gvg_requirements, log_channel_id, neg_color, neutral_color, staff_application_questions,
ticket_categories,
unknown_ign_embed, guild_handle, positive_responses, dnkl_creation_embed, member_req)
unknown_ign_embed, guild_handle, positive_responses, dnkl_creation_embed, dnkl_channel_id,
missing_permissions_embed)
from src.utils.db_utils import select_one, insert_new_dnkl, update_dnkl, delete_dnkl
from src.utils.minecraft_utils import get_player_gexp
from src.utils.request_utils import get_hypixel_player, get_mojang_profile, get_player_guild, get_guild_level, get_guild_by_name
from src.utils.request_utils import get_hypixel_player, get_mojang_profile, get_player_guild, get_guild_level


async def name_grabber(author: discord.Member) -> str:
if not author.nick:
Expand All @@ -39,11 +43,136 @@ async def is_linked_discord(player_data: dict, user: discord.User) -> bool:
return (discord == str(user)[:-2]) or (discord == (str(user.id) + "#0000") or (discord == str(user)))



async def get_ticket_creator(channel: discord.TextChannel):
return bot.guild.get_member(int(channel.topic.split("|")[0]))


async def close_ticket(channel: discord.TextChannel, author: discord.User, ign: str, uuid: str,
embed: discord.Embed, interaction: discord.Interaction):
if author != interaction.user:
await channel.send(embed=missing_permissions_embed)
return None

embed = discord.Embed(title="This ticket will be deleted in 20 seconds!", color=neg_color)

# Send deletion warning and gather transcript
await interaction.response.send_message(embed=embed)
transcript = await chat_exporter.export(channel, limit=None)
if transcript:
transcript = discord.File(BytesIO(transcript.encode()),
filename=f"transcript-{channel.name}.html")
await bot.get_channel(log_channel_id).send(
f"DNKL Request was denied and channel was deleted by {author}")
await bot.get_channel(log_channel_id).send(file=transcript)

# Sleep and delete channel
await asyncio.sleep(20)
await discord.TextChannel.delete(channel)


async def gvg_approve(channel: discord.TextChannel, author: discord.User, ign: str, uuid: str, embed: discord.Embed,
interaction: discord.Interaction):
if bot.staff not in interaction.user.roles:
await channel.send(embed=missing_permissions_embed)
return None

await interaction.response.send_message(embed=discord.Embed(
title="Your application has been accepted!",
description="Please await staff assistance for more information!",
color=neutral_color))
member = await bot.guild.fetch_member(author.id)
await member.add_roles(bot.gvg)

return True


async def gvg_deny(channel: discord.TextChannel, author: discord.User, ign: str, uuid: str, embed: discord.Embed,
interaction: discord.Interaction):
if bot.staff not in interaction.user.roles:
await channel.send(embed=missing_permissions_embed)
return None

await interaction.response.send_message(embed=discord.Embed(
title="Your application has been denied!",
description="Please await staff assistance for more information!",
color=neg_color))

return True


async def dnkl_error(channel: discord.TextChannel, author: discord.User, ign: str, uuid: str, embed: discord.Embed,
interaction: discord.Interaction):
if bot.staff not in interaction.user.roles:
await channel.send(embed=missing_permissions_embed)
return None

await interaction.response.send_message(embed=discord.Embed(
title="Your application has been accepted, however there was an error!",
description="Please await staff assistance!",
color=neutral_color))
return True


async def dnkl_deny(channel: discord.TextChannel, author: discord.User, ign: str, uuid: str, embed: discord.Embed,
interaction: discord.Interaction, self_denial: bool = False):
if bot.staff not in interaction.user.roles and not self_denial:
await channel.send(embed=missing_permissions_embed)
return None

if not self_denial:
await interaction.response.send_message("**This user's do-not-kick-list application has been denied!.**\n"
"If you didn't mean to hit deny, you can add them using `/dnkl_add`.",
ephemeral=True)

embed = discord.Embed(title="Your do-not-kick-list application has been denied!",
description=f"You do not meet the DNKL requirements of {format(dnkl_req, ',d')} weekly guild experience.",
color=neg_color)
embed.set_footer(
text="If don't you think you can meet the requirements, you may rejoin the guild once your inactivity period has ended.")

closeView = discord.ui.View(timeout=None) # View for staff members to approve/deny the DNKL
button = ("Close This Ticket", "close_ticket", discord.enums.ButtonStyle.red)
closeView.add_item(
uiutils.Button_Creator(channel=channel, author=author, ign=ign, uuid=uuid, button=button,
function=close_ticket))
await channel.send(embed=embed, view=closeView)
await delete_dnkl(ign)

return True


async def dnkl_approve(channel: discord.TextChannel, author: discord.User, ign: str, uuid: str, embed: discord.Embed,
interaction: discord.Interaction):
if bot.staff not in interaction.user.roles:
await channel.send(embed=missing_permissions_embed)
return None

msg = await bot.get_channel(dnkl_channel_id).send(embed=embed)

# Check if user is already on DNKL
current_message = await select_one("SELECT message_id FROM dnkl WHERE uuid = (?)",
(uuid,))
# User is not currently on DNKL
if not current_message:
await insert_new_dnkl(msg.id, uuid, ign)
return await interaction.response.send_message("**This user has been added to the do-not-kick-list!**")

# User is already on DNKl
# Try to delete current message
try:
current_message = await bot.get_channel(dnkl_channel_id).fetch_message(
current_message)
await current_message.delete()
except Exception:
pass

await update_dnkl(msg.id, uuid)
await interaction.response.send_message(
"**Since this user was already on the do-not-kick-list, their entry has been updated.**")

return True


async def create_ticket(user: discord.Member, ticket_name: str, category_name: str = ticket_categories["generic"]):
# Create ticket
ticket: discord.TextChannel = await bot.guild.create_text_channel(ticket_name,
Expand Down Expand Up @@ -119,8 +248,8 @@ async def callback(self, interaction: discord.Interaction):
]
embed = discord.Embed(title="Player Report", color=neutral_color)
await interaction.response.send_modal(
modal=uiutils.ModalCreator(embed=embed, fields=fields, ign=ign, uuid=uuid, 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 Expand Up @@ -214,9 +343,9 @@ async def callback(self, interaction: discord.Interaction):
name=ticket_categories["generic"]))

# Fetch player data
player_data = await get_hypixel_player(ign)
player_data = await get_hypixel_player(uuid=uuid)
if not player_data:
return await ticket.send(unknown_ign_embed)
return await ticket.send(embed=unknown_ign_embed)
player_data = player_data["stats"]

# Set vars for each stat
Expand Down Expand Up @@ -286,13 +415,14 @@ async def callback(self, interaction: discord.Interaction):
# Send embed and end loop

GvGView = discord.ui.View(timeout=None) # View for staff members to approve/deny the DNKL
buttons = [["Accept", "GvG_Application_Positive", discord.enums.ButtonStyle.green],
["Deny", "GvG_Application_Negative", discord.enums.ButtonStyle.red]]
buttons = (("Accept", "GvG_Application_Positive", discord.enums.ButtonStyle.green, gvg_approve),
("Deny", "GvG_Application_Negative", discord.enums.ButtonStyle.red, gvg_deny))
# Loop through the list of roles and add a new button to the view for each role.
for button in buttons:
# Get the role from the guild by ID.
GvGView.add_item(
uiutils.Button_Creator(channel=ticket, ign=ign, button=button, member=user, uuid=uuid))
uiutils.Button_Creator(channel=ticket, ign=ign, button=button, author=user, uuid=uuid,
function=button[3]))

await ticket.send("Staff, what do you wish to do with this application?", embed=embed,
view=GvGView)
Expand Down Expand Up @@ -424,7 +554,11 @@ async def create_transcript(channel: discord.TextChannel, limit: int = None):

async def dnkl_application(ign: str, uuid: str, channel: discord.TextChannel, author: discord.User, weekly_gexp: int):
YearView = discord.ui.View()
YearView.add_item(uiutils.StartYearSelect(channel=channel, ign=ign, uuid=uuid, weekly_gexp=weekly_gexp)) # Year Selection Dropdown
buttons = (("Approve", "DNKL_Approve", discord.enums.ButtonStyle.green, dnkl_approve),
("Deny", "DNKL_Deny", discord.enums.ButtonStyle.red, dnkl_deny),
("Error", "DNKL_Error", discord.enums.ButtonStyle.gray, dnkl_error))
YearView.add_item(uiutils.StartYearSelect(channel=channel, ign=ign, uuid=uuid,
weekly_gexp=weekly_gexp, buttons=buttons)) # Year Selection Dropdown
embed = discord.Embed(title=f"In which year will {ign}'s inactivity begin?",
color=neutral_color)
await channel.send(embed=embed, view=YearView)
Expand All @@ -437,7 +571,6 @@ async def get_ticket_properties(channel: discord.TextChannel):
return topic.split('|')



@tasks.loop(count=1)
async def after_cache_ready():
# Set owner id(s) and guild
Expand Down Expand Up @@ -466,7 +599,6 @@ async def after_cache_ready():
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]


from src.utils.loop_utils import check_giveaways, send_gexp_lb, update_invites
check_giveaways.start()
send_gexp_lb.start()
Expand Down
Loading
Loading