2025-06-24 06:34:26 +00:00
|
|
|
import discord
|
|
|
|
|
import importlib
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
class View(discord.ui.View):
|
|
|
|
|
|
|
|
|
|
def __init__(self, button_dir=None):
|
|
|
|
|
super().__init__(timeout=None)
|
|
|
|
|
self.button_dir = button_dir
|
|
|
|
|
self.buttons = []
|
|
|
|
|
self.get_buttons()
|
|
|
|
|
self.load_buttons()
|
|
|
|
|
|
|
|
|
|
def get_buttons(self):
|
2025-06-29 07:23:04 +00:00
|
|
|
if self.button_dir is not None:
|
2025-06-24 06:34:26 +00:00
|
|
|
for filename in os.listdir(self.button_dir):
|
|
|
|
|
if filename.endswith(".py"):
|
|
|
|
|
class_name = filename[:-3]
|
|
|
|
|
module = self.button_dir.replace("./", "", 1)
|
|
|
|
|
module = module.replace("/", ".")
|
|
|
|
|
btn_module = importlib.import_module(f"{module}.{class_name}")
|
|
|
|
|
btn_class = getattr(btn_module, class_name)
|
|
|
|
|
self.buttons.append(btn_class())
|
|
|
|
|
return self.buttons
|
|
|
|
|
|
|
|
|
|
def load_buttons(self):
|
|
|
|
|
for btn in self.buttons:
|
|
|
|
|
self.add_item(btn)
|