import json
import aiohttp
import discord
from discord.ui import Select
from discord import SelectOption, ui, app_commands
from datetime import datetime, timedelta
from uuid import uuid4 # gen random guid
from addons.buttons import TestButtons
from pystyle import Colors
import os
import asyncio # asyncio needs to be imported
def clear():
os.system('cls' if os.name == 'nt' else 'clear')
class Client(discord.Client): # Class names should be PascalCase
def __init__(self, intents):
super().__init__(intents=intents)
self.synced = False
async def on_ready(self):
await self.wait_until_ready()
if not self.synced:
await tree.sync()
self.synced = True
print(f"\n\nWe have logged in as {self.user} | In {len(self.guilds)}
Servers:")
for guild in self.guilds:
print(Colors.blue + guild.name + Colors.reset)
game = discord.Activity(type=discord.ActivityType.watching, name="Dev・
zxzx")
await self.change_presence(activity=game, status=discord.Status.online)
intents = discord.Intents.all()
aclient = Client(intents=intents) # Using the corrected class name
tree = app_commands.CommandTree(aclient)
@tree.command(name='gen', description='Generate receipts with ease.')
async def receiptgen(interaction: discord.Interaction):
owner_id = interaction.user.id
embed = discord.Embed(title="Lua Receipt Gen", description=f'{interaction.user}
please select your brand.\n\n<:crosss:1229840828651016253> You have currently no
access.', color=0x1e1f22)
with open("config.json", "r") as f:
config = json.load(f) # Config is loaded here for use later
role_brand_mapping = {
284862516635238420: "StockX",
1284862551334846484: "Farfetch",
1284862568430702725: "Balenciaga",
1284862587154202714: "Bape",
1284862615687790623: "Apple",
1284862668909576212: "Stüssy",
1284862691860811876: "JD Sports",
1284862719849136209: "Nike",
1284862733883539488: "Prada",
1284862747623817286: "Trapstar",
1284862761939111949: "NoSauceThePlug",
1284862791139983400: "Corteiz",
1284862801218764882: "The North Face"
}
user_roles_ids = [role.id for role in interaction.user.roles]
brand_names = [brand_name for required_role_id, brand_name in
role_brand_mapping.items() if required_role_id in user_roles_ids]
if brand_names:
if len(brand_names) == len(role_brand_mapping):
embed = discord.Embed(title="Lua Receipt Gen",
description=f'{interaction.user} please select your brand.\n\
n<:info:1229841278037004349> You have a subscription for `all` brands',
color=0x1e1f22)
else:
brand_count = len(brand_names)
embed = discord.Embed(title="Lua Receipt Gen",
description=f'{interaction.user} please select your brand.\n\
n<:info:1229841278037004349> You have a subscription for `{brand_count}` brands',
color=0x1e1f22)
else:
embed = discord.Embed(title="Lua Receipt Gen",
description=f'{interaction.user} please select your brand.\n\
n<:crosss:1229840828651016253> You have currently no access.', color=0x1e1f22)
embed.set_footer(text=f'{interaction.user}`s Panel')
embed.set_thumbnail(url='https://cdn.discordapp.com/attachments/1229782496057626666
/1231184806155386890/brandmark-design_5.png')
buttons_view = TestButtons(owner_id)
await interaction.response.send_message(embed=embed, view=buttons_view)
await asyncio.sleep(160) # Import asyncio to use it
follow_up_embed = discord.Embed(title="No Interaction", description="The menu
timed out automatically due to no interaction.\nYou can type `/gen` again to
generate receipts.")
follow_up_embed.set_footer(text=f'{interaction.user}`s Panel')
await interaction.edit_original_response(embed=follow_up_embed, view=None)
# Continue with the Utils and other command functions, using the corrected config
loading method
class Utils:
@staticmethod
async def is_whitelisted(user_id: int) -> bool:
with open("whitelist.txt", "r") as f:
whitelisted_users = f.read().splitlines()
return str(user_id) in whitelisted_users
@staticmethod
async def add_to_whitelist(user_id: int) -> bool:
with open("whitelist.txt", "r+") as f:
whitelisted_users = f.read().splitlines()
if str(user_id) in whitelisted_users:
return False
f.write(str(user_id) + "\n")
return True
@staticmethod
async def remove_from_whitelist(user_id: int) -> bool:
with open("whitelist.txt", "r+") as f:
lines = f.readlines()
f.seek(0)
user_removed = False
for line in lines:
if str(user_id) not in line.strip():
f.write(line)
else:
user_removed = True
f.truncate()
return user_removed
# Load the `config` inside each command as needed, and avoid missing definitions or
imports.
# Also, adjust the interaction responses where needed to make sure correct config
data is handled.