11import os
22import pathlib
3- import pkgutil
43import shutil
54import sys
6- import tempfile
75import appdirs
86
97
@@ -61,23 +59,23 @@ async def setup(bot):
6159 await bot.add_cog({class_name}(bot))
6260"""
6361
64- config_dir = appdirs .user_data_dir (appauthor = "Adib Baji" , appname = "discordai" )
62+ config_dir = pathlib . Path ( appdirs .user_data_dir (appname = "discordai" ) )
6563
6664
6765def gen_new_command (model_id : str , command_name : str , temp_default : float , pres_default : float , freq_default : float ,
6866 max_tokens_default : int , stop_default : bool , openai_key : str ):
6967 if getattr (sys , 'frozen' , False ):
7068 # The code is being run as a frozen executable
71- data_dir = appdirs .user_data_dir (appauthor = "Adib Baji" , appname = "discordai" )
72- cogs_path = os . path . join ( data_dir , "discordai/ bot/ cogs" )
69+ data_dir = pathlib . Path ( appdirs .user_data_dir (appname = "discordai" ) )
70+ cogs_path = data_dir / "discordai" / " bot" / " cogs"
7371 if not os .path .exists (cogs_path ):
74- data_dir = sys ._MEIPASS
75- og_cogs_path = os . path . join ( data_dir , "discordai/ bot/ cogs" )
76- shutil .copytree (og_cogs_path , os . path . join ( data_dir , cogs_path ) )
72+ data_dir = pathlib . Path ( sys ._MEIPASS )
73+ og_cogs_path = data_dir / "discordai" / " bot" / " cogs"
74+ shutil .copytree (og_cogs_path , data_dir / cogs_path )
7775 else :
7876 # The code is being run normally
79- template_dir = os .path .dirname (__file__ )
80- cogs_path = os . path . join ( os . path . join ( template_dir , "bot" ), "cogs" )
77+ template_dir = pathlib . Path ( os .path .dirname (__file__ ) )
78+ cogs_path = template_dir / "bot" / "cogs"
8179 with open (pathlib .Path (cogs_path , f"{ command_name } .py" ), "w" ) as f :
8280 os .makedirs (cogs_path , exist_ok = True )
8381 f .write (
@@ -98,16 +96,16 @@ def delete_command(command_name: str):
9896 return
9997 if getattr (sys , 'frozen' , False ):
10098 # The code is being run as a frozen executable
101- data_dir = appdirs .user_data_dir (appauthor = "Adib Baji" , appname = "discordai" )
102- cogs_path = os . path . join ( data_dir , "discordai/ bot/ cogs" )
99+ data_dir = pathlib . Path ( appdirs .user_data_dir (appname = "discordai" ) )
100+ cogs_path = data_dir / "discordai" / " bot" / " cogs"
103101 if not os .path .exists (cogs_path ):
104- data_dir = sys ._MEIPASS
105- og_cogs_path = os . path . join ( data_dir , "discordai/ bot/ cogs" )
106- shutil .copytree (og_cogs_path , os . path . join ( data_dir , cogs_path ) )
102+ data_dir = pathlib . Path ( sys ._MEIPASS )
103+ og_cogs_path = data_dir / "discordai" / " bot" / " cogs"
104+ shutil .copytree (og_cogs_path , data_dir / cogs_path )
107105 else :
108106 # The code is being run normally
109- template_dir = os .path .dirname (__file__ )
110- cogs_path = os . path . join ( os . path . join ( template_dir , "bot" ), "cogs" )
107+ template_dir = pathlib . Path ( os .path .dirname (__file__ ) )
108+ cogs_path = template_dir / "bot" / "cogs"
111109 try :
112110 os .remove (pathlib .Path (cogs_path , f"{ command_name } .py" ))
113111 print (f"Successfully deleted command: /{ command_name } " )
0 commit comments