def loadCogs(): for cog in config["cogs"]: try: bot.load_extension(cog) colours.success(f"{cog} loaded successfully") except Exception as e: colours.warn(f"{cog} failed to load: {e}")
def cogLoad(self, res, cog, error=None): if res == "success": Colours.success(f"Loaded {cog} cog successfully") self.writeToFile(logMsg["cogSuccess"].format(self.date(), cog)) else: Colours.fail(f"Failed to load cog: {cog}.\n{error}") self.writeToFile(logMsg["cogFail"].format(self.date(), cog))
def writeToFile(self, msg): if not os.path.isdir("logs"): try: os.mkdir("logs") except: colours.fail( "Couldn't create the log directory -- check your file permissions" ) #Handle for the log file -- opening in append mode with open(getLog(), "a") as handle: handle.write(f"{msg}\n")
def connect(self): try: self.conn = sqlite3.connect(self.dbname) except: colours.fail(strings["errors"]["dbConnectFail"]) self.curs = self.conn.cursor() #Check to see if the database contains a "users" table tableList = self.conn.execute( "SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name" ).fetchall() for i in tableList: if i[0] == "users": return #If not, create it! self.setup()
def dbCreate(self, dbname): colours.info(f"New Database {dbname}. Creating tables...") self.writeToFile(logMsg["dbCreate"].format(self.date(), dbname))
def end(self): colours.info(f"Ending Log {getLog()}...") self.writeToFile(logMsg["end"].format(self.date()))
def start(self): colours.info(f"Starting Log {getLog()}...") self.writeToFile(logMsg["initialise"].format(self.date()))
Log.end() sys.exit() def sigHandle(sig, frame): exit() signal.signal(signal.SIGINT, sigHandle) #Sort out log directory if not os.path.isdir("logs"): try: os.mkdir("logs") except: Colours.fail("Couldn't create log directory") #Record the start time for the bot os.environ["START-TIME"] = str(datetime.date.today()) #Create the bot bot = commands.Bot(command_prefix=config["prefix"]) bot.remove_command("help") #Load Cogs for cog in config["cogs"]: if cog not in config["disabledCogs"]: try: bot.load_extension(f"cogs.{cog}") Colours.success(f"{cog} loaded successfully") except Exception as e:
async def on_ready(): if config["status"] != "": await bot.change_presence(activity=discord.Game(config["status"])) colours.success("Connected")
def exiting(): log.end() colours.success("Exiting...") sys.exit(0)
def start(self): Colours.success("Logging Enabled") self.writeToFile(logMsg["start"].format(self.date()))