
from twitchio.ext import commands

import os

import dotenv

class Bot(commands.Bot):
	
	def __init__(self, **kwargs):
		super().__init__(**kwargs)
		self.version = "3.0.0-a.0"
	
	async def event_ready(self):
		print(f"Ready | {self.nick}")

dotenv.load_dotenv()
bot = Bot(irc_token = os.getenv("TWITCH_BOT_ACCOUNT_OAUTH_TOKEN"), 
			client_id = os.getenv("TWITCH_CLIENT_ID"), 
			nick = "harmonbot", prefix = '!', initial_channels = ("harmonbot",))
bot.run()


@@ -40,11 +40,41 @@
 ort 
-os%0A
+asyncio%0Aimport os%0A%0Aimport asyncpg
 %0Aimp
@@ -131,16 +131,29 @@
 __(self,
+ loop = None,
  **kwarg
@@ -163,62 +163,1192 @@
 %0A%09%09s
-uper().__init__(**kwargs)%0A%09%09self.version = %223.0.0-a.0%22
+elf.version = %223.0.0-a.1%22%0A%09%09%0A%09%09loop = loop or asyncio.get_event_loop()%0A%09%09%0A%09%09# Credentials%0A%09%09for credential in (%22DATABASE_PASSWORD%22, %22POSTGRES_HOST%22):%0A%09%09%09setattr(self, credential, os.getenv(credential))%0A%09%09if not self.POSTGRES_HOST:%0A%09%09%09self.POSTGRES_HOST = %22localhost%22%0A%09%09self.DATABASE_HOST = self.POSTGRES_HOST%0A%09%09%0A%09%09# PostgreSQL database connection%0A%09%09self.db = self.database = self.database_connection_pool = None%0A%09%09self.connected_to_database = asyncio.Event()%0A%09%09self.connected_to_database.set()%0A%09%09loop.run_until_complete(self.initialize_database())%0A%09%09%0A%09%09super().__init__(loop = loop, **kwargs)%0A%09%0A%09async def connect_to_database(self):%0A%09%09if self.database_connection_pool:%0A%09%09%09return%0A%09%09if self.connected_to_database.is_set():%0A%09%09%09self.connected_to_database.clear()%0A%09%09%09self.database_connection_pool = await asyncpg.create_pool(user = %22harmonbot%22, %0A%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09password = self.DATABASE_PASSWORD, %0A%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09%09database = %22harmonbot%22, host = self.DATABASE_HOST)%0A%09%09%09self.db = self.database = self.database_connection_pool%0A%09%09%09self.connected_to_database.set()%0A%09%09else:%0A%09%09%09await self.connected_to_database.wait()%0A%09%0A%09async def initialize_database(self):%0A%09%09await self.connect_to_database()
 %0A%09%0A%09

Connect to database