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.db_file: str = d
|
||||||
self.__load()
|
self.__load()
|
||||||
|
|
||||||
|
|
||||||
def __load(self) -> None:
|
def __load(self) -> None:
|
||||||
try:
|
try:
|
||||||
self.__emoji_storage = pickle.load(open(self.db_file, "rb"))
|
self.__emoji_storage = pickle.load(open(self.db_file, "rb"))
|
||||||
@@ -215,21 +214,16 @@ class EmojiStorage:
|
|||||||
return emoji
|
return emoji
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
CONFIG: Config = Config("config.json")
|
||||||
DATABASE: Database = Database("db.dat")
|
DATABASE: Database = Database("db.dat")
|
||||||
EMOJI_STORAGE: EmojiStorage = EmojiStorage("emojis.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]]]
|
rc_func = Callable[[list[str], discord.Message], Awaitable[tuple[str | discord.Embed, bool]]]
|
||||||
registry: list[tuple[str, rc_func, int]] = []
|
registry: list[tuple[str, rc_func, int]] = []
|
||||||
|
|
||||||
|
|
||||||
def register(name: str, args_amount: int):
|
def register(name: str, args_amount: int):
|
||||||
def decorator(func: rc_func):
|
def decorator(func: rc_func):
|
||||||
registry.append((name, func, args_amount))
|
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
|
return DATABASE.embed_message(int(args[0])), False
|
||||||
|
|
||||||
|
|
||||||
@register("send", 2)
|
@register("send", 2)
|
||||||
async def send(args: list[str], message: discord.Message) -> tuple[str, bool]:
|
async def send(args: list[str], message: discord.Message) -> tuple[str, bool]:
|
||||||
if not message.author.guild_permissions.manage_guild:
|
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
|
return f"changed reaction role description from {result} to {args[2]}", True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@register("edithdr", 2)
|
@register("edithdr", 2)
|
||||||
async def edithdr(args: list[str], message: discord.Message) -> tuple[str, bool]:
|
async def edithdr(args: list[str], message: discord.Message) -> tuple[str, bool]:
|
||||||
if not message.author.guild_permissions.manage_guild:
|
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
|
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]:
|
async def handle_command(msg: str, message: discord.Message) -> tuple[str | discord.Embed, bool]:
|
||||||
for reg in registry:
|
for reg in registry:
|
||||||
if msg.lower().startswith(reg[0] + ' '):
|
if msg.lower().startswith(reg[0] + ' '):
|
||||||
@@ -655,4 +656,5 @@ Usage:
|
|||||||
color=discord.Color(0xa2d2df)
|
color=discord.Color(0xa2d2df)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
CONFIG.run_bot()
|
CONFIG.run_bot()
|
||||||
|
|||||||
Reference in New Issue
Block a user