small refactoring
This commit is contained in:
22
main.py
22
main.py
@@ -167,7 +167,6 @@ class EmojiStorage:
|
||||
self.db_file: str = d
|
||||
self.__load()
|
||||
|
||||
|
||||
def __load(self) -> None:
|
||||
try:
|
||||
self.__emoji_storage = pickle.load(open(self.db_file, "rb"))
|
||||
@@ -215,21 +214,16 @@ class EmojiStorage:
|
||||
return emoji
|
||||
return None
|
||||
|
||||
|
||||
CONFIG: Config = Config("config.json")
|
||||
DATABASE: Database = Database("db.dat")
|
||||
EMOJI_STORAGE: EmojiStorage = EmojiStorage("emojis.dat")
|
||||
CONFIG: Config = Config("config.json")
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
print(f"{bot.user} is ready")
|
||||
await bot.change_presence(activity=discord.CustomActivity("gaming"))
|
||||
await bot.tree.sync()
|
||||
|
||||
|
||||
rc_func = Callable[[list[str], discord.Message], Awaitable[tuple[str | discord.Embed, bool]]]
|
||||
registry: list[tuple[str, rc_func, int]] = []
|
||||
|
||||
|
||||
def register(name: str, args_amount: int):
|
||||
def decorator(func: rc_func):
|
||||
registry.append((name, func, args_amount))
|
||||
@@ -250,6 +244,7 @@ async def show(args: list[str], message: discord.Message) -> tuple[str | discord
|
||||
|
||||
return DATABASE.embed_message(int(args[0])), False
|
||||
|
||||
|
||||
@register("send", 2)
|
||||
async def send(args: list[str], message: discord.Message) -> tuple[str, bool]:
|
||||
if not message.author.guild_permissions.manage_guild:
|
||||
@@ -513,7 +508,6 @@ async def editdesc(args: list[str], message: discord.Message) -> tuple[str, bool
|
||||
return f"changed reaction role description from {result} to {args[2]}", True
|
||||
|
||||
|
||||
|
||||
@register("edithdr", 2)
|
||||
async def edithdr(args: list[str], message: discord.Message) -> tuple[str, bool]:
|
||||
if not message.author.guild_permissions.manage_guild:
|
||||
@@ -541,6 +535,13 @@ async def edithdr(args: list[str], message: discord.Message) -> tuple[str, bool]
|
||||
return "i have done the thing", True
|
||||
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
print(f"{bot.user} is ready")
|
||||
await bot.change_presence(activity=discord.CustomActivity("gaming"))
|
||||
await bot.tree.sync()
|
||||
|
||||
|
||||
async def handle_command(msg: str, message: discord.Message) -> tuple[str | discord.Embed, bool]:
|
||||
for reg in registry:
|
||||
if msg.lower().startswith(reg[0] + ' '):
|
||||
@@ -655,4 +656,5 @@ Usage:
|
||||
color=discord.Color(0xa2d2df)
|
||||
))
|
||||
|
||||
|
||||
CONFIG.run_bot()
|
||||
|
||||
Reference in New Issue
Block a user