Skip to content

Commit

Permalink
gonna get id from em
Browse files Browse the repository at this point in the history
  • Loading branch information
Selyss committed Dec 11, 2023
1 parent 8d9f0be commit fa89ce8
Showing 1 changed file with 13 additions and 68 deletions.
81 changes: 13 additions & 68 deletions cogs/inquiry.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from datetime import datetime
from datetime import datetime, timedelta
import json
from nextcord import slash_command
from nextcord.ext.commands import Bot, Cog
from nextcord.ext import commands
import nextcord
from typing import Dict


CLOSED_CATEGORY = 1182473403303723128

Expand All @@ -23,32 +21,6 @@
MARLOW_ID: int = 630872658027872273
ADVERTISING_ROLE: int = 1096584186304942111

JSON_FILE = "data.json"

requests_data: Dict[str, Dict[str, str]] = {}


# Function to load data from the JSON file
def load_data() -> None:
global requests_data
try:
with open(JSON_FILE, "r", encoding="utf-8") as json_file:
requests_data = json.load(json_file)
except FileNotFoundError:
print("NO JSON FILE")
# File doesn't exist, initialize with an empty dictionary
requests_data = {}


# Function to save data to the JSON file
def save_data() -> None:
with open(JSON_FILE, "w", encoding="utf-8") as json_file:
json.dump(requests_data, json_file, ensure_ascii=False, indent=4)


# Load data when the bot starts
load_data()


def get_date() -> str:
return datetime.now().strftime("%m/%d/%Y")
Expand Down Expand Up @@ -114,7 +86,7 @@ async def close(self, btn: nextcord.ui.Button, inter: nextcord.Interaction):


class QuickResponse(nextcord.ui.Modal):
def __init__(self, person=None) -> None:
def __init__(self, person=None):
super().__init__(
title="Quick Response",
custom_id="ticket:quickresponse",
Expand All @@ -134,38 +106,33 @@ def __init__(self, person=None) -> None:

async def callback(self, inter: nextcord.Interaction) -> None:
if isinstance(inter.channel, nextcord.TextChannel):
# FIXME: SWITCH TO GET MEMBER (DOCS)
mem = await inter.guild.fetch_member(self.person)
name = mem.name
id = mem.id
category = nextcord.utils.get(inter.guild.categories, id=TICKET_CATEGORY)
new_channel = await category.create_text_channel(
name=f"ticket-{name}",
reason=f"Created ticket for {id} - {name}",
topic=id,
name=f"ticket-{self.person.user.name}",
reason=f"Created ticket for {self.person.user.id} - {self.person.user.name}",
topic=self.person.user.id,
)
await inter.response.send_message(
f"Ticket created: <#{new_channel.id}>", ephemeral=True
)
em = nextcord.Embed()
em.color = EMBED_COLOR
# em.set_author(icon_url=marlow.user.avatar, name=marlow.user.name)
em.add_field(name="**CONTACT REQUEST ACCEPTED**", value="", inline=False)
em.add_field(name="**message**", value=self.details.value, inline=False)
em.set_footer(text=f"{id}{get_date()}{get_time()}")
em.set_footer(text=f"{self.person.user.id}{get_date()}{get_time()}")

await new_channel.send(
content=f"<@{id}>",
content=f"<@{self.person.user.id}>",
embed=em,
view=CloseView(),
)
await new_channel.set_permissions(
mem, send_messages=False, read_messages=True
self.person.user, send_messages=False, read_messages=True
)


class RequestView(nextcord.ui.View):
def __init__(self, person=None, message=None) -> None:
def __init__(self, person=None, message=None):
super().__init__(timeout=None)
self.person = person
self.message = message
Expand Down Expand Up @@ -201,11 +168,11 @@ async def accept(self, btn: nextcord.ui.Button, inter: nextcord.Interaction):
@nextcord.ui.button(
label="Quick Response",
style=nextcord.ButtonStyle.blurple,
custom_id="ticket:ID", ### SUB ID??
custom_id="ticket:quickresponse",
)
async def quickresponse(self, btn: nextcord.ui.Button, inter: nextcord.Interaction):
p = str(btn.custom_id).split(":")
await inter.response.send_modal(QuickResponse(person=p[1]))
modal = QuickResponse(self.person)
await inter.response.send_modal(modal)


class AdView(nextcord.ui.View):
Expand Down Expand Up @@ -301,35 +268,14 @@ async def callback(self, inter: nextcord.Interaction) -> None:
em.set_author(icon_url=inter.user.avatar, name=inter.user.name)
em.add_field(name="**reason**", value=self.details.value)
em.set_footer(text=f"{inter.user.id}{get_date()}{get_time()}")

await target_channel.send(
embed=em, view=RequestView(person=inter.user.id, message=em)
embed=em, view=RequestView(person=inter, message=self.details.value)
)
msg = target_channel.last_message_id
save_request_data(inter.user.id, self.details.value, msg)
await inter.response.send_message(
"""📫 **Your request has been sent!**""", ephemeral=True
)


def save_request_data(user_id: int, request_details: str, msg_id: int) -> None:
# Load existing data
load_data()

# Get or create a dictionary for the user's requests
user_requests = requests_data.setdefault(str(user_id), {})

# Add the request details to the user's requests
user_requests[str(msg_id)] = {
"timestamp": f"{get_date()} {get_time()}",
"details": request_details,
"response": None, # Initialize response as None
}

# Save the data to the JSON file
save_data()


class Inquiry(Cog):
def __init__(self, bot: Bot) -> None:
self.bot = bot
Expand All @@ -341,7 +287,6 @@ async def on_ready(self) -> None:
if not self.persistent_modals_added:
self.bot.add_modal(QuestionForm())
self.bot.add_modal(AdForm())
self.bot.add_modal(QuickResponse())
self.persistent_modals_added = True

if not self.persistent_views_added:
Expand Down

0 comments on commit fa89ce8

Please sign in to comment.