From 0ae9b50a76560776b8df8bf2fcfa8e0a79d85164 Mon Sep 17 00:00:00 2001 From: Dustin Pianalto Date: Thu, 7 Jun 2018 09:20:04 -0800 Subject: [PATCH 1/5] Changed load message --- src/cogs/contributors.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cogs/contributors.py b/src/cogs/contributors.py index 4a888a6..f942184 100644 --- a/src/cogs/contributors.py +++ b/src/cogs/contributors.py @@ -74,10 +74,9 @@ class Upload: extension = extension.lower() try: self.bot.load_extension("src.cogs.{}".format(extension)) - except Exception as e: traceback.print_exc() - await ctx.send(f'Could not unload `{extension}` -> `{e}`') + await ctx.send(f'Could not load `{extension}` -> `{e}`') else: await ctx.send(f'Loaded `{extension}`.') From 22c6dd2a7d4a0b3373642a70802f453cce865675 Mon Sep 17 00:00:00 2001 From: Dustin Pianalto Date: Thu, 7 Jun 2018 09:23:39 -0800 Subject: [PATCH 2/5] renamed BasicCommands to basic_commands --- src/cogs/{BasicCommands.py => basic_commands.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/cogs/{BasicCommands.py => basic_commands.py} (100%) diff --git a/src/cogs/BasicCommands.py b/src/cogs/basic_commands.py similarity index 100% rename from src/cogs/BasicCommands.py rename to src/cogs/basic_commands.py From 049130e77d0ba7d078e0bce244d1d67604835051 Mon Sep 17 00:00:00 2001 From: Dustin Pianalto Date: Mon, 11 Jun 2018 13:50:46 -0800 Subject: [PATCH 3/5] fixed extension name --- src/extensions.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extensions.txt b/src/extensions.txt index a47049f..d97db6c 100644 --- a/src/extensions.txt +++ b/src/extensions.txt @@ -5,4 +5,4 @@ code git fun moderation -BasicCommands +basic_commands From f8b0771520c91f9c9d864ef50642f8e89b7e7088 Mon Sep 17 00:00:00 2001 From: "Dusty.P" Date: Tue, 12 Jun 2018 00:04:51 -0800 Subject: [PATCH 4/5] Create DB connection --- src/__main__.py | 12 +++++------- src/shared_libs/database.py | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 src/shared_libs/database.py diff --git a/src/__main__.py b/src/__main__.py index a883bd2..03c6ca2 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -19,6 +19,7 @@ from discord.ext import commands from src.config.config import LoadConfig from src.shared_libs.loggable import Loggable from src.shared_libs.ioutils import in_here +from src.shared_libs import database # Init logging to output on INFO level to stderr. @@ -52,6 +53,9 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable): # Initialize and attach config / settings LoadConfig.__init__(self) commands.Bot.__init__(self, command_prefix=self.defaultprefix) + with open(in_here('config', 'PrivateConfig.json')) as fp: + self.bot_secrets = json.load(fp) + self.db_con = database.DatabaseConnection(**self.bot_secrets['db_con']) # Load plugins # Add your cog file name in this list @@ -134,11 +138,5 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable): client = SebiMachine() -# Make sure the key stays private. -# I am 99% certain this is valid! -with open(in_here('config', 'PrivateConfig.json')) as fp: - PrivateConfig = json.load(fp) -if PrivateConfig["bot-key"] == '': - PrivateConfig["bot-key"] = os.getenv('botkey') -client.run(PrivateConfig["bot-key"]) +client.run(client.bot_secrets["bot-key"]) diff --git a/src/shared_libs/database.py b/src/shared_libs/database.py new file mode 100644 index 0000000..edcc655 --- /dev/null +++ b/src/shared_libs/database.py @@ -0,0 +1,23 @@ +import asyncpg +import asyncio + + +class DatabaseConnection: + def __init__(self, host: str='localhost', port: int=5432, database: str='', user: str='', password: str=''): + if user == '' or password == '' or database == '': + raise RuntimeError('Username or Password are blank') + self.kwargs = {'host': host, 'port': port, 'database': database, 'user': user, 'password': password} + self._conn = None + asyncio.get_event_loop().run_until_complete(self.acquire()) + self.fetchval = self._conn.fetchval + self.execute = self._conn.execute + self.fetch = self._conn.fetch + self.fetchrow = self._conn.fetchrow + + async def acquire(self): + if not self._conn: + self._conn = await asyncpg.create_pool(**self.kwargs) + + async def close(self): + await self._conn.close() + self._conn = None From a30f2cc4ae437e1b9d1ba72ccd829d186b4047a8 Mon Sep 17 00:00:00 2001 From: "Dusty.P" Date: Tue, 12 Jun 2018 00:11:34 -0800 Subject: [PATCH 5/5] Fix key error --- src/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__main__.py b/src/__main__.py index 03c6ca2..e3a96fb 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -55,7 +55,7 @@ class SebiMachine(commands.Bot, LoadConfig, Loggable): commands.Bot.__init__(self, command_prefix=self.defaultprefix) with open(in_here('config', 'PrivateConfig.json')) as fp: self.bot_secrets = json.load(fp) - self.db_con = database.DatabaseConnection(**self.bot_secrets['db_con']) + self.db_con = database.DatabaseConnection(**self.bot_secrets['db-con']) # Load plugins # Add your cog file name in this list